| 1 | //! GENINFO :: platform:OS/2, version:20.45, target:ApiTest.generate
|
|---|
| 2 | /*****************************************************************************\
|
|---|
| 3 | * ApiTestPm.cpp :: This is the PM variant of ApiTest *
|
|---|
| 4 | * --------------------------------------------------------------------------- *
|
|---|
| 5 | * The PM version has a different purpose than the Odin Based and Windows *
|
|---|
| 6 | * variants. Here the focus is not directly on testing the Odin32-API, but *
|
|---|
| 7 | * rather on testing the OS/2-API. While Odin implements a lot of Win32 *
|
|---|
| 8 | * functionality from scratch, there are also situations where things are *
|
|---|
| 9 | * delegated to OS/2. This variant provides that angle. *
|
|---|
| 10 | \*****************************************************************************/
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | /*
|
|---|
| 14 | // Standard C/C++ Headers
|
|---|
| 15 | */
|
|---|
| 16 | #include <stdlib.h>
|
|---|
| 17 | #include <stdio.h>
|
|---|
| 18 | #include <string.h>
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | /*
|
|---|
| 23 | // Platform Headers for OS/2
|
|---|
| 24 | */
|
|---|
| 25 | #define INCL_DOS
|
|---|
| 26 | #define INCL_WIN
|
|---|
| 27 | #include <os2.h>
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | /*
|
|---|
| 32 | // Module Headers
|
|---|
| 33 | */
|
|---|
| 34 | #include "ids.h"
|
|---|
| 35 | #include "ApiTestPm.hpp"
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | /*
|
|---|
| 40 | // Minimal Window Procedure
|
|---|
| 41 | */
|
|---|
| 42 | MRESULT EXPENTRY Pm32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) {
|
|---|
| 43 | /*
|
|---|
| 44 | // Local Variables follow here.
|
|---|
| 45 | */
|
|---|
| 46 | MRESULT mres = (MRESULT) 0;
|
|---|
| 47 | ERRORID err = -1;
|
|---|
| 48 |
|
|---|
| 49 | /*
|
|---|
| 50 | // The Message Switch
|
|---|
| 51 | */
|
|---|
| 52 | switch (msg) {
|
|---|
| 53 |
|
|---|
| 54 | /*
|
|---|
| 55 | // Initial Window Creation.
|
|---|
| 56 | */
|
|---|
| 57 | case WM_CREATE:
|
|---|
| 58 | printf("WM_CREATE received\n");
|
|---|
| 59 | mres = WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 60 | /*
|
|---|
| 61 | // Create a button on the client-window
|
|---|
| 62 | */
|
|---|
| 63 | do {
|
|---|
| 64 | HWND hwndButton = NULLHANDLE;
|
|---|
| 65 | //break;
|
|---|
| 66 | /* Create the button */
|
|---|
| 67 | hwndButton = WinCreateWindow(
|
|---|
| 68 | hwnd, // Parent (client-window)
|
|---|
| 69 | WC_BUTTON, // We want a window of class WC_BUTTON
|
|---|
| 70 | (PSZ)"Bye", // The button-text
|
|---|
| 71 | WS_VISIBLE|BS_PUSHBUTTON, // Make it visible
|
|---|
| 72 | 20, // The x-pos from llc
|
|---|
| 73 | 20, // The y-pos from llc
|
|---|
| 74 | 100, // Width of the button
|
|---|
| 75 | 50, // Height of the button
|
|---|
| 76 | hwnd, // Owner (client-window)
|
|---|
| 77 | HWND_TOP, // Z-order
|
|---|
| 78 | ID_EXIT, // Window ID
|
|---|
| 79 | NULL, // Control Data (none)
|
|---|
| 80 | NULL // Presentation Parameters (none)
|
|---|
| 81 | );
|
|---|
| 82 | /* Give the focus to the button */
|
|---|
| 83 | WinSetFocus(HWND_DESKTOP, hwndButton);
|
|---|
| 84 | } while (0);
|
|---|
| 85 | break;
|
|---|
| 86 |
|
|---|
| 87 | /*
|
|---|
| 88 | // Commands sent by Controls.
|
|---|
| 89 | */
|
|---|
| 90 | case WM_COMMAND:
|
|---|
| 91 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 92 |
|
|---|
| 93 | /* Message from the button, we post a message to close the window */
|
|---|
| 94 | case ID_EXIT:
|
|---|
| 95 | WinPostMsg(hwnd, WM_CLOSE, NULL, NULL);
|
|---|
| 96 | break;
|
|---|
| 97 |
|
|---|
| 98 | /* Exit Message from the File Menu, forward it to ID_EXIT */
|
|---|
| 99 | case ID_FILE_EXIT:
|
|---|
| 100 | WinPostMsg(hwnd, WM_COMMAND, (MPARAM) ID_EXIT, NULL);
|
|---|
| 101 | break;
|
|---|
| 102 |
|
|---|
| 103 | /* Messages from the Testing Menu */
|
|---|
| 104 | case ID_TESTING_TEST1:
|
|---|
| 105 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 106 | break;
|
|---|
| 107 | case ID_TESTING_TEST2:
|
|---|
| 108 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 109 | break;
|
|---|
| 110 | case ID_TESTING_TEST3:
|
|---|
| 111 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 112 | break;
|
|---|
| 113 | case ID_TESTING_TEST4:
|
|---|
| 114 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 115 | break;
|
|---|
| 116 | case ID_TESTING_TEST5:
|
|---|
| 117 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 118 | break;
|
|---|
| 119 | case ID_TESTING_TEST6:
|
|---|
| 120 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 121 | break;
|
|---|
| 122 | case ID_TESTING_TEST7:
|
|---|
| 123 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 124 | break;
|
|---|
| 125 | case ID_TESTING_TEST8:
|
|---|
| 126 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 127 | break;
|
|---|
| 128 | case ID_TESTING_TEST9:
|
|---|
| 129 | printf("WM_COMMAND received (Testing), id: %04d\n", SHORT1FROMMP(mp1));
|
|---|
| 130 | break;
|
|---|
| 131 |
|
|---|
| 132 | default:
|
|---|
| 133 | mres = WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 134 | break;
|
|---|
| 135 | }
|
|---|
| 136 | break; /*WM_COMMAND*/
|
|---|
| 137 |
|
|---|
| 138 | /*
|
|---|
| 139 | // Background Erasure.
|
|---|
| 140 | */
|
|---|
| 141 | case WM_ERASEBACKGROUND:
|
|---|
| 142 | printf("WM_ERASEBACKGROUND received\n");
|
|---|
| 143 | mres = (MRESULT) TRUE;
|
|---|
| 144 | break;
|
|---|
| 145 |
|
|---|
| 146 | /*
|
|---|
| 147 | // Request to quit the application.
|
|---|
| 148 | */
|
|---|
| 149 | case WM_QUIT:
|
|---|
| 150 | printf("WM_QUIT received\n");
|
|---|
| 151 | mres = WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 152 | break;
|
|---|
| 153 |
|
|---|
| 154 | /*
|
|---|
| 155 | // Request to close the application.
|
|---|
| 156 | // On PM this this posts a WM_QUIT message which in turn terminates
|
|---|
| 157 | // the message-loop. Only an explicit call to WinDestroyWindow()
|
|---|
| 158 | // seems to generate a WM_DESTROY message, which we do after the loop
|
|---|
| 159 | // has terminated.
|
|---|
| 160 | // On Win32 WM_CLOSE does a DestroyWindow() but does not post a WM_QUIT
|
|---|
| 161 | // message and thus does not terminate the message-loop.
|
|---|
| 162 | */
|
|---|
| 163 | case WM_CLOSE:
|
|---|
| 164 | printf("WM_CLOSE received\n");
|
|---|
| 165 | mres = WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 166 | break;
|
|---|
| 167 |
|
|---|
| 168 | /*
|
|---|
| 169 | // Window is being destroyed, time to cleanup resources allocated.
|
|---|
| 170 | // This message seems only to be sent on a WinDestroyWindow() call.
|
|---|
| 171 | // When clicking the close-button and not doing an explicit
|
|---|
| 172 | // WinDestroyWindow() does not output the message below.
|
|---|
| 173 | */
|
|---|
| 174 | case WM_DESTROY:
|
|---|
| 175 | printf("WM_DESTROY received\n");
|
|---|
| 176 | mres = WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 177 | break;
|
|---|
| 178 |
|
|---|
| 179 | /*
|
|---|
| 180 | // Pass all unhandled messages to the default handler.
|
|---|
| 181 | */
|
|---|
| 182 | default: {
|
|---|
| 183 | mres = WinDefWindowProc(hwnd, msg, mp1, mp2);
|
|---|
| 184 | break;
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | /*
|
|---|
| 189 | // Return whatever was composed as a return-value in the switch above.
|
|---|
| 190 | */
|
|---|
| 191 | return mres;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 | /*
|
|---|
| 197 | // Gui EntryPoint for Presentation Manager
|
|---|
| 198 | */
|
|---|
| 199 | int APIENTRY PmMain(int argc, char* argv[]) {
|
|---|
| 200 | BOOL brc = FALSE; // Boolean return values
|
|---|
| 201 | APIRET ulrc = -1; // Numeric return values
|
|---|
| 202 | HAB hab = NULL; // Handle Anchor Block
|
|---|
| 203 | HMQ hmq = NULL; // Handle Message Queue
|
|---|
| 204 | QMSG qmsg = {0}; // Message Queue Structure
|
|---|
| 205 | ULONG flStyle = {0}; // Style Flags
|
|---|
| 206 | ULONG flCreateFlags = {
|
|---|
| 207 | FCF_SYSMENU | // Create a system-menu button
|
|---|
| 208 | FCF_TITLEBAR | // Create a title-bar
|
|---|
| 209 | FCF_MINMAX | // Create the min-max buttons (and close)
|
|---|
| 210 | FCF_CLOSEBUTTON | // Actually redundant, implied by FCF_MINMAX
|
|---|
| 211 | FCF_SIZEBORDER | // Draw a sizing-border
|
|---|
| 212 | FCF_NOBYTEALIGN | // Make horizontal positioning smooth
|
|---|
| 213 | FCF_MENU | // Load a menu
|
|---|
| 214 | FCF_TASKLIST // Put the beast in the task-list
|
|---|
| 215 | };
|
|---|
| 216 | PSZ pszClassClient = (PSZ) "ApiTestPm"; // Window Class Name
|
|---|
| 217 | PSZ pszTitle = (PSZ) "ApiTestPm :: Main Window [generated:201602091922]"; // Window Title
|
|---|
| 218 | ULONG flStyleClient = 0; // Style for Client Window
|
|---|
| 219 | HWND hwndFrame = NULL; // Receives handle for Frame Window
|
|---|
| 220 | HWND hwndClient = NULL; // Receives handle for Client Window
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | /*
|
|---|
| 224 | // Switch the process type to PM so the command line app can create PM
|
|---|
| 225 | // windows. This makes it possible to use printf() to stdout.
|
|---|
| 226 | */
|
|---|
| 227 | do {
|
|---|
| 228 | PTIB ptib;
|
|---|
| 229 | PPIB ppib;
|
|---|
| 230 | //break;
|
|---|
| 231 | if(DosGetInfoBlocks(&ptib, &ppib) == 0) {
|
|---|
| 232 | ppib->pib_ultype = 3;
|
|---|
| 233 | }
|
|---|
| 234 | } while (0);
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 | /* Initialize the PM Graphics System */
|
|---|
| 238 | hab = WinInitialize(NULL);
|
|---|
| 239 |
|
|---|
| 240 | /* Create the message-queue for this (main) thread */
|
|---|
| 241 | hmq = WinCreateMsgQueue(hab, 0);
|
|---|
| 242 |
|
|---|
| 243 | /* Register the class of the Main Window */
|
|---|
| 244 | brc = WinRegisterClass(hab, pszClassClient, Pm32WindowProc, CS_SIZEREDRAW, 0);
|
|---|
| 245 |
|
|---|
| 246 | /* Create the Main Window */
|
|---|
| 247 | hwndFrame = WinCreateStdWindow(
|
|---|
| 248 | HWND_DESKTOP, // Desktop is parent so this is a top-level Window
|
|---|
| 249 | flStyle, // Style stuff
|
|---|
| 250 | &flCreateFlags, // Creation options like min-max buttonts, etc.
|
|---|
| 251 | pszClassClient, // Classname for the Client
|
|---|
| 252 | pszTitle, // Title for the Window
|
|---|
| 253 | flStyleClient, // Style stuff
|
|---|
| 254 | NULL, // Module handle (null is current module)
|
|---|
| 255 | 1, // Window-ID
|
|---|
| 256 | &hwndClient // Storage for Client Handle
|
|---|
| 257 | );
|
|---|
| 258 |
|
|---|
| 259 |
|
|---|
| 260 | /*
|
|---|
| 261 | // Show the handles of the windows created.
|
|---|
| 262 | // The application has to be built as WINDOWCOMPAT and the code to change
|
|---|
| 263 | // the application-type to PM has to be active.
|
|---|
| 264 | */
|
|---|
| 265 | do {
|
|---|
| 266 | int delay = 1000;
|
|---|
| 267 | int i = 0;
|
|---|
| 268 | //break;
|
|---|
| 269 | printf("hwndFrame=%08X\n", hwndFrame);
|
|---|
| 270 | printf("hwndClient=%08X\n", hwndClient);
|
|---|
| 271 | break;
|
|---|
| 272 | for (i=5; i>0; i--) {
|
|---|
| 273 | i > 1 ? printf("Pausing for %d seconds...\n", i) : printf("Pausing for %d second...\n", i);
|
|---|
| 274 | DosSleep(delay);
|
|---|
| 275 | }
|
|---|
| 276 | printf("Continuing program...\n");
|
|---|
| 277 | } while (0);
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 | /* Set the size and position */
|
|---|
| 281 | brc = WinSetWindowPos(
|
|---|
| 282 | hwndFrame, // Window to position (FrameWindow)
|
|---|
| 283 | HWND_TOP, // Z-order
|
|---|
| 284 | 100, // The x-pos from llc
|
|---|
| 285 | 100, // The y-pos from llc
|
|---|
| 286 | 800, // Width
|
|---|
| 287 | 600, // Height
|
|---|
| 288 | SWP_MOVE | // Do the move
|
|---|
| 289 | SWP_SIZE | // Do the sizing
|
|---|
| 290 | SWP_ZORDER | // Do the z-ordering
|
|---|
| 291 | SWP_SHOW | // Make window visible
|
|---|
| 292 | SWP_ACTIVATE // Activate it
|
|---|
| 293 | );
|
|---|
| 294 |
|
|---|
| 295 | /* Enter the message-processing loop */
|
|---|
| 296 | while (WinGetMsg(hab, &qmsg, 0, 0, 0))
|
|---|
| 297 | WinDispatchMsg(hab, &qmsg);
|
|---|
| 298 |
|
|---|
| 299 | /* Destroy the Main Window -- causes WM_DESTROY to be sent */
|
|---|
| 300 | brc = WinDestroyWindow(hwndFrame);
|
|---|
| 301 |
|
|---|
| 302 | /* Destroy the message-queue for this (main) thread */
|
|---|
| 303 | brc = WinDestroyMsgQueue(hmq);
|
|---|
| 304 |
|
|---|
| 305 | /* Release the Graphics System */
|
|---|
| 306 | brc = WinTerminate(hab);
|
|---|
| 307 |
|
|---|
| 308 | /* App is terminating */
|
|---|
| 309 | printf("ApiTestPm is terminating...\n");
|
|---|
| 310 |
|
|---|
| 311 | /* Return our reply-code */
|
|---|
| 312 | return 0;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 | /*
|
|---|
| 318 | // This is the standard C/C++ EntryPoint
|
|---|
| 319 | */
|
|---|
| 320 | int main(int argc, char* argv[]) {
|
|---|
| 321 | printf("\n");
|
|---|
| 322 | printf("%s\n","###############################################################################");
|
|---|
| 323 | printf("%s\n","# This is the PM variant of ApiTest version.201602091922 #");
|
|---|
| 324 | printf("%s\n","###############################################################################");
|
|---|
| 325 | printf("\n");
|
|---|
| 326 | printf("%s\n","Switching to Graphical Mode with this Window as a Console Log...");
|
|---|
| 327 |
|
|---|
| 328 | /*
|
|---|
| 329 | // The graphical part is encapsulated in a separate function so we can
|
|---|
| 330 | // easily fiddle with it.
|
|---|
| 331 | */
|
|---|
| 332 | PmMain(argc, argv);
|
|---|
| 333 | return 0;
|
|---|
| 334 | }
|
|---|
| 335 |
|
|---|