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

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

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