home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / develo.zip / ZIP / SAMPLE.C next >
C/C++ Source or Header  |  1993-06-21  |  6KB  |  196 lines

  1. #define MAIN
  2. #define INCL_DOSFILEMGR
  3. #define INCL_PM
  4. #define INCL_WINDIALOGS
  5.  
  6. #include <os2.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <stddef.h>
  11. #include "sample.h"
  12. #include "wcpic16.h"
  13.  
  14. #define NULLHANDLE NULL
  15.  
  16. HAB   hAB;
  17. HMQ   hMQ;
  18. HWND  hwndFrame;
  19. HWND  hwndClient;
  20.  
  21. /********************************************************************\
  22. *                          Main Entrypoint                           * 
  23. \********************************************************************/
  24. int main(argc, argv)
  25. int argc;
  26. char *argv[];
  27. {
  28.    QMSG       qmsg;       // MSG structure to store your messages
  29.    ULONG      flStyle;
  30.    RECTL      rc;
  31.  
  32.    /*****************************************************************\
  33.    * The WinInitialize routine initializes the Presentation Manager  *
  34.    * facilities for use by this application and returns a handle to  *
  35.    * the anchor block assigned to the application by PM.             *
  36.    \*****************************************************************/
  37.    if((hAB = WinInitialize(0)) == 0)
  38.       return(FALSE);
  39.     
  40.    /*****************************************************************\
  41.    *  The WinCreateMsgQueue call creates a msg queue for this app.   *
  42.    /*****************************************************************/
  43.    if((hMQ = WinCreateMsgQueue(hAB, 0)) == 0)
  44.       return(FALSE);
  45.  
  46.    /*█████████████████████████████████████████████████████████████████
  47.    █                                                                 █
  48.    █  This is the only line of code you need to add to your codes.   █
  49.    █  Just initialize the entryfield picture mask window class.      █
  50.    █                                                                 █
  51.    ██████████████████████████████████████████████████████████████████*/
  52.     
  53.    fnInitWCPicMsk(hAB);
  54.  
  55.  
  56.  
  57.  
  58.    /*****************************************************************\
  59.    *  Register the sample window class                               * 
  60.    \*****************************************************************/
  61.    WinRegisterClass(hAB,                 // Anchor block handle
  62.                     (PCH)"SAMPLE",       // Name of class to register
  63.                     (PFNWP)WndProc,      // Window procedure for class
  64.                     CS_SIZEREDRAW ,
  65.                     0);
  66.  
  67.    flStyle = FCF_TITLEBAR     |  FCF_SYSMENU      |
  68.              FCF_MINBUTTON    |  FCF_MAXBUTTON    |
  69.              FCF_SIZEBORDER   |  FCF_TASKLIST     |
  70.              FCF_MENU;
  71.  
  72.    hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  73.                                   WS_VISIBLE,
  74.                                   &flStyle,
  75.                                   "SAMPLE",
  76.                                   "Picture Mask Sample Window",
  77.                                   WS_VISIBLE,
  78.                                   NULLHANDLE,
  79.                                   ID_SAMPLE,
  80.                                   &hwndClient);
  81.  
  82.    WinQueryWindowRect(HWND_DESKTOP, &rc);
  83.  
  84.    WinSetWindowPos(hwndFrame,
  85.                HWND_TOP,
  86.                (SHORT)(rc.xRight / 16L),
  87.                (SHORT)(rc.yTop / 6L),
  88.                (SHORT)(rc.xRight / 1.14L),
  89.                (SHORT)(rc.yTop / 1.5L),
  90.                SWP_ACTIVATE | SWP_SHOW | SWP_SIZE | SWP_MOVE
  91.                | SWP_ZORDER);
  92.  
  93.    /******************************************************************\
  94.     * The following is the message loop for the application.         * 
  95.    \******************************************************************/
  96.    while(WinGetMsg(hAB, (PQMSG)&qmsg, 0, 0, 0))
  97.          WinDispatchMsg(hAB,(PQMSG)&qmsg);
  98.  
  99.    /*****************************************************************\
  100.    * Cleanup and terminate                                           * 
  101.    \*****************************************************************/
  102.    WinDestroyWindow(hwndFrame); // Destroy the frame window
  103.    WinDestroyMsgQueue(hMQ);     // Destroy application's message queue
  104.    WinTerminate(hAB);           // Terminate application's use of the
  105.                                 // Presentation Manager resources
  106.  
  107.    DosExit(EXIT_PROCESS, 0);
  108. } /* end of main */
  109.  
  110.  
  111.  
  112. /********************************************************************\
  113. *                       Main Window Procedure                        * 
  114. \********************************************************************/
  115. MRESULT EXPENTRY WndProc(HWND hwnd, UINT msg, MPARAM mp1, MPARAM mp2)
  116. {
  117.    HPS      hps;
  118.    RECTL    rClient;
  119.  
  120.    switch(msg)
  121.      {
  122.       case WM_CREATE:
  123.            WinPostMsg(hwnd, WM_COMMAND, MPFROMSHORT(ID_M_ABOUT), 0L);
  124.            break;
  125.     
  126.       case WM_PAINT:
  127.            hps = WinBeginPaint(hwnd, NULLHANDLE, &rClient);
  128.            WinFillRect(hps, &rClient, SYSCLR_APPWORKSPACE);
  129.            WinEndPaint(hps);
  130.            break;
  131.  
  132.       case WM_COMMAND:
  133.            fnProcessCmd(hwnd, msg, mp1, mp2);
  134.            break;
  135.  
  136.       case WM_CLOSE:
  137.            WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  138.            break;
  139.  
  140.       default:
  141.            return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  142.      }
  143.  
  144.    return((MRESULT)0L);
  145. }
  146.  
  147.  
  148.  
  149.  
  150. VOID fnProcessCmd(HWND hwnd, UINT msg, MPARAM mp1, MPARAM mp2)
  151. {
  152.    ERRORID err;
  153.  
  154.    switch (SHORT1FROMMP(mp1))
  155.       {
  156.       case ID_M_DIALOG:
  157.            WinDlgBox(HWND_DESKTOP,
  158.                      hwnd,
  159.                      SampleDlgProc,
  160.                      NULLHANDLE,
  161.                      (LONG)IDLG_EMPINFO,
  162.                      NULL);
  163.  
  164.            err = WinGetLastError(hAB);
  165.            break;
  166.  
  167.       case ID_M_ABOUT:
  168.            WinDlgBox(hwnd,
  169.                      hwnd,
  170.                      AboutDlgProc,
  171.                      NULLHANDLE,
  172.                      IDLG_ABOUT,
  173.                      NULL);
  174.            break;
  175.  
  176.       case ID_M_EXIT:
  177.            WinPostMsg(hwnd, WM_CLOSE, 0L, 0L);
  178.            break;
  179.       }
  180.  
  181.    return ;
  182. }
  183.  
  184.  
  185. MRESULT EXPENTRY SampleDlgProc(HWND hwnd, UINT msg, MPARAM mp1, MPARAM mp2)
  186. {
  187.    return (WinDefDlgProc(hwnd, msg, mp1, mp2));
  188. }
  189.  
  190.  
  191. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, UINT msg, MPARAM mp1, MPARAM mp2)
  192. {
  193.    return (WinDefDlgProc(hwnd, msg, mp1, mp2));
  194. }
  195.  
  196.