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

Last change on this file since 21557 was 21557, checked in by dmik, 15 years ago

testapp/gui/input: Formatting.

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