home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk12 / expand / expand.c next >
Encoding:
C/C++ Source or Header  |  1990-07-05  |  4.5 KB  |  186 lines

  1. #define INCL_PM
  2. #include <OS2.H>
  3. #include "Expand.H"
  4.  
  5. MRESULT EXPENTRY WndProc      (HWND, USHORT, MPARAM, MPARAM );
  6. MRESULT EXPENTRY AboutDlgProc (HWND, USHORT, MPARAM, MPARAM);
  7. MRESULT EXPENTRY DialogProc  (HWND, USHORT, MPARAM, MPARAM);
  8.  
  9. int cdecl main(void);
  10.  
  11. char szAppName[] = "Expand";
  12.  
  13. HAB    hAB;
  14. HMQ    hmqMsgQueue;
  15. HWND    hWndMain,
  16.     hWndFrame;
  17.  
  18. int cdecl main()
  19. {
  20.     QMSG    qmsg;
  21.     ULONG   ctlData;
  22.  
  23.     hAB = WinInitialize (0);
  24.     hmqMsgQueue = WinCreateMsgQueue (hAB, 0);
  25.  
  26.     if (!WinRegisterClass (hAB,
  27.                szAppName,
  28.                WndProc,
  29.                CS_SYNCPAINT | CS_SIZEREDRAW,
  30.                0)) {
  31.     return(0);
  32.     }
  33.  
  34.  
  35.     ctlData = FCF_STANDARD;
  36.     hWndFrame = WinCreateStdWindow ( HWND_DESKTOP,
  37.                     WS_VISIBLE,
  38.                     &ctlData,
  39.                     szAppName,
  40.                     NULL,
  41.                     0L,
  42.                     0,
  43.                     ID_RESOURCE,
  44.                     &hWndMain);
  45.     WinSetWindowText (hWndFrame, szAppName);
  46.     WinShowWindow (hWndFrame, TRUE);
  47.  
  48.     while ( WinGetMsg (hAB, &qmsg, NULL, 0, 0)) {
  49.     WinDispatchMsg (hAB, &qmsg);
  50.     }
  51.  
  52.     WinDestroyWindow   (hWndFrame);
  53.     WinDestroyMsgQueue (hmqMsgQueue);
  54.     WinTerminate       (hAB);
  55. }
  56.  
  57. MRESULT EXPENTRY WndProc (hWnd, msg, mp1, mp2)
  58.     HWND    hWnd;
  59.     USHORT  msg;
  60.     MPARAM  mp1, mp2;
  61. {
  62.     HPS    hPS;
  63.     RECTL   rclPaint, rclWindow;
  64.     POINTL  ptlPatternRef;
  65.  
  66.     switch (msg) {
  67.  
  68.     case WM_COMMAND:
  69.         switch (COMMANDMSG(&msg)->cmd) {
  70.         case IDM_ABOUT:
  71.             WinDlgBox(HWND_DESKTOP, hWnd, AboutDlgProc,
  72.             (HMODULE) NULL, ID_RESOURCE, NULL);
  73.             break;
  74.  
  75.         case IDM_ITEM+1:
  76.             WinDlgBox(HWND_DESKTOP, hWnd, DialogProc,
  77.             (HMODULE) NULL, ID_DIALOG, NULL);
  78.             break;
  79.  
  80.         case IDM_ITEM+2:
  81.         case IDM_ITEM+3:
  82.         case IDM_ITEM+4:
  83.             break;
  84.  
  85.         case IDM_EXIT:
  86.             WinPostMsg (hWnd, WM_CLOSE, 0L, 0L);
  87.             break;
  88.         }
  89.         break;
  90.  
  91.     case WM_HELP:
  92.         WinMessageBox (HWND_DESKTOP, hWnd,
  93.         "Help Not Implemented Yet.",
  94.         " - Help - ",
  95.         0,
  96.         MB_OK | MB_MOVEABLE | MB_APPLMODAL);
  97.         break;
  98.  
  99.     case WM_CLOSE:
  100.         WinPostMsg (hWnd, WM_QUIT, 0L, 0L);
  101.         break;
  102.  
  103.     case WM_PAINT:
  104.         hPS = WinBeginPaint (hWnd, NULL, &rclPaint);
  105.  
  106.         WinQueryWindowRect(hWnd, &rclWindow);
  107.         ptlPatternRef.x = rclWindow.xLeft;
  108.         ptlPatternRef.y = rclWindow.yTop;
  109.         GpiSetPatternRefPoint(hPS, &ptlPatternRef);
  110.         WinFillRect(hPS, &rclPaint, SYSCLR_APPWORKSPACE);
  111.  
  112.         WinEndPaint (hPS);
  113.         break;
  114.  
  115.     default:
  116.         return (WinDefWindowProc (hWnd, msg, mp1, mp2));
  117.     }
  118.     return 0L;
  119. }
  120.  
  121.  
  122. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  123. {
  124.     switch (msg) {
  125.     case WM_COMMAND:
  126.         switch (COMMANDMSG(&msg)->cmd) {
  127.         case IDB_OK:
  128.             WinDismissDlg (hwnd, TRUE);
  129.             return 0;
  130.         }
  131.         break;
  132.      }
  133.      return WinDefDlgProc (hwnd, msg, mp1, mp2);
  134. }
  135.  
  136. MRESULT EXPENTRY DialogProc (HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2)
  137. {
  138.     SWP  swpDlg, swpParent, swpOwner;
  139.     static HWND option, button1, button2, button3, button4;
  140.  
  141.     switch (msg) {
  142.  
  143.     case WM_INITDLG:
  144.         WinSendDlgItemMsg (hDlg, 256, EM_SETTEXTLIMIT, MPFROMSHORT(8), 0L);
  145.         WinQueryWindowPos (hDlg, &swpDlg);
  146.         WinQueryWindowPos (WinQueryWindow(hDlg, QW_PARENT, FALSE), &swpParent);
  147.         WinQueryWindowPos (WinQueryWindow(hDlg, QW_OWNER, FALSE), &swpOwner);
  148.         swpDlg.x = swpOwner.x + ((swpOwner.cx / 2) - ((swpDlg.cx+120) / 2));
  149.         swpDlg.y = swpOwner.y + ((swpOwner.cy / 2) - (swpDlg.cy / 2));
  150.         WinSetMultWindowPos (hAB, &swpDlg, 1);
  151.         option  = WinWindowFromID (hDlg, IDB_OPTION);
  152.         button1 = WinWindowFromID (hDlg, IDB_RADIO1);
  153.         WinShowWindow (button1, FALSE);
  154.         button2 = WinWindowFromID (hDlg, IDB_RADIO2);
  155.         WinShowWindow (button2, FALSE);
  156.         button3 = WinWindowFromID (hDlg, IDB_RADIO3);
  157.         WinShowWindow (button3, FALSE);
  158.         button4 = WinWindowFromID (hDlg, IDB_RADIO4);
  159.         WinShowWindow (button4, FALSE);
  160.         break;
  161.  
  162.     case WM_COMMAND:
  163.         switch (COMMANDMSG(&msg)->cmd) {
  164.         case IDB_OPTION:
  165.             WinQueryWindowPos (hDlg, &swpDlg);
  166.             swpDlg.fs = SWP_SIZE;
  167.             swpDlg.cx += 120;
  168.             WinSetMultWindowPos (hAB, &swpDlg, 1);
  169.             WinEnableWindow (option, FALSE);
  170.             WinShowWindow (button1, TRUE);
  171.             WinShowWindow (button2, TRUE);
  172.             WinShowWindow (button3, TRUE);
  173.             WinShowWindow (button4, TRUE);
  174.             WinSetFocus (HWND_DESKTOP, button1);
  175.             return FALSE;
  176.  
  177.         case IDB_OK:
  178.         case IDB_CANCEL:
  179.             WinDismissDlg (hDlg, TRUE);
  180.             return 0;
  181.         }
  182.         break;
  183.      }
  184.      return WinDefDlgProc (hDlg, msg, mp1, mp2);
  185. }
  186.