home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sample8.zip / SAMPLE8.CPP next >
C/C++ Source or Header  |  1997-05-17  |  5KB  |  125 lines

  1. //---------------------------------------------------------------------------------------------
  2. // File SAMPLE8.CPP (Example for OS/2 e-Zine!) Eric Slaats 1997
  3. //
  4. // May 1997
  5. // Created with Smalled
  6. //
  7. // Introduction to dialogs
  8. //---------------------------------------------------------------------------------------------
  9. #define INCL_WIN
  10. #define INCL_DOS
  11.  
  12. #include <os2.h>
  13. #include <stdio.h>
  14. #include "sample8.h"
  15. //------------------------------------------------------------------------------
  16. // Prototypes
  17. //------------------------------------------------------------------------------
  18. MRESULT EXPENTRY ClientWndProc (HWND,ULONG,MPARAM,MPARAM);
  19.  
  20. HWND hwndFrame;
  21.  
  22. void main()
  23.      {
  24.      HAB   hab;                    // Anchor
  25.      HMQ   hmq;                    // Message queue handle
  26.      QMSG  qmsg;                   // Message struct
  27.      HWND  hwndClient;             // Client window handles
  28.  
  29.     ULONG flFrameFlags = FCF_TITLEBAR   |FCF_SYSMENU |FCF_SHELLPOSITION |
  30.                           FCF_SIZEBORDER |FCF_MINMAX  |FCF_TASKLIST|
  31.                           FCF_MENU;
  32.  
  33.      //-------------------------------------------------------------------------
  34.      // Initialize application and create message queue
  35.      //-------------------------------------------------------------------------
  36.      hab = WinInitialize (0);
  37.      hmq = WinCreateMsgQueue (hab, 0);
  38.      //-------------------------------------------------------------------------
  39.      // Register class and create window
  40.      //-------------------------------------------------------------------------
  41.      WinRegisterClass (hab, "SampleClass", ClientWndProc, CS_SIZEREDRAW, 0);
  42.  
  43.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP,     // Parent
  44.                                      WS_VISIBLE,       // Style (visible)
  45.                                      &flFrameFlags,    // Creation flags
  46.                                      "SampleClass",    // Class name
  47.                                      "Sample8 for OS/2 e-Zine!",// Titlebar text
  48.                               0,                // Client style
  49.                                      NULLHANDLE,       // Resource handle
  50.                                      MAIN,             // Frame ID
  51.                                      &hwndClient);     // Client handle
  52.      //-------------------------------------------------------------------------
  53.      // Message loop
  54.      //-------------------------------------------------------------------------
  55.      while (WinGetMsg (hab, &qmsg, 0, 0, 0))
  56.            WinDispatchMsg (hab, &qmsg);
  57.      //-------------------------------------------------------------------------
  58.      // Clean up (destroy window, queue and hab)
  59.      //-------------------------------------------------------------------------
  60.     WinDestroyWindow (hwndFrame);
  61.     WinDestroyMsgQueue (hmq);
  62.     WinTerminate (hab);
  63.     }
  64.  
  65.  
  66. //------------------------------------------------------------------------------
  67. // Window procedure
  68. //------------------------------------------------------------------------------
  69. MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  70.     {
  71.     switch (msg)
  72.         {
  73.         //--------------------------------------------------------------------
  74.         // Fill client with default color
  75.         //--------------------------------------------------------------------
  76.         case WM_PAINT:
  77.             {
  78.                RECTL rectl ;
  79.                HPS   hps;
  80.  
  81.                hps = WinBeginPaint( hwnd, (HPS) NULL, &rectl);
  82.             WinFillRect( hps, (PRECTL)&rectl, CLR_DARKGRAY);
  83.                WinEndPaint( hps );
  84.                }
  85.         return MRFROMSHORT(TRUE);
  86.         //--------------------------------------------------------------------
  87.         // Handling of the menu-items and the button by WM_COMMAND
  88.         //--------------------------------------------------------------------
  89.         case WM_COMMAND:
  90.             {
  91.             switch(SHORT1FROMMP(mp1))
  92.                 {
  93.                 case IDM_BOX_11:
  94.                     WinMessageBox(hwnd, hwnd, "Owner and Parent clientwindow", "Modal box", 1, MB_OK|MB_MOVEABLE|MB_SYSTEMMODAL);
  95.                 break;
  96.  
  97.                 case IDM_BOX_12:
  98.                     WinMessageBox(HWND_DESKTOP, hwnd, "Owner=clientwindow Parent=Desktop", "Modal box", 1, MB_OK|MB_MOVEABLE|MB_SYSTEMMODAL);
  99.                 break;
  100.  
  101.                 case IDM_BOX_21:
  102.                     WinMessageBox(hwnd, hwnd, "Owner and Parent clientwindow", "Modeless box", 1, MB_OK|MB_MOVEABLE);
  103.                 break;
  104.  
  105.                 case IDM_BOX_22:
  106.                     WinMessageBox(hwnd, HWND_DESKTOP, "Owner=clientwindow Parent=Desktop", "Modeless box", 1, MB_OK|MB_MOVEABLE);
  107.                 break;
  108.  
  109.                 case IDM_BOX_23:
  110.                     WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Owner=DESKTOP Parent=Desktop", "Modeless box", 1, MB_OK|MB_MOVEABLE);
  111.                 break;
  112.                 case IDM_ABOUT:
  113.                     WinMessageBox(hwnd,hwnd, "Sample8 for OS/2 e-Zine!", "About", 0, MB_OK|MB_MOVEABLE|MB_SYSTEMMODAL);
  114.                 break;
  115.                 }
  116.             //---------------------------------------------------------------
  117.             // Display message box
  118.             //---------------------------------------------------------------
  119.             }
  120.         break;
  121.         }
  122.     return (WinDefWindowProc (hwnd,msg,mp1,mp2));
  123.     }
  124.  
  125.