home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mnth0101.zip / Sharf / subclass.c < prev    next >
C/C++ Source or Header  |  1991-12-15  |  4KB  |  96 lines

  1. /* subclass.c -- Sample program to demonstrate a private window class */
  2.  
  3. #define INCL_PM
  4. #define INCL_BASE
  5. #include <OS2.H>
  6. #include <process.h>
  7.  
  8. #include "entryfld.H"
  9.  
  10. static MRESULT EXPENTRY TestDlgProc (HWND, USHORT, MPARAM, MPARAM);
  11.  
  12. typedef struct                          /* Data area for dialog */
  13. {
  14.     CHAR    szTypedData[8];             /* Typed data area */
  15. } WWTEST, *PWWTEST;
  16.  
  17. void main (void)
  18. {
  19.     HAB        hab;                        /* Handle to anchor block */
  20.     HMQ        hmqMsgQueue;                /* Handle to message queue */
  21.     WWTEST  wwtest;                     /* Dialog communication area */
  22.  
  23.     hab = WinInitialize (0);            /* Initialize PM */
  24.  
  25.     if (!RegisterEntryFieldClasses (hab))  /* Register our classes */
  26.         exit (1);
  27.  
  28.     hmqMsgQueue = WinCreateMsgQueue (hab, 0);  /* Create message queue */
  29.  
  30.     WinDlgBox (HWND_DESKTOP, HWND_DESKTOP, TestDlgProc, 0,
  31.                IDLG_TEST, &wwtest);
  32.  
  33.     WinDestroyMsgQueue (hmqMsgQueue);   /* Shutdown */
  34.     WinTerminate       (hab);
  35. }
  36.  
  37. /***************************************************************************
  38.  *                                                                         *
  39.  *  TestDlgProc() -- A procedure to test our new control                   *
  40.  *                                                                         *
  41.  ***************************************************************************/
  42.  
  43. static MRESULT EXPENTRY TestDlgProc (
  44. HWND    hwndDlg,
  45. USHORT  msg,
  46. MPARAM  mp1,
  47. MPARAM  mp2)
  48. {
  49.     PWWTEST     pwwtest;                /* --> dialog data area */
  50.  
  51.     switch(msg)
  52.     {
  53.         case WM_INITDLG:                /* Save address of passed buffer */
  54.                                         /* So we can use it later */
  55.                                         /* (Dialog windows reserve 4 bytes */
  56.                                         /* at QWL_USER that we can use as */
  57.                                         /* we wish.  We usually use this as */
  58.                                         /* a pointer to data for the dialog */
  59.             WinSetWindowPtr (hwndDlg, QWL_USER, PVOIDFROMMP(mp2));
  60.                                         /* Don't allow more input than */
  61.                                         /* we can store */
  62.             WinSendDlgItemMsg (hwndDlg, IDEF_SUBCLASS_ENTRYFIELD,
  63.                                EM_SETTEXTLIMIT,
  64.                                MPFROMSHORT (sizeof (pwwtest->szTypedData)-1),
  65.                                0);
  66.             return 0;
  67.  
  68.         case WM_COMMAND:
  69.             switch(SHORT1FROMMP(mp1))
  70.             {
  71.                                         /* Cancel (ESC) key pressed */
  72.                                         /* Tell caller dialog was cancelled */
  73.                 case DID_CANCEL:
  74.                     WinDismissDlg(hwndDlg, FALSE);
  75.                     return 0;
  76.  
  77.                                         /* OK button (ENTER key) was pressed */
  78.                 case DID_OK:            /* Get address of caller's data area */
  79.                     pwwtest = WinQueryWindowPtr (hwndDlg, QWL_USER);
  80.                                         /* Read current contents of entry */
  81.                                         /* field into data area */
  82.                     WinQueryDlgItemText (hwndDlg, IDEF_SUBCLASS_ENTRYFIELD,
  83.                                          sizeof (pwwtest->szTypedData),
  84.                                          pwwtest->szTypedData);
  85.                                         /* Tell user all data is input */
  86.                     WinDismissDlg(hwndDlg, TRUE);
  87.                     return 0;
  88.             }
  89.             return 0;
  90.                                
  91.         default:
  92.             return(WinDefDlgProc(hwndDlg, msg, mp1, mp2));
  93.     }
  94.     return FALSE;
  95. }
  96.