source: trunk/testapp/gui/input/input.c@ 21999

Last change on this file since 21999 was 21999, checked in by dmik, 13 years ago

kernel32: Make SEH work in OS/2 context.

See #82 for details.

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1#include <stdio.h>
2#include <windows.h>
3#include <commctrl.h>
4#include <tchar.h>
5
6#ifndef _MSC_VER
7
8#include <odinlx.h>
9
10#define WC_EDIT TEXT("Edit")
11
12int APIENTRY WinMain(HINSTANCE hInstance,
13 HINSTANCE hPrevInstance,
14 LPSTR lpCmdLine,
15 int nCmdShow);
16
17int main()
18{
19#ifdef ODIN_FORCE_WIN32_TIB
20 ForceWin32TIB();
21#endif
22 RegisterLxExe(WinMain, NULL);
23 return 0;
24}
25
26#else
27
28int main()
29{
30 return WinMain(NULL, NULL, 0, SW_SHOWNORMAL);
31}
32
33#endif
34
35#define MY_IDC_EDIT 100
36
37HINSTANCE ghInst;
38
39LRESULT CALLBACK EditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
40{
41 WNDPROC wpOld = (WNDPROC)GetWindowLong(hWnd, GWL_USERDATA);
42 LRESULT lrResult = 0;
43
44 if (wpOld)
45 {
46 switch (uMsg)
47 {
48 case WM_KEYDOWN:
49 {
50 printf("WM_KEYDOWN = %08x (%04x)\n", (int)wParam,
51 (!!GetKeyState(VK_SHIFT) << 2) |
52 (!!GetKeyState(VK_CONTROL) << 1) |
53 (!!GetKeyState(VK_MENU) << 0));
54 break;
55 }
56
57 case WM_CHAR:
58 {
59 printf("WM_CHAR = %08x\n", (int)wParam,
60 (!!GetKeyState(VK_SHIFT) << 2) |
61 (!!GetKeyState(VK_CONTROL) << 1) |
62 (!!GetKeyState(VK_MENU) << 0));
63 break;
64 }
65 }
66
67 return CallWindowProc(wpOld, hWnd, uMsg, wParam, lParam);
68 }
69
70 return DefWindowProc(hWnd, uMsg, wParam, lParam);
71}
72
73LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
74{
75 switch (uMsg)
76 {
77 case WM_CREATE:
78 {
79 HWND hWndChild;
80 hWndChild = CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, NULL,
81 ES_MULTILINE | ES_WANTRETURN |
82 ES_AUTOVSCROLL | ES_NOHIDESEL |
83 WS_VSCROLL | WS_CHILD |
84 WS_TABSTOP | WS_VISIBLE,
85 0, 0, 0, 0, hWnd,
86 (HMENU)MY_IDC_EDIT, ghInst, NULL);
87 printf("hWndChild = %08x\n", hWndChild);
88 if (!hWndChild)
89 return -1;
90
91 SetWindowLong(hWndChild, GWL_USERDATA,
92 GetWindowLong(hWndChild, GWL_WNDPROC));
93 SetWindowLong(hWndChild, GWL_WNDPROC, (LONG)EditProc);
94 SetFocus(hWndChild);
95
96 return 0;
97 }
98
99 case WM_WINDOWPOSCHANGING:
100 case WM_WINDOWPOSCHANGED:
101 {
102 HDWP hDWP;
103 RECT rc;
104
105 if (hDWP = BeginDeferWindowPos(5))
106 {
107 GetClientRect(hWnd, &rc);
108
109 hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, MY_IDC_EDIT), NULL,
110 10, 70, rc.right - 20, rc.bottom - 80,
111 SWP_NOZORDER | SWP_NOREDRAW);
112
113 EndDeferWindowPos(hDWP);
114
115 RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN |
116 RDW_ERASE | RDW_NOFRAME | RDW_UPDATENOW);
117 }
118
119 return 0;
120 }
121
122 case WM_DESTROY:
123 PostQuitMessage(0);
124 break;
125 }
126
127 return DefWindowProc(hWnd, uMsg, wParam, lParam);
128}
129
130int APIENTRY WinMain(HINSTANCE hInstance,
131 HINSTANCE hPrevInstance,
132 LPSTR lpCmdLine,
133 int nCmdShow)
134{
135 WNDCLASSEX wcex;
136 DWORD dwExStyle;
137 HWND hWnd;
138 MSG msg;
139
140 InitCommonControls();
141
142 ZeroMemory(&msg, sizeof(MSG));
143 ZeroMemory(&wcex, sizeof(WNDCLASSEX));
144
145 ghInst = hInstance;
146
147 wcex.cbSize = sizeof(WNDCLASSEX);
148 wcex.hInstance = hInstance;
149 wcex.lpszClassName = TEXT("MainWindow");
150 wcex.lpfnWndProc = MainWindowProc;
151 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
152 wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
153 wcex.hIconSm = wcex.hIcon;
154 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
155 if(!RegisterClassEx(&wcex))
156 return 1;
157
158 dwExStyle = WS_EX_APPWINDOW;
159
160 hWnd = CreateWindowEx(dwExStyle, wcex.lpszClassName,
161#ifdef UNICODE
162 TEXT("Edit Control Test (oe lat: \x00F6) (yo rus: \x0451) [unicode]"),
163#else
164 TEXT("Edit Control Test (oe lat: \xF6) (yo rus: \xB8) [ascii]"),
165#endif
166 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
167 CW_USEDEFAULT, CW_USEDEFAULT, 450, 330,
168 HWND_DESKTOP, NULL, ghInst, NULL);
169 printf("hWnd = %08x\n", hWnd);
170
171 if (hWnd) {
172 ShowWindow(hWnd, nCmdShow);
173 UpdateWindow(hWnd);
174 while (GetMessage(&msg, NULL, 0, 0))
175 {
176 printf("GetMessage = %08x %08x %08x %08x\n",
177 hWnd, msg.message, msg.wParam, msg.lParam);
178 TranslateMessage(&msg);
179 printf("TranslateMessage = %08x %08x %08x %08x\n",
180 hWnd, msg.message, msg.wParam, msg.lParam);
181 DispatchMessage(&msg);
182 }
183 }
184
185 return (int)msg.wParam;
186}
Note: See TracBrowser for help on using the repository browser.