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