home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / zfamily.zip / zfamily / ZNLFUNCS / SAMPLE / CTYINF.C next >
Text File  |  1993-09-21  |  45KB  |  1,371 lines

  1. /*
  2. ** /----------------------------------------------------------------------\
  3. ** |             IBM Z Family Reusable Libraries/2 (5641-504)             |
  4. ** |----------------------------------------------------------------------|
  5. ** | (C) Copyright International Business Machines Corporation 1993, 1994 |
  6. ** |----------------------------------------------------------------------|
  7. ** |                       DISCLAIMER OF WARRANTIES                       |
  8. ** |                       ------------------------                       |
  9. ** | The following code is sample code created by IBM Corporation.        |
  10. ** | Such a code is provided to you solely for the purpose of assisting   |
  11. ** | you in the development of your applications. The code is provided    |
  12. ** | "AS IS", without warranty of any kind.  IBM shall not be liable for  |
  13. ** | any damages arising out of your use of the following code, even if   |
  14. ** | they have been advised of the possibility of such damages.           |                                                                         *
  15. ** \----------------------------------------------------------------------/
  16. **
  17. **  Header   : CTYINF.C
  18. **  Author   : Valerio Tavazzi (TAVAZZI at ROMEPPC)
  19. **  Reviewer : Dario de Judicibus (DEJUDICI at ROMEPPC)
  20. **  Created  : 13 Jul 1992 
  21. **  Updated  : 21 Sep 1993
  22. **  Version  : 3.22
  23. **  Content  : Sample program for FMZNLFUN.DLL functions
  24. **
  25. */
  26.  #define EXTERN
  27.  
  28.  #include <ctyinf.h>
  29.  #include <zzzlogo.h>
  30.  
  31. /* ------------------------------------------------------------------------ */
  32.  
  33. /*
  34. **  Presentation Manager Program Main Body
  35. **
  36. **  The following routine is the Presentation Manager program Main Body.
  37. **  The Main Body of a PM program is concerned with associating the
  38. **  application with the Presentation Manager system, creating its
  39. **  message queue, registering and displaying its main window, servicing
  40. **  its message queue during the time that the application is active,
  41. **  and disassociating the application from PM when the user is finished
  42. **  with the application. The remaining parts of this source module that
  43. **  are concerned with the Presentation Manager are the application's
  44. **  window procedures (main window procedure, child window procedures,
  45. **  and dialog window procedures) that process the messages associated
  46. **  with the application's various windows.
  47. **
  48. */
  49.  int main(int argc, char *argv[])
  50. {
  51.    QMSG qmsg ; // MSG structure to store your messages
  52.    PID  pid ; // Process identifier for adding name to switch list
  53.    TID  tid ; // Thread identifier
  54.  
  55.    static CHAR szTitle[20] ;
  56.  
  57.    argc = argc ; // Suppress compiler warning - can remove if argc and argv
  58.    argv = argv ; // are referenced by user-supplied code.
  59.  
  60.   /*
  61.   **  The WinInitialize routine initializes the Presentation Manager
  62.   **  facilities for use by this application and returns a handle to the
  63.   **  anchor block assigned to the application by PM.
  64.   */
  65.    if ((hAB = WinInitialize(0)) == 0) return(FALSE) ;
  66.  
  67.   /*
  68.   **  The WinCreateMsgQueue call creates a message queue for this application
  69.   */
  70.    if ((hMQ = WinCreateMsgQueue(hAB, 0)) == 0) return(FALSE) ;
  71.  
  72.   /*
  73.   **  The following function registers the classes of all application windows
  74.   */
  75.    if (!cwRegisterClass()) return(FALSE) ;
  76.  
  77.   /*
  78.   **  Content : Initialize country
  79.   */
  80.    if (!znlInitCtryInfo(&Country)) return(FALSE) ;
  81.  
  82.   /*
  83.   **  The CreateWindow function creates a frame window for this application's
  84.   **  top window, and set the window's size and location as appropriate.
  85.   */
  86.    WinLoadString(hAB, 0, IDS_TITLE, 20, szTitle) ;
  87.    hWndFrame = cwCreateWindow((HWND)HWND_DESKTOP,
  88.                               FCF_TITLEBAR     |
  89.                               FCF_SYSMENU      |
  90.                               FCF_MINBUTTON    | 
  91.                               FCF_MAXBUTTON    | 
  92.                               FCF_SIZEBORDER   | 
  93.                               FCF_MENU         |
  94.                               FCF_ACCELTABLE   |
  95.                               FCF_SHELLPOSITION,
  96.                               szAppName,
  97.                               szTitle,
  98.                               ID_CTYINF, 
  99.                               122, 117,  
  100.                               162, 38,   
  101.                               &hWndClient,
  102.                               0L, SWP_SHOW) ;
  103.  
  104.    if (hWndFrame == 0) return(FALSE) ;
  105.  
  106.   /*
  107.   **  The following inline routine fills out the application's switch control
  108.   **  structure with the appropriate information to add the application's
  109.   **  name to the OS/2 Task Manager List, a list of the jobs currently
  110.   **  running on the computer.
  111.   */
  112.    WinQueryWindowProcess(hWndFrame, &pid, &tid) ;
  113.  
  114.    Swctl.hwnd = hWndFrame ;                         // Frame window handle
  115.    Swctl.idProcess = pid ;                          // Process identifier
  116.    Swctl.uchVisibility = SWL_VISIBLE ;              // visibility
  117.    Swctl.fbJump = SWL_JUMPABLE ;                    // Jump indicator
  118.    strcpy(Swctl.szSwtitle, szTitle) ;               // Frame window title
  119.    hSwitch = WinAddSwitchEntry(&Swctl) ;
  120.  
  121.   /*
  122.   **  The following is the message loop for the application.
  123.   */
  124.    while (WinGetMsg(hAB, (PQMSG)&qmsg, 0, 0, 0))
  125.    {
  126.      WinDispatchMsg(hAB,(PQMSG)&qmsg) ;
  127.    }
  128.  
  129.   /*
  130.   **  Perform clean up before exiting application.
  131.   **  The following routine destroys the application's frame window (which
  132.   **  also destroys its child windows), destroys its message queue, and
  133.   **  disassociates the application from the Presentation Manager system.
  134.   */
  135.    WinDestroyWindow(hWndFrame) ; // Destroy the frame window
  136.    WinDestroyMsgQueue(hMQ) ;     // Destroy this application's message queue
  137.    WinTerminate(hAB) ;           // Terminate this application's use of the
  138.                                  // Presentation Manager resources
  139.    return (0) ;
  140.  }
  141.  
  142. /* ------------------------------------------------------------------------ */
  143.  
  144. /*
  145. **  Main Window Procedure
  146. **
  147. **  This procedure provides service routines for the general PM events
  148. **  (messages) that PM sends to the window, as well as the user
  149. **  initiated events (messages) that are generated when the user selects
  150. **  the action bar and pulldown menu controls or the corresponding
  151. **  keyboard accelerators.
  152. **
  153. **  The SWITCH statement shown below distributes the window messages to
  154. **  the respective message service routines, which are set apart by the
  155. **  CASE statements. The window procedures must provide an appropriate
  156. **  service routine for its end user initiated messages, as well as the
  157. **  general PM messages (like the WM_CLOSE message). If a message is
  158. **  sent to this procedure for which there is no programmed CASE clause
  159. **  (i.e., no service routine), the message is defaulted to the
  160. **  WinDefWindowProc function, where it is disposed of by PM.
  161. **
  162. */
  163.  MRESULT EXPENTRY WndProc
  164.  (
  165.    HWND   hWnd    ,  // Handle
  166.    ULONG  message ,  // Message received from PM
  167.    MPARAM mp1     ,  // First parameter of message
  168.    MPARAM mp2        // Second parameter of message
  169.  )
  170.  {
  171.    HPS   hPS    ;   // Handle for the Presentation Space
  172.    RECTL rClient ;   // Handle to rectangle formed by client area
  173.  
  174.    switch(message)
  175.    {
  176.      case WM_INITMENU :
  177.           break ;
  178.  
  179.      case WM_MENUEND :
  180.           break ;
  181.  
  182.     /*
  183.     **  The PM messages for action bar and pulldown menu items are
  184.     **  processed in this routine.
  185.     */
  186.      case WM_COMMAND :
  187.      {
  188.        switch(SHORT1FROMMP(mp1))
  189.        {
  190.          case IDM_S_GENERAL :
  191.          {
  192.           /*
  193.           **  The code below makes a call to the dialog box named
  194.           **  "NTLINF". Variable rc will receive the
  195.           **  return code sent when the dialog box is closed.
  196.           */
  197.            APIRET rc ;
  198.  
  199.            rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)NTLINFMsgProc,
  200.                           0, IDLG_NTLINF, (PVOID)&hWnd) ;
  201.          }
  202.          break ;
  203.  
  204.          case IDM_S_DATE :
  205.          {
  206.           /*
  207.           **  The code below makes a call to the dialog box named
  208.           **  "DTEFMT". Variable rc will receive the
  209.           **  return code sent when the dialog box is closed.
  210.           */
  211.            APIRET rc ;
  212.  
  213.            rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DTEFMTMsgProc,
  214.                           0, IDLG_DTEFMT, (PVOID)&hWnd) ;
  215.          }
  216.          break ;
  217.  
  218.          case IDM_S_TIME :
  219.          {
  220.           /*
  221.           **  The code below makes a call to the dialog box named
  222.           **  "TMEFMT". Variable rc will receive the
  223.           **  return code sent when the dialog box is closed.
  224.           */
  225.            APIRET rc ;
  226.  
  227.            rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)TMEFMTMsgProc,
  228.                           0, IDLG_TMEFMT, (PVOID)&hWnd) ;
  229.          }
  230.          break ;
  231.  
  232.          case IDM_S_NUMBERS :
  233.          {
  234.           /*
  235.           **  The code below makes a call to the dialog box named
  236.           **  "NUMFMT". Variable rc will receive the
  237.           **  return code sent when the dialog box is closed.
  238.           */
  239.            APIRET rc ;
  240.  
  241.            rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)NUMFMTMsgProc,
  242.                           0, IDLG_NUMFMT, (PVOID)&hWnd) ;
  243.          }
  244.          break ;
  245.  
  246.          case IDM_S_CURRENCY :
  247.          {
  248.           /*
  249.           **  The code below makes a call to the dialog box named
  250.           **  "CURFMT". Variable rc will receive the
  251.           **  return code sent when the dialog box is closed.
  252.           */
  253.            APIRET rc ;
  254.  
  255.            rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)CURFMTMsgProc,
  256.                           0, IDLG_CURFMT, (PVOID)&hWnd) ;
  257.          }
  258.          break ;
  259.  
  260.          case IDM_S_ABOUT:
  261.               #include "TSTABOUT.INC"
  262.               break ;
  263.  
  264.          case IDM_S_EXIT:
  265.               #include "TSTEXITW.INC"
  266.               break ;
  267.  
  268.          default:
  269.               break ; // End of default case for switch(mp1)
  270.        }
  271.      }
  272.      break ; // End of WM_COMMAND
  273.  
  274.      case WM_CREATE :
  275.      {
  276.       /*
  277.       ** The WM_CREATE message is sent to a window when an application
  278.       ** requests that the window be created.  The window procedure
  279.       ** for the new window receives this message after the window is
  280.       ** created, but before the window becomes visible.
  281.       **
  282.       */
  283.        cwSetInitDlgStatus(hWnd) ;
  284.      }
  285.      break ;
  286.  
  287.      case WM_MOUSEMOVE :
  288.      {
  289.        return(WinDefWindowProc(hWnd, message, mp1, mp2)) ;
  290.      }
  291.      break ;
  292.  
  293.      case WM_SIZE :
  294.      {
  295.      }
  296.      break ;
  297.  
  298.      case WM_PAINT:    // Code for the window's client area
  299.      {
  300.       /*
  301.       **  Obtain a handle to a cache presentation space
  302.       */
  303.        hPS = WinBeginPaint(hWnd, 0, 0) ;
  304.  
  305.       /*
  306.       **  Determine the size of the client area
  307.       */
  308.        WinQueryWindowRect(hWnd, &rClient) ;
  309.  
  310.       /*
  311.       **  Fill the background with the default background color
  312.       */
  313.        WinFillRect(hPS, &rClient, CLR_BACKGROUND) ;
  314.  
  315.       /*
  316.       **  Return presentation space to state before WinBeginPaint
  317.       */
  318.        WinEndPaint(hPS) ;
  319.      }
  320.      break ;
  321.  
  322.      case WM_CLOSE :
  323.      {
  324.        #include "TSTCLOSE.INC"
  325.  
  326.        if (hWnd != hWndClient) break ;
  327.        cwFreeDlgMemory(hWnd) ;
  328.        return(WinDefWindowProc(hWnd, message, mp1, mp2)) ;
  329.      }
  330.      break ;
  331.  
  332.      case WM_TRANSLATEACCEL:
  333.      {
  334.        return(WinDefWindowProc(hWndClient, message, mp1, mp2)) ;
  335.      }
  336.      break ;
  337.  
  338.      default :
  339.      {
  340.       /*
  341.       **  For any message for which you don't specifically provide a
  342.       **  service routine, you should return the message to PM using
  343.       **  the WinDefWindowProc function.
  344.       */
  345.        return(WinDefWindowProc(hWnd, message, mp1, mp2)) ;
  346.      }
  347.      break ;
  348.    }
  349.    return(0L) ;
  350.  }
  351.  
  352. /* ------------------------------------------------------------------------ */
  353.  
  354. /*
  355. **  Dialog Window Procedure
  356. **
  357. **  This procedure is associated with the dialog box that is included in
  358. **  the function name of the procedure. It provides the service routines
  359. **  for the events (messages) that occur because the end user operates
  360. **  one of the dialog box's buttons, entry fields, or controls.
  361. **
  362. **  The SWITCH statement in the function distributes the dialog box
  363. **  messages to the respective service routines, which are set apart by
  364. **  the CASE clauses. Like any other PM window, the Dialog Window
  365. **  procedures must provide an appropriate service routine for their end
  366. **  user initiated messages as well as for the general PM messages (like
  367. **  the WM_CLOSE message). If a message is sent to this procedure for
  368. **  which there is no programmed CASE condition (no service routine),
  369. **  the message is defaulted to the WinDefDlgProc function, where it is
  370. **  disposed of by PM.
  371. **
  372. */
  373.  MRESULT EXPENTRY NTLINFMsgProc
  374.  (
  375.    HWND   hWndDlg ,  // Handle
  376.    ULONG  message ,  // Message received from PM
  377.    MPARAM mp1     ,  // First parameter of message
  378.    MPARAM mp2        // Second parameter of message
  379.  )
  380.  {
  381.    static HWND   hWndParent ;
  382.    NTLINFStruct *Ntlinf ;
  383.   
  384.    switch(message)
  385.    {
  386.      case WM_INITDLG:
  387.      {
  388.        Ntlinf = (NTLINFStruct *)WinQueryWindowULong(hWndClient, OFFSET_NTLINF) ;
  389.  
  390.        hWndParent = *((HWND *)mp2) ;
  391.        cwCenter(hWndDlg, (HWND)hWndParent) ;
  392.   
  393.       /* 
  394.       **  Initialize entry field control: NtlInfCountry 
  395.       **  It must be filled with the country name                        
  396.       */
  397.        WinSendDlgItemMsg(hWndDlg, NTLINFCTYFLD, EM_SETTEXTLIMIT, MPFROMSHORT(32), 0L) ;
  398.        if (Ntlinf->NtlInfCountry[0])
  399.          WinSetDlgItemText(hWndDlg, NTLINFCTYFLD, Ntlinf->NtlInfCountry) ;
  400.   
  401.       /* 
  402.       **  Initialize entry field control: NtlInfMeasurements             
  403.       **  It must be filled with the measurement name                    
  404.       */
  405.        WinSendDlgItemMsg(hWndDlg, NTLINFMSRFLD, EM_SETTEXTLIMIT, MPFROMSHORT(32), 0L) ;
  406.        if (Ntlinf->NtlInfMeasurements[0])
  407.          WinSetDlgItemText(hWndDlg, NTLINFMSRFLD, Ntlinf->NtlInfMeasurements) ;
  408.   
  409.       /* 
  410.       **  Initialize entry field control: NtlInfListSeparator            
  411.       **  It must be filled with the data separator symbol               
  412.       */
  413.        WinSendDlgItemMsg(hWndDlg, NTLINFSEPFLD, EM_SETTEXTLIMIT, MPFROMSHORT(2), 0L) ;
  414.        if (Ntlinf->NtlInfListSeparator[0])
  415.          WinSetDlgItemText(hWndDlg, NTLINFSEPFLD, Ntlinf->NtlInfListSeparator) ;
  416.   
  417.        #include "TSTNTNL.INC"
  418.      }
  419.      break ; // End of WM_INITDLG
  420.   
  421.      case WM_CONTROL:
  422.      {
  423.        switch(SHORT1FROMMP(mp1))
  424.        {
  425.          case NTLINFCTYFLD : // Entry field variable: "NtlInfCountry"   
  426.          case NTLINFMSRFLD : // Entry field variable: "NtlInfMeasurements"
  427.          case NTLINFSEPFLD : // Entry field variable: "NtlInfListSeparator" 
  428.          {
  429.            switch(SHORT2FROMMP(mp1)) // Switch on Notification Code 
  430.            {
  431.              case EN_SETFOCUS :  // Entry field is receiving the focus 
  432.                   break ;
  433.   
  434.              case EN_KILLFOCUS : // Entry field is losing the focus  
  435.                  break ;
  436.   
  437.              default :           // Default other messages                     
  438.                  return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  439.                  break ;
  440.            }
  441.          }
  442.          break ;
  443.        }
  444.      }
  445.      break ; // End of WM_CONTROL
  446.      
  447.      case WM_COMMAND:
  448.      {
  449.        switch(SHORT1FROMMP(mp1))
  450.        {
  451.          case DID_OK: // Button text: "OK"                                
  452.          {
  453.            Ntlinf = (NTLINFStruct *)WinQueryWindowULong(hWndClient, OFFSET_NTLINF) ;
  454.            WinDismissDlg(hWndDlg, TRUE) ;
  455.          }
  456.          break ;
  457.        }
  458.      } 
  459.      break ; // End of WM_COMMAND   
  460.   
  461.      case WM_CLOSE:
  462.      {
  463.        WinDismissDlg(hWndDlg, FALSE) ;
  464.      } 
  465.      break ; // End of WM_CLOSE   
  466.   
  467.      case WM_FAILEDVALIDATE:
  468.      {
  469.        return((MRESULT)TRUE) ;
  470.      } 
  471.      break ; // End of WM_FAILEDVALIDATE   
  472.   
  473.      default:
  474.      {
  475.        return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  476.      } 
  477.      break ;
  478.    }
  479.  
  480.    return FALSE ;
  481.  }
  482.  
  483. /* ------------------------------------------------------------------------ */
  484.  
  485. /*
  486. **  Dialog Window Procedure
  487. **
  488. **  This procedure is associated with the dialog box that is included in
  489. **  the function name of the procedure. It provides the service routines
  490. **  for the events (messages) that occur because the end user operates
  491. **  one of the dialog box's buttons, entry fields, or controls.
  492. **
  493. **  The SWITCH statement in the function distributes the dialog box
  494. **  messages to the respective service routines, which are set apart by
  495. **  the CASE clauses. Like any other PM window, the Dialog Window
  496. **  procedures must provide an appropriate service routine for their end
  497. **  user initiated messages as well as for the general PM messages (like
  498. **  the WM_CLOSE message). If a message is sent to this procedure for
  499. **  which there is no programmed CASE condition (no service routine),
  500. **  the message is defaulted to the WinDefDlgProc function, where it is
  501. **  disposed of by PM.
  502. **
  503. */
  504.  MRESULT EXPENTRY DTEFMTMsgProc
  505.  (
  506.    HWND   hWndDlg ,  // Handle
  507.    ULONG  message ,  // Message received from PM
  508.    MPARAM mp1     ,  // First parameter of message
  509.    MPARAM mp2        // Second parameter of message
  510.  )
  511.  {
  512.    static HWND   hWndParent ;
  513.    DTEFMTStruct *Dtefmt ;
  514.  
  515.    switch(message)
  516.    {
  517.      case WM_INITDLG:
  518.      {
  519.        Dtefmt = (DTEFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_DTEFMT) ;
  520.  
  521.        hWndParent = *((HWND *)mp2) ;
  522.        cwCenter(hWndDlg, (HWND)hWndParent) ;
  523.  
  524.       /*
  525.       **  Initialize radio button control: DteFmtFormat                    
  526.       */
  527.        WinPostMsg(hWndDlg, WM_CONTROL,
  528.                   MPFROMSHORT(Dtefmt->DteFmtFormat), 0L) ;
  529.  
  530.       /*
  531.       **  Initialize entry field control: DteFmtSeparator                  
  532.       */
  533.        WinSendDlgItemMsg(hWndDlg, DTEFMTSEPFLD, EM_SETTEXTLIMIT, MPFROMSHORT(2), 0L) ;
  534.        if (Dtefmt->DteFmtSeparator[0])
  535.           WinSetDlgItemText(hWndDlg, DTEFMTSEPFLD, Dtefmt->DteFmtSeparator) ;
  536.  
  537.        #include "TSTDATE.INC"
  538.      }
  539.      break ; // End of WM_INITDLG   
  540.  
  541.      case WM_CONTROL:
  542.      {
  543.        switch(SHORT1FROMMP(mp1))
  544.        {
  545.          case DTEFMTDMYRDB: // Radiobutton text: "Day Month Year"         
  546.          case DTEFMTMDYRDB: // Radiobutton text: "Month Day Year"         
  547.          case DTEFMTYMDRDB: // Radiobutton text: "Year Month Day"         
  548.          {
  549.            // Read only   
  550.          }
  551.          break ;
  552.  
  553.          case DTEFMTSEPFLD: // Entry field variable: "DteFmtSeparator"    
  554.          {
  555.            switch(SHORT2FROMMP(mp1)) // Switch on Notification Code    
  556.            {
  557.              case EN_SETFOCUS :  // Entry field is receiving the focus   
  558.                   break ;
  559.  
  560.              case EN_KILLFOCUS : // Entry field is losing the focus    
  561.                   break ;
  562.  
  563.              default :           // Default other messages                       
  564.                   return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  565.                   break ;
  566.            }
  567.          }
  568.          break ;
  569.        }
  570.      }
  571.      break ; // End of WM_CONTROL   
  572.  
  573.      case WM_COMMAND:
  574.      {
  575.        switch(SHORT1FROMMP(mp1))
  576.        {
  577.          case DID_OK: // Button text: "OK"                                
  578.          {
  579.            Dtefmt = (DTEFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_DTEFMT) ;
  580.  
  581.           /*
  582.           ** Query radio buttons for current state, if set then        
  583.           ** set the dialog structure variable to the control ID      
  584.           */
  585.            if (WinSendDlgItemMsg(hWndDlg, DTEFMTDMYRDB, BM_QUERYCHECK, 0L, 0L ))
  586.              Dtefmt->DteFmtFormat = DTEFMTDMYRDB ;
  587.  
  588.            if (WinSendDlgItemMsg(hWndDlg, DTEFMTMDYRDB, BM_QUERYCHECK, 0L, 0L ))
  589.              Dtefmt->DteFmtFormat = DTEFMTMDYRDB ;
  590.  
  591.            if (WinSendDlgItemMsg(hWndDlg, DTEFMTYMDRDB, BM_QUERYCHECK, 0L, 0L ))
  592.              Dtefmt->DteFmtFormat = DTEFMTYMDRDB ;
  593.  
  594.            WinDismissDlg(hWndDlg, TRUE) ;
  595.          }
  596.          break ;
  597.        }
  598.      }
  599.      break ; // End of WM_COMMAND   
  600.  
  601.      case WM_CLOSE:
  602.      {
  603.        WinDismissDlg(hWndDlg, FALSE) ;
  604.      }
  605.      break ; // End of WM_CLOSE   
  606.  
  607.      case WM_FAILEDVALIDATE:
  608.      {
  609.        return((MRESULT)TRUE) ;
  610.      }
  611.      break ; // End of WM_FAILEDVALIDATE   
  612.  
  613.      default:
  614.      {
  615.        return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  616.      }
  617.      break ;
  618.    }
  619.  
  620.    return FALSE ;
  621.  } 
  622.  
  623. /* ------------------------------------------------------------------------ */
  624.  
  625. /*
  626. **  Dialog Window Procedure
  627. **
  628. **  This procedure is associated with the dialog box that is included in
  629. **  the function name of the procedure. It provides the service routines
  630. **  for the events (messages) that occur because the end user operates
  631. **  one of the dialog box's buttons, entry fields, or controls.
  632. **
  633. **  The SWITCH statement in the function distributes the dialog box
  634. **  messages to the respective service routines, which are set apart by
  635. **  the CASE clauses. Like any other PM window, the Dialog Window
  636. **  procedures must provide an appropriate service routine for their end
  637. **  user initiated messages as well as for the general PM messages (like
  638. **  the WM_CLOSE message). If a message is sent to this procedure for
  639. **  which there is no programmed CASE condition (no service routine),
  640. **  the message is defaulted to the WinDefDlgProc function, where it is
  641. **  disposed of by PM.
  642. **
  643. */
  644.  MRESULT EXPENTRY TMEFMTMsgProc
  645.  (
  646.    HWND   hWndDlg ,  // Handle
  647.    ULONG  message ,  // Message received from PM
  648.    MPARAM mp1     ,  // First parameter of message
  649.    MPARAM mp2        // Second parameter of message
  650.  )
  651.  {
  652.    static HWND   hWndParent ;
  653.    TMEFMTStruct *Tmefmt ;
  654.  
  655.    switch(message)
  656.    {
  657.      case WM_INITDLG :
  658.      {
  659.        Tmefmt = (TMEFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_TMEFMT) ;
  660.  
  661.        hWndParent = *((HWND *)mp2) ;
  662.        cwCenter(hWndDlg, (HWND)hWndParent) ;
  663.  
  664.       /*
  665.       **  Initialize radio button control: TmeFmtFormat                    
  666.       */
  667.        WinPostMsg(hWndDlg, WM_CONTROL,
  668.                   MPFROMSHORT(Tmefmt->TmeFmtFormat), 0L) ;
  669.  
  670.       /*
  671.       **  Initialize entry field control: TmeFmtSeparator                  
  672.       */
  673.        WinSendDlgItemMsg(hWndDlg, TMEFMTSEPFLD, EM_SETTEXTLIMIT, MPFROMSHORT(2), 0L) ;
  674.        if (Tmefmt->TmeFmtSeparator[0])
  675.          WinSetDlgItemText(hWndDlg, TMEFMTSEPFLD, Tmefmt->TmeFmtSeparator) ;
  676.  
  677.        #include "TSTTIME.INC"
  678.      }
  679.      break ; // End of WM_INITDLG   
  680.  
  681.      case WM_CONTROL:
  682.      {
  683.        switch(SHORT1FROMMP(mp1))
  684.        {
  685.          case TMEFMT12HRDB: // Radiobutton text: "12h (AM/PM)"            
  686.          case TMEFMT24HRDB: // Radiobutton text: "24h"                    
  687.          {
  688.            // Read only   
  689.          }
  690.          break ;
  691.  
  692.          case TMEFMTSEPFLD: // Entry field variable: "TmeFmtSeparator"    
  693.          {
  694.            switch(SHORT2FROMMP(mp1)) // Switch on Notification Code    
  695.            {
  696.              case EN_SETFOCUS :  // Entry field is receiving the focus   
  697.                   break ;
  698.  
  699.              case EN_KILLFOCUS : // Entry field is losing the focus    
  700.                   break ;
  701.  
  702.              default :           // Default other messages                       
  703.                   return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  704.                   break ;
  705.            }
  706.          }
  707.          break ;
  708.        }
  709.      }
  710.      break ; // End of WM_CONTROL   
  711.      case WM_COMMAND:
  712.      {
  713.        switch(SHORT1FROMMP(mp1))
  714.        {
  715.          case DID_OK: // Button text: "OK"                                
  716.          {
  717.            Tmefmt = (TMEFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_TMEFMT) ;
  718.  
  719.           /*
  720.           ** Query radio buttons for current state, if set then        
  721.           ** set the dialog structure variable to the control ID      
  722.           */
  723.            if (WinSendDlgItemMsg(hWndDlg, TMEFMT12HRDB, BM_QUERYCHECK, 0L, 0L ))
  724.              Tmefmt->TmeFmtFormat = TMEFMT12HRDB ;
  725.  
  726.            if (WinSendDlgItemMsg(hWndDlg, TMEFMT24HRDB, BM_QUERYCHECK, 0L, 0L ))
  727.              Tmefmt->TmeFmtFormat = TMEFMT24HRDB ;
  728.  
  729.            WinDismissDlg(hWndDlg, TRUE) ;
  730.          }
  731.          break ;
  732.        }
  733.      }
  734.      break ; // End of WM_COMMAND   
  735.  
  736.      case WM_CLOSE:
  737.      {
  738.        WinDismissDlg(hWndDlg, FALSE) ;
  739.      }
  740.      break ; // End of WM_CLOSE   
  741.  
  742.      case WM_FAILEDVALIDATE:
  743.      {
  744.        return((MRESULT)TRUE) ;
  745.      }
  746.      break ; // End of WM_FAILEDVALIDATE   
  747.  
  748.      default:
  749.      {
  750.        return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  751.      }
  752.      break ;
  753.    }
  754.  
  755.    return FALSE ;
  756.  } 
  757.  
  758. /* ------------------------------------------------------------------------ */
  759.  
  760. /*
  761. **  Dialog Window Procedure
  762. **
  763. **  This procedure is associated with the dialog box that is included in
  764. **  the function name of the procedure. It provides the service routines
  765. **  for the events (messages) that occur because the end user operates
  766. **  one of the dialog box's buttons, entry fields, or controls.
  767. **
  768. **  The SWITCH statement in the function distributes the dialog box
  769. **  messages to the respective service routines, which are set apart by
  770. **  the CASE clauses. Like any other PM window, the Dialog Window
  771. **  procedures must provide an appropriate service routine for their end
  772. **  user initiated messages as well as for the general PM messages (like
  773. **  the WM_CLOSE message). If a message is sent to this procedure for
  774. **  which there is no programmed CASE condition (no service routine),
  775. **  the message is defaulted to the WinDefDlgProc function, where it is
  776. **  disposed of by PM.
  777. **
  778. */
  779.  MRESULT EXPENTRY NUMFMTMsgProc
  780.  (
  781.    HWND   hWndDlg ,  // Handle
  782.    ULONG  message ,  // Message received from PM
  783.    MPARAM mp1     ,  // First parameter of message
  784.    MPARAM mp2        // Second parameter of message
  785.  )
  786.  {
  787.    static HWND   hWndParent ;
  788.    NUMFMTStruct *Numfmt ;
  789.  
  790.    switch(message)
  791.    {
  792.      case WM_INITDLG:
  793.      {
  794.        Numfmt = (NUMFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_NUMFMT) ;
  795.  
  796.        hWndParent = *((HWND *)mp2) ;
  797.        cwCenter(hWndDlg, (HWND)hWndParent) ;
  798.  
  799.        /*
  800.        ** Initialize entry field control: NumFmtDec                        
  801.        */
  802.         WinSendDlgItemMsg(hWndDlg, NUMFMTDECFLD, EM_SETTEXTLIMIT, MPFROMSHORT(1), 0L) ;
  803.         if (Numfmt->NumFmtDec)
  804.           WinSetDlgItemText(hWndDlg, NUMFMTDECFLD, &Numfmt->NumFmtDec) ;
  805.  
  806.        /*
  807.        ** Initialize entry field control: NumFmtThs                        
  808.        */
  809.         WinSendDlgItemMsg(hWndDlg, NUMFMTTHSFLD, EM_SETTEXTLIMIT, MPFROMSHORT(1), 0L) ;
  810.         if (Numfmt->NumFmtThs)
  811.           WinSetDlgItemText(hWndDlg, NUMFMTTHSFLD, &Numfmt->NumFmtThs) ;
  812.  
  813.        /*
  814.        ** Initialize entry field control: NumFmtSample                     
  815.        */
  816.         WinSendDlgItemMsg(hWndDlg, NUMFMTSMPFLD, EM_SETTEXTLIMIT, MPFROMSHORT(16), 0L) ;
  817.         if (Numfmt->NumFmtSample[0])
  818.           WinSetDlgItemText(hWndDlg, NUMFMTSMPFLD, Numfmt->NumFmtSample) ;
  819.  
  820.        #include "TSTNUM.INC"
  821.      }
  822.      break ; // End of WM_INITDLG   
  823.  
  824.      case WM_CONTROL:
  825.      {
  826.        switch(SHORT1FROMMP(mp1))
  827.        {
  828.          case NUMFMTDECFLD: // Entry field variable: "NumFmtDec"          
  829.          case NUMFMTTHSFLD: // Entry field variable: "NumFmtThs"          
  830.          case NUMFMTSMPFLD: // Entry field variable: "NumFmtSample"       
  831.          {
  832.            switch(SHORT2FROMMP(mp1)) // Switch on Notification Code    
  833.            {
  834.              case EN_SETFOCUS :  // Entry field is receiving the focus   
  835.                   break ;
  836.  
  837.              case EN_KILLFOCUS : // Entry field is losing the focus    
  838.                   break ;
  839.  
  840.              default :           // Default other messages                       
  841.                   return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  842.                   break ;
  843.            }
  844.          }
  845.          break ;
  846.        }
  847.      }
  848.      break ; // End of WM_CONTROL   
  849.  
  850.      case WM_COMMAND:
  851.      {
  852.        switch(SHORT1FROMMP(mp1))
  853.        {
  854.          case DID_OK: // Button text: "OK"                                
  855.          {
  856.            WinDismissDlg(hWndDlg, TRUE) ;
  857.          }
  858.          break ;
  859.        }
  860.      }
  861.      break ; // End of WM_COMMAND   
  862.  
  863.      case WM_CLOSE:
  864.      {
  865.        WinDismissDlg(hWndDlg, FALSE) ;
  866.      }
  867.      break ; // End of WM_CLOSE   
  868.  
  869.      case WM_FAILEDVALIDATE:
  870.      {
  871.        return((MRESULT)TRUE) ;
  872.      }
  873.      break ; // End of WM_FAILEDVALIDATE   
  874.  
  875.      default:
  876.      {
  877.        return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  878.      }
  879.      break ;
  880.    }
  881.  
  882.    return FALSE ;
  883.  } 
  884.  
  885. /* ------------------------------------------------------------------------ */
  886.  
  887. /*
  888. **  Dialog Window Procedure
  889. **
  890. **  This procedure is associated with the dialog box that is included in
  891. **  the function name of the procedure. It provides the service routines
  892. **  for the events (messages) that occur because the end user operates
  893. **  one of the dialog box's buttons, entry fields, or controls.
  894. **
  895. **  The SWITCH statement in the function distributes the dialog box
  896. **  messages to the respective service routines, which are set apart by
  897. **  the CASE clauses. Like any other PM window, the Dialog Window
  898. **  procedures must provide an appropriate service routine for their end
  899. **  user initiated messages as well as for the general PM messages (like
  900. **  the WM_CLOSE message). If a message is sent to this procedure for
  901. **  which there is no programmed CASE condition (no service routine),
  902. **  the message is defaulted to the WinDefDlgProc function, where it is
  903. **  disposed of by PM.
  904. **
  905. */
  906.  MRESULT EXPENTRY CURFMTMsgProc
  907.  (
  908.    HWND   hWndDlg ,  // Handle
  909.    ULONG  message ,  // Message received from PM
  910.    MPARAM mp1     ,  // First parameter of message
  911.    MPARAM mp2        // Second parameter of message
  912.  )
  913.  {
  914.    static HWND   hWndParent ;
  915.    CURFMTStruct *Curfmt ;
  916.  
  917.    switch(message)
  918.    {
  919.      case WM_INITDLG:
  920.      {
  921.        Curfmt = (CURFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_CURFMT) ;
  922.  
  923.        hWndParent = *((HWND *)mp2) ;
  924.        cwCenter(hWndDlg, (HWND)hWndParent) ;
  925.  
  926.       /*
  927.       **  Initialize radio button control: CurFmtPosition                  
  928.       */
  929.        WinPostMsg(hWndDlg, WM_CONTROL,
  930.                   MPFROMSHORT(Curfmt->CurFmtPosition), 0L) ;
  931.  
  932.       /*
  933.       **  Initialize entry field control: CurFmtSymbol                     
  934.       */
  935.        WinSendDlgItemMsg(hWndDlg, CURFMTSYMFLD, EM_SETTEXTLIMIT, MPFROMSHORT(8), 0L) ;
  936.        if (Curfmt->CurFmtSymbol[0])
  937.          WinSetDlgItemText(hWndDlg, CURFMTSYMFLD, Curfmt->CurFmtSymbol) ;
  938.  
  939.       /*
  940.       **  Initialize check box control: CurFmtInterSpace                   
  941.       */
  942.        WinSendDlgItemMsg(hWndDlg, CURFMTISPCHK, BM_SETCHECK,
  943.            MPFROMSHORT(Curfmt->CurFmtInterSpace), 0L) ;
  944.  
  945.       /*
  946.       **  Initialize check box control: CurFmtLeadZeros                    
  947.       */
  948.        WinSendDlgItemMsg(hWndDlg, CURFMTLZRCHK, BM_SETCHECK,
  949.            MPFROMSHORT(Curfmt->CurFmtLeadZeros), 0L) ;
  950.  
  951.       /*
  952.       **  Initialize entry field control: CurFmtDecDigits                  
  953.       */
  954.        {
  955.          CHAR szWorkBuf[50] ; // local scratch memory   
  956.  
  957.          if (Curfmt->CurFmtDecDigits != 0)
  958.          {
  959.            _itoa(Curfmt->CurFmtDecDigits, szWorkBuf, 10) ;
  960.            WinSetDlgItemText(hWndDlg, CURFMTDGTFLD, szWorkBuf) ;
  961.          }
  962.        }
  963.  
  964.       /*
  965.       ** Initialize entry field control: CurFmtSample                     
  966.       */
  967.        WinSendDlgItemMsg(hWndDlg, CURFMTSMPFLD, EM_SETTEXTLIMIT, MPFROMSHORT(16), 0L) ;
  968.        if (Curfmt->CurFmtSample[0])
  969.          WinSetDlgItemText(hWndDlg, CURFMTSMPFLD, Curfmt->CurFmtSample) ;
  970.  
  971.        #include "TSTCUR.INC"
  972.      }
  973.      break ; // End of WM_INITDLG   
  974.  
  975.      case WM_CONTROL:
  976.      {
  977.        switch(SHORT1FROMMP(mp1))
  978.        {
  979.          case CURFMTPFXRDB: // Radiobutton text: "Prefix"                 
  980.          case CURFMTSFXRDB: // Radiobutton text: "Suffix"                 
  981.          case CURFMTISPCHK: // Checkbox text: "Intervening space"         
  982.          case CURFMTLZRCHK: // Checkbox text: "Leading zeros"             
  983.          {
  984.            // Read only   
  985.          }
  986.          break ;
  987.  
  988.          case CURFMTSYMFLD: // Entry field variable: "CurFmtSymbol"       
  989.          case CURFMTDGTFLD: // Entry field variable: "CurFmtDecDigits"    
  990.          case CURFMTSMPFLD: // Entry field variable: "CurFmtSample"       
  991.          {
  992.            switch(SHORT2FROMMP(mp1)) // Switch on Notification Code    
  993.            {
  994.              case EN_SETFOCUS :  // Entry field is receiving the focus   
  995.                   break ;
  996.  
  997.              case EN_KILLFOCUS : // Entry field is losing the focus    
  998.                   break ;
  999.  
  1000.              default :           // Default other messages                       
  1001.                   return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  1002.                   break ;
  1003.            }
  1004.          }
  1005.          break ;
  1006.        }
  1007.      }
  1008.      break ; // End of WM_CONTROL   
  1009.  
  1010.      case WM_COMMAND:
  1011.      {
  1012.        switch(SHORT1FROMMP(mp1))
  1013.        {
  1014.          case DID_OK: // Button text: "OK"                                
  1015.          {
  1016.            Curfmt = (CURFMTStruct *)WinQueryWindowULong(hWndClient, OFFSET_CURFMT) ;
  1017.  
  1018.           /*
  1019.           ** Query radio buttons for current state, if set then        
  1020.           ** set the dialog structure variable to the control ID      
  1021.           */
  1022.            if (WinSendDlgItemMsg(hWndDlg, CURFMTPFXRDB, BM_QUERYCHECK, 0L, 0L ))
  1023.              Curfmt->CurFmtPosition = CURFMTPFXRDB ;
  1024.  
  1025.            if (WinSendDlgItemMsg(hWndDlg, CURFMTSFXRDB, BM_QUERYCHECK, 0L, 0L ))
  1026.              Curfmt->CurFmtPosition = CURFMTSFXRDB ;
  1027.  
  1028.            Curfmt->CurFmtInterSpace = (ULONG)(WinSendDlgItemMsg(hWndDlg, 
  1029.                                       CURFMTISPCHK, BM_QUERYCHECK, 0L, 0L)) ;
  1030.            Curfmt->CurFmtLeadZeros  = (ULONG)(WinSendDlgItemMsg(hWndDlg, 
  1031.                                       CURFMTLZRCHK, BM_QUERYCHECK, 0L, 0L)) ;
  1032.  
  1033.            WinDismissDlg(hWndDlg, TRUE) ;
  1034.          }
  1035.          break ;
  1036.        }
  1037.      }
  1038.      break ; // End of WM_COMMAND   
  1039.  
  1040.      case WM_CLOSE:
  1041.      {
  1042.        WinDismissDlg(hWndDlg, FALSE) ;
  1043.      }
  1044.      break ; // End of WM_CLOSE   
  1045.  
  1046.      case WM_FAILEDVALIDATE:
  1047.      {
  1048.        return((MRESULT)TRUE) ;
  1049.      }
  1050.      break ; // End of WM_FAILEDVALIDATE   
  1051.  
  1052.      default:
  1053.      {
  1054.        return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  1055.      }
  1056.      break ;
  1057.    }
  1058.  
  1059.    return FALSE ;
  1060.  } 
  1061.  
  1062. /* ------------------------------------------------------------------------ */
  1063.  
  1064. /*
  1065. **  cwRegisterClass Function
  1066. **
  1067. **  The following function registers all the classes of all the windows
  1068. **  associated with this application. The function returns TRUE if it is
  1069. **  successful, otherwise it returns FALSE.
  1070. **
  1071. */
  1072.  INT cwRegisterClass(VOID)
  1073.  {
  1074.    APIRET rc ;
  1075.  
  1076.    WinLoadString(hAB, 0, IDS_APP_NAME, 80, szAppName) ; // Program name
  1077.  
  1078.    rc = WinRegisterClass (hAB,              // Anchor block handle
  1079.                           (PCH)szAppName,   // Name of class being registered
  1080.                           (PFNWP)WndProc,   // Window procedure for class
  1081.                           CS_SIZEREDRAW ,
  1082.                           5*sizeof(char*)) ;
  1083.    if (rc == FALSE) return(FALSE) ;
  1084.  
  1085.    return(TRUE) ;
  1086.  }
  1087.  
  1088. /* ------------------------------------------------------------------------ */
  1089.  
  1090. /*
  1091. **  cwCreateWindow Function
  1092. **
  1093. **  The following function is used to create a window (the main window,
  1094. **  a child window, an icon window, etc.) and set it's initial size and
  1095. **  position. It returns the handle to the frame window.
  1096. **
  1097. */
  1098.  HWND cwCreateWindow
  1099.  (
  1100.    HWND   hWndParent,  // Handle to the parent of the window to be created
  1101.    ULONG  ctldata,     // Frame control flags for the window
  1102.    PCH    appname,     // Class name of the window
  1103.    PCH    title,       // Title of the window
  1104.    ULONG  ResID,       // Resource id value
  1105.    INT    x,           // Initial horizontal and vertical location
  1106.    INT    y,           //
  1107.    INT    cx,          // Initial width and height of the window
  1108.    INT    cy,          //
  1109.    PHWND  hWndClient,  // Handle to the client area of the window
  1110.    ULONG  lfStyle,     // Frame window style
  1111.    USHORT uSizeStyle   // User defined size and location flags
  1112.  )
  1113.  {
  1114.    ULONG  rc ;            // Accepts return codes from function calls
  1115.    HWND   hWndFrame ;     // Local handle to created window frame
  1116.    ULONG  SizeStyle ;     // Local window positioning options
  1117.    CHAR   MsgBuffer[80] ; // Buffer for error messages
  1118.    HPS    hPS ;           // Handle to a presentation space
  1119.    int    xmod, ymod ;    // Modifiers for sizing
  1120.    #define DLGXMOD  4     // Dialog units X modulo
  1121.    #define DLGYMOD  8     // Dialog units Y modulo
  1122.    FONTMETRICS fm ;       // Structure for determing modifiers
  1123.  
  1124.   /*
  1125.   **  Create the frame window
  1126.   */
  1127.    hWndFrame = WinCreateStdWindow(hWndParent,  // Parent of window
  1128.                                   lfStyle,     // Frame window style
  1129.                                   &ctldata,    // Frame flags
  1130.                                   appname,     // Class name
  1131.                                   title,       // Window title
  1132.                                   0L,          // Client window style
  1133.                                   0,           // Module for resources
  1134.                                   ResID,       // Resource id
  1135.                                   (HWND *)hWndClient) ; // Client handle
  1136.  
  1137.   /*
  1138.   **  If hWndFrame is NULL, an error occured when opening the window,
  1139.   **  notify the user and exit this function
  1140.   */
  1141.    if(hWndFrame == 0)
  1142.    {
  1143.      WinLoadString(hAB, 0, IDS_ERR_WINDOW_CREATE, 80, MsgBuffer) ;
  1144.      WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  1145.                    0, 0, MB_OK|MB_ICONEXCLAMATION) ;
  1146.      return ((HWND)0) ;
  1147.    }
  1148.  
  1149.   /*
  1150.   **  Set up size options
  1151.   */
  1152.    SizeStyle = SWP_ACTIVATE | SWP_ZORDER | uSizeStyle ;
  1153.  
  1154.   /*
  1155.   **  If the height, width, intial x or initial y values are non-zero,
  1156.   **  then we will need to set up the modifiers for size and location
  1157.   */
  1158.    if((cx > 0) || (cy > 0) || (x != 0)  || (y != 0))
  1159.    {
  1160.      hPS = WinGetPS(HWND_DESKTOP) ;
  1161.      GpiQueryFontMetrics(hPS, (LONG)sizeof(FONTMETRICS), &fm) ;
  1162.      xmod = (INT)fm.lAveCharWidth ;
  1163.      ymod = (INT)fm.lMaxBaselineExt ;
  1164.      WinReleasePS(hPS) ;
  1165.    }
  1166.  
  1167.   /*
  1168.   **  If either the width or the height are non-zero, then the size of the
  1169.   **  created window will be changed, set SizeStyle accordingly
  1170.   */
  1171.    if((cx > 0) || (cy > 0) || (x != 0) || (y != 0))
  1172.    {
  1173.      SizeStyle |= SWP_SIZE ;
  1174.      SizeStyle |= SWP_MOVE ;
  1175.    }
  1176.  
  1177.   /*
  1178.   **  Set the size and position of the window and activate it
  1179.   */
  1180.    rc = WinSetWindowPos(hWndFrame, HWND_TOP,
  1181.                         ((x * xmod)/DLGXMOD),
  1182.                         ((y * ymod)/DLGYMOD),
  1183.                         ((cx * xmod)/DLGXMOD),
  1184.                         ((cy * ymod)/DLGYMOD), SizeStyle) ;
  1185.  
  1186.   /*
  1187.   **  If rc is not set to TRUE then WinSetWindowPos failed, notify the user
  1188.   **  and exit this function
  1189.   */
  1190.    if(!rc)
  1191.    {
  1192.      WinLoadString(hAB, 0, IDS_ERR_WINDOW_POS, 80, MsgBuffer) ;
  1193.      WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  1194.                    0, 0, MB_OK|MB_ICONEXCLAMATION) ;
  1195.      return((HWND)0) ;
  1196.    }
  1197.  
  1198.   /*
  1199.   **  Return the handle to the frame window
  1200.   */
  1201.    return(hWndFrame) ;
  1202.  }
  1203.  
  1204. /* ------------------------------------------------------------------------ */
  1205.  
  1206. /*
  1207. **  cwCenter Function
  1208. **
  1209. **  Centers a dialog box on the client area of the caller
  1210. **
  1211. **  hWnd       - handle of the window to be centered
  1212. **  hWndParent - handle of the window on which to center
  1213. **
  1214. */
  1215.  INT cwCenter
  1216.  (
  1217.    HWND hWnd       ,
  1218.    HWND hWndParent
  1219.  )
  1220.  {
  1221.    LONG   SrcX, SrcY ;                // Center of parent
  1222.    LONG   x, y ;                      // Destination points
  1223.    SWP    DlgSwp, ParentSwp ;         // Set window position structures
  1224.    LONG   ScreenWidth, ScreenHeight ; // Dimensions of the DESKTOP
  1225.    POINTL pt ;                        // Point
  1226.  
  1227.   /*
  1228.   **  Determine the width and height of the DESKTOP so the dialog box
  1229.   **  will not be positioned to a point off of the screen.
  1230.   */
  1231.    ScreenWidth  = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) ;
  1232.    ScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) ;
  1233.  
  1234.   /*
  1235.   **  Query width and depth of dialog box
  1236.   */
  1237.    WinQueryWindowPos(hWnd, (PSWP)&DlgSwp) ;
  1238.  
  1239.   /*
  1240.   **  Query width and depth of caller
  1241.   */
  1242.    WinQueryWindowPos(hWndParent, (PSWP)&ParentSwp) ;
  1243.  
  1244.   /*
  1245.   **  Map the point parent points to the Desktop
  1246.   */
  1247.    pt.x = ParentSwp.x ;
  1248.    pt.y = ParentSwp.y ;
  1249.  
  1250.   /*
  1251.   **  Convert the point from having our window as the origin to having
  1252.   **  the DESKTOP as the origin
  1253.   */
  1254.    WinMapWindowPoints(hWndParent, HWND_DESKTOP, &pt, 1) ;
  1255.  
  1256.    SrcX = pt.x + (ParentSwp.cx / 2) ;
  1257.    SrcY = pt.y + (ParentSwp.cy / 2) ;
  1258.  
  1259.   /*
  1260.   **  Determine the point to move the dialog box to
  1261.   */
  1262.    x = (SrcX - (DlgSwp.cx / 2)) ;
  1263.    y = (SrcY - (DlgSwp.cy / 2)) ;
  1264.  
  1265.   /*
  1266.   **  If either point is less than zero, then set that point to zero
  1267.   **  so the dialog box will not be positoned off of the window
  1268.   */
  1269.    x = (x < 0L) ? 0L : x ;
  1270.    y = (y < 0L) ? 0L : y ;
  1271.  
  1272.   /*
  1273.   **  If either point plus the height or width of the dialog box is
  1274.   **  greater than the height or width of the screen adjust point
  1275.   */
  1276.    if ((x + DlgSwp.cx) > ScreenWidth)  x = ScreenWidth - DlgSwp.cx ;
  1277.    if ((y + DlgSwp.cy) > ScreenHeight) y = ScreenHeight - DlgSwp.cy ;
  1278.  
  1279.   /*
  1280.   **  Move the dialog box
  1281.   */
  1282.    return(WinSetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_MOVE)) ;
  1283.  }
  1284.  
  1285. /* ------------------------------------------------------------------------ */
  1286.  
  1287. /*
  1288. **  This function allocates memory for dialog box variables and initializes
  1289. **  the state of any initially selected radio buttons and check boxes.
  1290. */
  1291.  INT cwSetInitDlgStatus(HWND hWnd)
  1292.  {
  1293.    NTLINFStruct *Ntlinf ;
  1294.    DTEFMTStruct *Dtefmt ;
  1295.    TMEFMTStruct *Tmefmt ;
  1296.    NUMFMTStruct *Numfmt ;
  1297.    CURFMTStruct *Curfmt ;
  1298.  
  1299.    OFFSETOF(Ntlinf) = 0 ;
  1300.    DosAllocMem(((PPVOID)&Ntlinf), sizeof(NTLINFStruct), fALLOC) ;
  1301.    memset(Ntlinf, 0x00, sizeof(NTLINFStruct)) ;
  1302.    WinSetWindowULong(hWnd, OFFSET_NTLINF, (ULONG)Ntlinf) ;
  1303.  
  1304.    OFFSETOF(Dtefmt) = 0 ;
  1305.    DosAllocMem(((PPVOID)&Dtefmt), sizeof(DTEFMTStruct), fALLOC) ;
  1306.    memset(Dtefmt, 0x00, sizeof(DTEFMTStruct)) ;
  1307.    WinSetWindowULong(hWnd, OFFSET_DTEFMT, (ULONG)Dtefmt) ;
  1308.  
  1309.    OFFSETOF(Tmefmt) = 0 ;
  1310.    DosAllocMem(((PPVOID)&Tmefmt), sizeof(TMEFMTStruct), fALLOC) ;
  1311.    memset(Tmefmt, 0x00, sizeof(TMEFMTStruct)) ;
  1312.    WinSetWindowULong(hWnd, OFFSET_TMEFMT, (ULONG)Tmefmt) ;
  1313.  
  1314.    OFFSETOF(Numfmt) = 0 ;
  1315.    DosAllocMem(((PPVOID)&Numfmt), sizeof(NUMFMTStruct), fALLOC) ;
  1316.    memset(Numfmt, 0x00, sizeof(NUMFMTStruct)) ;
  1317.    WinSetWindowULong(hWnd, OFFSET_NUMFMT, (ULONG)Numfmt) ;
  1318.  
  1319.    OFFSETOF(Curfmt) = 0 ;
  1320.    DosAllocMem(((PPVOID)&Curfmt), sizeof(CURFMTStruct), fALLOC) ;
  1321.    memset(Curfmt, 0x00, sizeof(CURFMTStruct)) ;
  1322.    WinSetWindowULong(hWnd, OFFSET_CURFMT, (ULONG)Curfmt) ;
  1323.    Curfmt->CurFmtPosition = CURFMTPFXRDB ;
  1324.    Curfmt->CurFmtInterSpace = FALSE ;
  1325.    Curfmt->CurFmtLeadZeros = FALSE ;
  1326.  
  1327.    return(0) ;
  1328.  }
  1329.  
  1330. /* ------------------------------------------------------------------------ */
  1331.  
  1332.  INT cwFreeDlgMemory(HWND hWnd)
  1333.  {
  1334.    NTLINFStruct *Ntlinf ;
  1335.    DTEFMTStruct *Dtefmt ;
  1336.    TMEFMTStruct *Tmefmt ;
  1337.    NUMFMTStruct *Numfmt ;
  1338.    CURFMTStruct *Curfmt ;
  1339.  
  1340.    Ntlinf = (NTLINFStruct *)WinQueryWindowULong(hWnd, OFFSET_NTLINF) ;
  1341.    DosFreeMem((PVOID)(Ntlinf)) ;
  1342.    Dtefmt = (DTEFMTStruct *)WinQueryWindowULong(hWnd, OFFSET_DTEFMT) ;
  1343.    DosFreeMem((PVOID)(Dtefmt)) ;
  1344.    Tmefmt = (TMEFMTStruct *)WinQueryWindowULong(hWnd, OFFSET_TMEFMT) ;
  1345.    DosFreeMem((PVOID)(Tmefmt)) ;
  1346.    Numfmt = (NUMFMTStruct *)WinQueryWindowULong(hWnd, OFFSET_NUMFMT) ;
  1347.    DosFreeMem((PVOID)(Numfmt)) ;
  1348.    Curfmt = (CURFMTStruct *)WinQueryWindowULong(hWnd, OFFSET_CURFMT) ;
  1349.    DosFreeMem((PVOID)(Curfmt)) ;
  1350.   return(0) ;
  1351.  }
  1352.  
  1353. /* ------------------------------------------------------------------------ */
  1354.  
  1355.  void lmemset(void FAR *memptr, CHAR value, INT size)
  1356.  {
  1357.    char FAR *chrptr = memptr ;
  1358.  
  1359.    while (size--) *chrptr++ = value ;
  1360.  }
  1361.  
  1362. /* ------------------------------------------------------------------------ */
  1363.  
  1364.  int cwCheckDlgItem(HWND hWndDlg, INT id, INT state)
  1365.  {
  1366.    return((ULONG)WinSendDlgItemMsg(hWndDlg, id, BM_SETCHECK, MPFROMSHORT(state), 0L)) ;
  1367.  }
  1368.  
  1369. /* ------------------------------------------------------------------------ */
  1370.  
  1371.