home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / DAYFIELD.ZIP / DAYCRATE.C < prev    next >
C/C++ Source or Header  |  1989-07-28  |  3KB  |  105 lines

  1. /* ----------------------------------------------------------------------
  2. .context DayCreate
  3. .category Day-Field-Windows
  4. BOOL DayCreate ( HWND  hwnd, MPARAM mp1, MPARAM mp2 )
  5.  
  6. Description: 
  7.      This procedure creates a WC_ENTRYFIELD window that will then be
  8. subclassed to provide the error checking of the field.
  9.  
  10. Parameter     Description
  11. -------------------------------------------------------------------------
  12. hwnd          a 32 bit pointer for the window this message was sent to
  13.  
  14. mp1, mp2      see WM_CREATE
  15.  
  16. Returns: 
  17.  
  18. Comments: 
  19.  
  20. References: 
  21.  
  22. See Also: WM_CREATE, DayWinProc, DaySubWinProc, WinSubclassWindow
  23. .ref WM_CREATE, DayWinProc, DaySubWinProc, WinSubclassWindow
  24.  
  25. Development History: 
  26.   Date         Programmer          Description of modification   
  27.   07/20/1989   Paul Montgomery     Initial development           
  28. -------------------------------------------------------------------- */
  29.  
  30. #define INCL_PM
  31. #define INCL_DOSMODULEMGR
  32. #include <os2.h>
  33.  
  34. #include "day.h"
  35.  
  36. #include "daysubpr.h"
  37.  
  38. BOOL DayCreate ( HWND  hwnd, MPARAM mp1, MPARAM mp2 )
  39.    {
  40.    HPS hps;
  41.    FONTMETRICS fm;
  42.    PCREATESTRUCT pcs;
  43.    SEL           sel;
  44.    PDAYINFO      pdayi;
  45.    HMODULE       hmod;
  46.    PFNWP         pfentry;
  47.    SHORT         xchar, ychar;
  48.    CHAR          fname[4];
  49.  
  50.    // the "DAYFIELD" class needs some window specific data so we create a
  51.    // segment that we hang off of the hwnd.
  52.    DosAllocSeg(sizeof(DAYINFO), 
  53.        &sel,                    
  54.        0);                      
  55.    pdayi = MAKEP(sel, 0);       
  56.  
  57.    WinSetWindowULong(hwnd,PDAYI_OFFSET,(ULONG)pdayi);
  58.  
  59.    // part of the data we need is the handle for the DLL that this proc
  60.    // was loaded from.
  61.    DosLoadModule(fname, sizeof(fname), MODNAME, &hmod);             
  62.    WinSetWindowULong(hwnd,DAYHMOD_OFFSET,(ULONG)hmod);
  63.  
  64.    // figure out what it is we are supposed to look like and use the parms
  65.    // in the creation of the WC_ENTRYFIELD
  66.    pcs = (PCREATESTRUCT)mp2;
  67.  
  68.    // get the sizes of the character used in this window
  69.    hps = WinGetPS ( hwnd );
  70.    GpiQueryFontMetrics ( hps, (LONG) sizeof ( fm ), &fm );
  71.    ychar = (SHORT) fm.lMaxBaselineExt;
  72.    xchar = (SHORT) fm.lAveCharWidth;
  73.    WinReleasePS ( hps );
  74.  
  75.    // the WC_ENTRYFIELD if it is of style ES_MARGIN offsets itself and
  76.    // draws a border.  the offsets below allow this window to position 
  77.    // itself and the WC_ENTRYFIELD so that they are where the user really
  78.    // want them to be.
  79.  
  80.    pdayi->xoffset = (pcs->flStyle & ES_MARGIN )? xchar/2:0;
  81.    pdayi->yoffset = (pcs->flStyle & ES_MARGIN )? ychar/4:0;
  82.    pdayi->flStyle = pcs->flStyle;
  83.  
  84.    // create the WC_ENTRYFIELD window
  85.    pdayi->hwndEntry = WinCreateWindow ( hwnd,
  86.                      WC_ENTRYFIELD,
  87.                      pcs->pszText,
  88.                      pcs->flStyle,
  89.                      0,0,     // relative to this window
  90.                      pcs->cx,
  91.                      pcs->cy,
  92.                      pcs->hwndOwner,
  93.                      pcs->hwndInsertBehind,
  94.                      pcs->id,
  95.                      pcs->pCtlData,
  96.                      pcs->pPresParams);
  97.  
  98.    // subclass the WC_ENTRYFIELD window to do the filtering
  99.  
  100.    pfentry = WinSubclassWindow ( pdayi->hwndEntry, (PFNWP)DaySubWinProc );
  101.    WinSetWindowULong(pdayi->hwndEntry,QWL_USER,(ULONG)pfentry);
  102.  
  103.    return FALSE;
  104. }
  105.