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

  1. /* entryfld.c -- Upper case conversion subclass procedure */
  2.  
  3. #define INCL_PM
  4. #define INCL_BASE
  5. #include <OS2.H>
  6.  
  7. #include <ctype.h>
  8.  
  9. #include "entryfld.h"
  10.  
  11. /***************************************************************************
  12.  *                                                                         *
  13.  *  Pointer to window procedure for WC_ENTRYFIELD window class.  We        *
  14.  *  use this to subclass the entry field.  This field is initialized       *
  15.  *  in RegisterEntryFieldClasses().                                        *
  16.  *                                                                         *
  17.  ***************************************************************************/
  18.  
  19. static PFNWP pfnEditWndProc;
  20.  
  21. /***************************************************************************
  22.  *                                                                         *
  23.  *  UDUpperWndProc                                                         *
  24.  *                                                                         *
  25.  *  Subclass edit fields for all uppercase, printable input                *
  26.  *                                                                         *
  27.  ***************************************************************************/
  28.  
  29. static MRESULT EXPENTRY UDUpperWndProc (
  30. HWND    hwnd,
  31. USHORT  msg,
  32. MPARAM  mp1,
  33. MPARAM  mp2)
  34. {
  35.     CHRMSG    *p;                      /* --> entire character msg */
  36.  
  37.     if (msg == WM_CHAR)
  38.     {                  /* Upper case conversion code taken from */
  39.                        /* Cheatham, Reich, Robinson -- */
  40.                        /* "OS/2 Presentation Manager Programming" */
  41.         p = CHARMSG (&msg);     /* Get char msg */
  42.         if (((p->fs & (KC_KEYUP|KC_CHAR)) == KC_CHAR)  /* Only want */
  43.             && (! (p->fs & KC_VIRTUALKEY) ) ) /* key downstroke message */
  44.         {
  45.             if (isalpha (p->chr) && islower (p->chr))  /* Lower case? */
  46.                 p->chr = (USHORT) _toupper ((UCHAR)p->chr);  /* Up it */
  47.                        /* end of extract from "OS/2 PM Programming" */
  48.  
  49.             if (!isprint (p->chr))   /* Eliminate non-printables */
  50.             {
  51.                 WinAlarm (HWND_DESKTOP, WA_ERROR);  /* Warn the user */
  52.                 return ((MRESULT) TRUE);  /* Say we processed the msg */
  53.             }
  54.  
  55.         }
  56.     } 
  57.  
  58.     return (pfnEditWndProc(hwnd, msg, mp1, mp2));
  59. }
  60.  
  61.  
  62.  
  63. /***************************************************************************
  64.  *                                                                         *
  65.  *  Register the entry field classes.  Return TRUE if successfull, FALSE   *
  66.  *  if not successful.  We register the class and save the entry point     *
  67.  *  to the original entry field procedure for later use.                   *
  68.  *                                                                         *
  69.  ***************************************************************************/
  70.  
  71. USHORT  RegisterEntryFieldClasses (     /* Register entry field classes */
  72. HAB     hab)                            /* I - Handle to anchor block */
  73. {
  74.     CLASSINFO   ci;                     /* Window class information */
  75.  
  76.                                         /* Get window class data */
  77.     WinQueryClassInfo (hab, WC_ENTRYFIELD, &ci);
  78.  
  79.                                         /* Save WC_ENTRYFIELD procedure */
  80.     pfnEditWndProc = ci.pfnWindowProc;
  81.  
  82.                                         /* Register our new class */
  83.     return (WinRegisterClass(hab, WC_UDUPPER, UDUpperWndProc, CS_SIZEREDRAW,
  84.                             ci.cbWindowData));
  85.  
  86. }
  87.  
  88. /* entryfld.c */
  89.