source: branches/swt/testapp/apitest/src/ApiTestOdin.cpp

Last change on this file was 22119, checked in by rousseau, 10 years ago

Added menu-entries and handler-stubs for 'usp10' and 'gdiplus' [apitest]

Here some module testing stuff will be added with Wine and WinXP as
behavioral references.

File size: 14.8 KB
Line 
1//! GENINFO :: platform:OS/2, version:20.45, target:ApiTest.generate
2/*****************************************************************************\
3* ApiTestOdin.cpp :: This is the Odin Based variant of ApiTest *
4* --------------------------------------------------------------------------- *
5* This is the main variant of interest as it uses the Odin32-API while being *
6* a Native OS/2 application and thus in LX-format. One could say this variant *
7* is 'Odin Aware' because it is built against Odin32 from the source-level. *
8* Another term is 'Odin Based'. *
9\*****************************************************************************/
10
11
12/*
13// Standard C/C++ Headers
14*/
15#include <stdlib.h>
16#include <stdio.h>
17#include <string.h>
18
19
20
21/*
22// Platform Headers for Odin32
23*/
24//#include <os2wrap.h>
25#include <windows.h>
26//#include <wingdi.h>
27#include <odinlx.h>
28
29
30
31/*
32// Module Headers
33*/
34#include "ids.h"
35#include "ApiTestOdin.hpp"
36
37
38
39/*
40// Window Procedure
41*/
42LRESULT CALLBACK Odin32WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
43
44 /*
45 // Local Variables follow here.
46 */
47 LRESULT lres = (LRESULT) 0;
48 //ERRORID err = -1;
49
50 /*
51 // The Message Switch
52 */
53 switch (msg) {
54
55 /*
56 // Initial Window Creation.
57 */
58 case WM_CREATE:
59 printf("WM_CREATE received\n");
60 lres = DefWindowProc(hwnd, msg, wparam, lparam);
61 /*
62 // Create a button on the client-window
63 */
64 do {
65 HWND hwndButton = NULL;
66 //break;
67 /* Create the button */
68 hwndButton = CreateWindow(
69 "BUTTON", // Window Class
70 "Bye", // The button-text
71 WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, // The button-style
72 20, // The x-pos from ulc
73 600-20-50-50, // The y-pos from ulc
74 100, // Width of the button
75 50, // Height of the button
76 hwnd, // Owner Window
77 (HMENU)ID_EXIT, // Button ID
78 (HANDLE)NULL, // Module Instance
79 (LPVOID)NULL // Create Structure (NA)
80 );
81
82 /* Give the focus to the button */
83 SetFocus(hwndButton);
84 } while (0);
85 break;
86
87 /*
88 // Commands sent by Controls.
89 */
90 case WM_COMMAND:
91 switch (LOWORD(wparam)) {
92
93 /* Message from the button, we post a message to close the window */
94 case ID_EXIT:
95 PostMessage(hwnd, WM_CLOSE, NULL, NULL);
96 break;
97
98 /* Message from the button, we post a message to close the window */
99 case ID_FILE_EXIT:
100 PostMessage(hwnd, WM_CLOSE, NULL, NULL);
101 break;
102
103 /* Messages from the Testing Menu */
104 case ID_TESTING_TEST1:
105 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
106 break;
107 case ID_TESTING_TEST2:
108 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
109 break;
110 case ID_TESTING_TEST3:
111 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
112 break;
113 case ID_TESTING_TEST4:
114 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
115 break;
116 case ID_TESTING_TEST5:
117 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
118 break;
119 case ID_TESTING_TEST6:
120 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
121 break;
122 case ID_TESTING_TEST7:
123 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
124 break;
125 case ID_TESTING_TEST8:
126 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
127 break;
128 case ID_TESTING_TEST9:
129 printf("WM_COMMAND received (Testing), id: %04d\n", LOWORD(wparam));
130 break;
131
132 /* Messages from the Usp10 Menu */
133 case ID_USP10_TEST1:
134 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
135 break;
136 case ID_USP10_TEST2:
137 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
138 break;
139 case ID_USP10_TEST3:
140 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
141 break;
142 case ID_USP10_TEST4:
143 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
144 break;
145 case ID_USP10_TEST5:
146 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
147 break;
148 case ID_USP10_TEST6:
149 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
150 break;
151 case ID_USP10_TEST7:
152 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
153 break;
154 case ID_USP10_TEST8:
155 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
156 break;
157 case ID_USP10_TEST9:
158 printf("WM_COMMAND received (Usp10), id: %04d\n", LOWORD(wparam));
159 break;
160
161 /* Messages from the Gdiplus Menu */
162 case ID_GDIPLUS_TEST1:
163 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
164 break;
165 case ID_GDIPLUS_TEST2:
166 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
167 break;
168 case ID_GDIPLUS_TEST3:
169 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
170 break;
171 case ID_GDIPLUS_TEST4:
172 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
173 break;
174 case ID_GDIPLUS_TEST5:
175 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
176 break;
177 case ID_GDIPLUS_TEST6:
178 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
179 break;
180 case ID_GDIPLUS_TEST7:
181 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
182 break;
183 case ID_GDIPLUS_TEST8:
184 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
185 break;
186 case ID_GDIPLUS_TEST9:
187 printf("WM_COMMAND received (Gdiplus), id: %04d\n", LOWORD(wparam));
188 break;
189
190 default:
191 lres = DefWindowProc(hwnd, msg, wparam, lparam);
192 break;
193 }
194 break; /*WM_COMMAND*/
195
196 /*
197 // This message is generated by a call to PostQuitMessage() or the
198 // posting of a WM_QUIT message. It causes GetMessage() to return zero
199 // and thus the message-loop to end. So this message is never
200 // dispatched and this case thus never reached. After the message-loop
201 // ends, the message-structure contains this message with an exit-code
202 // (from PostQuitMessage()) in wParam.
203 */
204 case WM_QUIT:
205 printf("WM_QUIT received\n");
206 lres = DefWindowProc(hwnd, msg, wparam, lparam);
207 break;
208
209 /*
210 // This message is sent when the close-button is clicked.
211 // On Win32, DefWindowProc() does a DestroyWindow(), but does not post
212 // a WM_QUIT message and thus does not terminate the message-loop.
213 */
214 case WM_CLOSE:
215 printf("WM_CLOSE received\n");
216 lres = DefWindowProc(hwnd, msg, wparam, lparam);
217 break;
218
219 /*
220 // This message is generated by a call to DestroyWindow().
221 // At the time this message is received, the windows and its children
222 // are not destroyed yet.
223 */
224 case WM_DESTROY:
225 printf("WM_DESTROY received\n");
226 lres = DefWindowProc(hwnd, msg, wparam, lparam);
227 PostQuitMessage(99);
228 break;
229
230 /*
231 // Show some info.
232 */
233 case WM_PAINT:
234 printf("WM_PAINT received\n");
235 do {
236 BOOL brc = FALSE;
237 PAINTSTRUCT ps;
238 CHAR buf[512] = {0};
239 CHAR buf2[512] = {0};
240 HDC hdc = NULL;
241 int y = 0;
242 int dy = 20;
243 hdc = BeginPaint(hwnd, &ps);
244 brc = TextOut(hdc, 0, 0, "Hello !!", strlen("Hello !!"));
245 GetWindowsDirectory(buf2, sizeof(buf2));
246 sprintf(buf, "WindowsDir: %s", buf2);
247 brc = TextOut(hdc, 0, y+=dy, buf, strlen(buf));
248 GetSystemDirectory(buf2, sizeof(buf2));
249 sprintf(buf, "SystemDir: %s", buf2);
250 brc = TextOut(hdc, 0, y+=dy, buf, strlen(buf));
251 EndPaint(hwnd, &ps);
252 lres = 0;
253 } while (0);
254
255 //lres = DefWindowProc(hwnd, msg, wparam, lparam);
256 break;
257
258 /*
259 // Pass all unhandled messages to the default handler.
260 */
261 default: {
262 lres = DefWindowProc(hwnd, msg, wparam, lparam);
263 break;
264 }
265
266 }
267 // Return result.
268 return(lres);
269
270}
271
272
273
274/*
275// Gui EntryPoint for Odin32
276*/
277int WINAPI OdinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
278 WNDCLASS wc; // Window Class Structure
279 LPCSTR MainWndClass = "ApiTestOdin"; // Window Class Name
280 HWND hwnd = NULL; // Receives Window Handle
281 HACCEL hAccelerators = NULL; // Handle for Accelerators
282 HMENU hSysMenu = NULL; // Handle for System Menu
283 MSG msg; // Message Structure
284
285 /* Window Class Structure */
286 wc.style = CS_HREDRAW | CS_VREDRAW;
287 wc.lpfnWndProc = Odin32WindowProc;
288 wc.cbClsExtra = 0;
289 wc.cbWndExtra = 0;
290 wc.hInstance = hInstance;
291 wc.hIcon = (HICON)0;
292 wc.hCursor = LoadCursor((HINSTANCE)0, IDC_ARROW );
293 wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
294 wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
295 wc.lpszClassName = MainWndClass;
296
297 /* Window Class Structure (Ex) */
298// wc.cbSize = sizeof(wc);
299// wc.style = CS_HREDRAW | CS_VREDRAW;
300// wc.lpfnWndProc = Odin32WindowProc;
301// wc.cbClsExtra = 0;
302// wc.cbWndExtra = 0;
303// wc.hInstance = hInstance;
304// wc.hIcon = (HICON) NULL;
305// wc.hCursor = (HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
306// wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
307// wc.lpszMenuName = NULL;
308// wc.lpszClassName = MainWndClass;
309// wc.hIconSm = (HICON) NULL;
310
311 /*
312 // Show some info.
313 // This does not work under Win32s because the Win16 system has no stdout.
314 */
315 do {
316 char buf[512] = {0};
317 break;
318 GetCurrentDirectory(sizeof(buf), buf);
319 printf("Creating Window...\n");
320 GetCurrentDirectory(sizeof(buf), buf);
321 printf("CurDir : %s\n", buf);
322 GetWindowsDirectory(buf, sizeof(buf));
323 printf("WindowsDir : %s\n", buf);
324 GetSystemDirectory(buf, sizeof(buf));
325 printf("SystemDir : %s\n", buf);
326 printf("WINDOWSPATH : %s\n", getenv("WINDOWSPATH"));
327 printf("INCLUDE : %s\n", getenv("INCLUDE"));
328 printf("CommandLine : %s\n", lpCmdLine);
329 } while (0);
330
331
332 /* Register the class of the Main Window */
333 RegisterClass(&wc);
334
335 /* Create the Main Window */
336 hwnd = CreateWindow(
337 MainWndClass, // Our Window Class
338 "ApiTestOdin :: Main Window [generated:201602091922]", // Caption Text
339 WS_OVERLAPPEDWINDOW, // Window Stype
340 100, // The x-pos from ulc
341 100, // The y-pos from ulc
342 800, // Width of the window
343 600, // Height of the window
344 (HWND)0, // Owner Window
345 (HMENU)0, // Menu Handle
346 hInstance, // Module Instance
347 NULL // Create Structure
348 );
349
350 /* Show the Window */
351 ShowWindow(hwnd, nCmdShow);
352
353 /* Force a Paint */
354 UpdateWindow(hwnd);
355
356 /* Enter the message-processing loop */
357 while(GetMessage(&msg, NULL, 0, 0) > 0) {
358 if (! TranslateAccelerator(msg.hwnd, hAccelerators, &msg)) {
359 TranslateMessage(&msg);
360 DispatchMessage(&msg);
361 }
362 }
363
364 /* Last Message Info */
365 printf("\n");
366 printf("Last Message:\n");
367 printf("msg.hwnd=%08X\n", msg.hwnd);
368 printf("msg.message=%08X (%d)\n", msg.message, msg.message);
369 printf("msg.wParam=%08X (%d)\n", msg.wParam, msg.wParam);
370 printf("msg.lParam=%08X (%d)\n", msg.lParam, msg.lParam);
371
372 /* App is terminating */
373 printf("\n");
374 printf("ApiTestOdin is terminating...\n");
375
376 /* Return our reply-code */
377 return (int) msg.wParam;
378}
379
380
381
382/*
383// This is the standard C/C++ EntryPoint
384*/
385int main(int argc, char* argv[]) {
386 printf("\n");
387 printf("%s\n","###############################################################################");
388 printf("%s\n","# This is the Odin variant of ApiTest version.201602091922 #");
389 printf("%s\n","###############################################################################");
390 printf("\n");
391 printf("%s\n","Switching to Graphical Mode with this Window as a Console Log...");
392
393
394 /*
395 // The graphical part is encapsulated in a separate function so we can
396 // easily fiddle with it.
397 */
398// OdinMain(NULL, NULL, NULL, NULL);
399 RegisterLxExe((WINMAIN) OdinMain, (PVOID) &Resource_PEResTab);
400 return 0;
401}
402
Note: See TracBrowser for help on using the repository browser.