home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / zfamily.zip / zfamily / ZISFUNCS / SAMPLE / CHKFUN.C next >
Text File  |  1993-09-01  |  25KB  |  741 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   : CHKFUN.C
  18. **  Authors  : Alessandro Cavallini (CAVALLI at ROMEPPC)
  19. **             Pino Venturella (VENTUREL at ROMEPPC)
  20. **  Reviewer : Dario de Judicibus (DEJUDICI at ROMEPPC)
  21. **  Created  : 08 Jul 1992
  22. **  Updated  : 31 Aug 1993
  23. **  Version  : 3.12
  24. **  Content  : Sample program for FMZISFUN.DLL
  25. **
  26. */
  27.  #define EXTERN
  28.  #include <chkfun.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[22] ;
  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.    **  The CreateWindow function creates a frame window for this application's
  79.    **  top window, and set the window's size and location as appropriate.
  80.    */
  81.     WinLoadString(hAB, 0, IDS_TITLE, 22, szTitle) ;
  82.     hWndFrame = cwCreateWindow( (HWND)HWND_DESKTOP,
  83.                                 FCF_TITLEBAR     |
  84.                                 FCF_SYSMENU      |
  85.                                 FCF_MINBUTTON    |
  86.                                 FCF_MAXBUTTON    |
  87.                                 FCF_SIZEBORDER   |
  88.                                 FCF_MENU         |
  89.                                 FCF_ACCELTABLE   |
  90.                                 FCF_SHELLPOSITION,
  91.                                 szAppName,
  92.                                 szTitle,
  93.                                 ID_CHKFUN,
  94.                                 130, 124,
  95.                                 144, 34,
  96.                                 &hWndClient,
  97.                                 0L, SWP_SHOW) ;
  98.  
  99.     if (hWndFrame == 0) return(FALSE) ;
  100.  
  101.    /*
  102.    **  The following inline routine fills out the application's switch control
  103.    **  structure with the appropriate information to add the application's
  104.    **  name to the OS/2 Task Manager List, a list of the jobs currently
  105.    **  running on the computer.
  106.    */
  107.     WinQueryWindowProcess(hWndFrame, &pid, &tid) ;
  108.  
  109.     Swctl.hwnd = hWndFrame ;                         // Frame window handle
  110.     Swctl.idProcess = pid ;                          // Process identifier
  111.     Swctl.uchVisibility = SWL_VISIBLE ;              // visibility
  112.     Swctl.fbJump = SWL_JUMPABLE ;                    // Jump indicator
  113.     strcpy(Swctl.szSwtitle, szTitle) ;               // Frame window title
  114.  
  115.     hSwitch = WinAddSwitchEntry(&Swctl) ;
  116.  
  117.    /*
  118.    ** The following is the message loop for the application.
  119.    */
  120.     while(WinGetMsg(hAB, (PQMSG)&qmsg, 0, 0, 0))
  121.     {
  122.       WinDispatchMsg(hAB,(PQMSG)&qmsg) ;
  123.     }
  124.  
  125.    /*
  126.    **  Perform clean up before exiting application.
  127.    **  The following routine destroys the application's frame window (which
  128.    **  also destroys its child windows), destroys its message queue, and
  129.    **  disassociates the application from the Presentation Manager system.
  130.    */
  131.     WinDestroyWindow(hWndFrame) ; // Destroy the frame window
  132.     WinDestroyMsgQueue(hMQ) ;     // Destroy this application's message queue
  133.     WinTerminate(hAB) ;           // Terminate this application's use of the
  134.                                   // Presentation Manager resources
  135.  }
  136.  
  137. /* ------------------------------------------------------------------------ */
  138.  
  139. /*
  140. **  Main Window Procedure
  141. **
  142. **  This procedure provides service routines for the general PM events
  143. **  (messages) that PM sends to the window, as well as the user
  144. **  initiated events (messages) that are generated when the user selects
  145. **  the action bar and pulldown menu controls or the corresponding
  146. **  keyboard accelerators.
  147. **
  148. **  The SWITCH statement shown below distributes the window messages to
  149. **  the respective message service routines, which are set apart by the
  150. **  CASE statements. The window procedures must provide an appropriate
  151. **  service routine for its end user initiated messages, as well as the
  152. **  general PM messages (like the WM_CLOSE message). If a message is
  153. **  sent to this procedure for which there is no programmed CASE clause
  154. **  (i.e., no service routine), the message is defaulted to the
  155. **  WinDefWindowProc function, where it is disposed of by PM.
  156. **
  157. */
  158.  MRESULT EXPENTRY WndProc
  159.  (
  160.    HWND   hWnd    , // Window handle
  161.    ULONG  message , // Message
  162.    MPARAM mp1     , // First parameter of message
  163.    MPARAM mp2       // Second parameter of message
  164.  )
  165.  {
  166.    HPS hPS ;        // Handle for the Presentation Space
  167.    RECTL rClient ;  // Handle to rectangle formed by client area
  168.  
  169.    switch (message)
  170.    {
  171.      case WM_INITMENU :
  172.           break ;
  173.  
  174.      case WM_MENUEND :
  175.           break ;
  176.  
  177.      case WM_COMMAND :
  178.           {
  179.            /*
  180.            **  The PM messages for action bar and pulldown menu items are
  181.            **  processed in this routine.
  182.            */
  183.             switch (SHORT1FROMMP(mp1))
  184.             {
  185.               case IDM_T_START :
  186.                    {
  187.                     /*
  188.                     **  The code below makes a call to the dialog box named
  189.                     **  "TSTFUN". Variable rc will receive the
  190.                     **  return code sent when the dialog box is closed.
  191.                     */
  192.                      APIRET rc ;
  193.  
  194.                      rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)TSTFUNMsgProc,
  195.                                     0, IDLG_TSTFUN, (PVOID)&hWnd) ;
  196.                     }
  197.                     break ;
  198.  
  199.               case IDM_T_ABOUT :
  200.                    {
  201.                      /*
  202.                      **  Place User Code to respond to the
  203.                      **  Menu Item Named "~About" here.
  204.                      */
  205.                       #include "TSTABOUT.INC"
  206.                     }
  207.                     break ;
  208.  
  209.               case IDM_T_EXIT :
  210.                    {
  211.                      /*
  212.                      ** Place User Code to respond to the
  213.                      ** Menu Item Named "E~xit" here.
  214.                      */
  215.                       #include "TSTEXITW.INC"
  216.                     }
  217.                     break ;
  218.  
  219.              default:
  220.                     break ; // End of default case for switch (mp1)
  221.             } // End of switch mp1
  222.           }
  223.           break ; // End of WM_COMMAND
  224.  
  225.      case WM_CREATE :
  226.           {
  227.            /*
  228.            **  The WM_CREATE message is sent to a window when an application
  229.            **  requests that the window be created.  The window procedure
  230.            **  for the new window receives this message after the window is
  231.            **  created, but before the window becomes visible.
  232.            */
  233.             cwSetInitDlgStatus(hWnd) ;
  234.           }
  235.           break ;
  236.  
  237.      case WM_MOUSEMOVE :
  238.           {
  239.             return(WinDefWindowProc(hWnd, message, mp1, mp2)) ;
  240.           }
  241.           break ;
  242.  
  243.      case WM_SIZE :     // Code for sizing client area
  244.           break ;
  245.  
  246.      case WM_PAINT :    // Code for the window's client area
  247.           {
  248.            /*
  249.            **  Obtain a handle to a cache presentation space
  250.            */
  251.             hPS = WinBeginPaint(hWnd, 0, 0) ;
  252.  
  253.            /*
  254.            **  Determine the size of the client area
  255.            */
  256.             WinQueryWindowRect(hWnd, &rClient) ;
  257.  
  258.            /*
  259.            **  Fill the background with the default background color
  260.            */
  261.             WinFillRect(hPS, &rClient, CLR_BACKGROUND) ;
  262.  
  263.            /*
  264.            **  Return presentation space to state before WinBeginPaint
  265.            */
  266.             WinEndPaint(hPS) ;
  267.           }
  268.           break ;
  269.  
  270.      case WM_CLOSE :  // Close the window
  271.           {
  272.             if(hWnd != hWndClient) break ;
  273.  
  274.             #include "TSTCLOSE.INC"
  275.  
  276.             cwFreeDlgMemory(hWnd) ;
  277.             return(WinDefWindowProc(hWnd, message, mp1, mp2)) ;
  278.           }
  279.           break ;
  280.  
  281.      case WM_TRANSLATEACCEL :
  282.           {
  283.             return(WinDefWindowProc(hWndClient, message, mp1, mp2)) ;
  284.           }
  285.           break ;
  286.  
  287.      default:
  288.           {
  289.            /*
  290.            **  For any message for which you don't specifically provide a
  291.            **  service routine, you should return the message to PM using
  292.            **  the WinDefWindowProc function.
  293.            */
  294.             return(WinDefWindowProc(hWnd, message, mp1, mp2)) ;
  295.           }
  296.           break ;
  297.    } // End of switch
  298.  
  299.    return(0L) ;
  300.  }
  301.  
  302. /* ------------------------------------------------------------------------ */
  303.  
  304. /*
  305. **  Dialog Window Procedure
  306. **
  307. **  This procedure is associated with the dialog box that is included in
  308. **  the function name of the procedure. It provides the service routines
  309. **  for the events (messages) that occur because the end user operates
  310. **  one of the dialog box's buttons, entry fields, or controls.
  311. **
  312. **  The SWITCH statement in the function distributes the dialog box
  313. **  messages to the respective service routines, which are set apart by
  314. **  the CASE clauses. Like any other PM window, the Dialog Window
  315. **  procedures must provide an appropriate service routine for their end
  316. **  user initiated messages as well as for the general PM messages (like
  317. **  the WM_CLOSE message). If a message is sent to this procedure for
  318. **  which there is no programmed CASE condition (no service routine),
  319. **  the message is defaulted to the WinDefDlgProc function, where it is
  320. **  disposed of by PM.
  321. **
  322. */
  323.  MRESULT EXPENTRY TSTFUNMsgProc
  324.  (
  325.    HWND   hWndDlg , // Dialog handle
  326.    ULONG  message , // Message
  327.    MPARAM mp1     , // First parameter of message
  328.    MPARAM mp2       // Second parameter of message
  329.  )
  330.  {
  331.    static HWND  hWndParent ;
  332.    TSTFUNStruct *Tstfun ;
  333.  
  334.    switch (message)
  335.    {
  336.      case WM_INITDLG :
  337.      {
  338.        int i ; // loop counter
  339.  
  340.        Tstfun = (TSTFUNStruct *)WinQueryWindowULong(hWndClient, OFFSET_TSTFUN) ;
  341.        hWndParent = *((HWND *)mp2) ;
  342.  
  343.        cwCenter(hWndDlg, (HWND)hWndParent) ;
  344.  
  345.       /*
  346.       ** Initialize entry field control: TstFunInput
  347.       */
  348.        WinSendDlgItemMsg (hWndDlg, TSTFUNINPFLD, EM_SETTEXTLIMIT, MPFROMSHORT(32), 0L) ;
  349.        Tstfun->TstFunInput[0] = 0 ;
  350.  
  351.       /*
  352.       **  Initialize all the other controls
  353.       */
  354.        #include "TSTINIT.INC"
  355.      }
  356.      break ; // End of WM_INITDLG
  357.  
  358.      case WM_CONTROL :
  359.      {
  360.        switch (SHORT1FROMMP(mp1))
  361.        {
  362.          case TSTFUNTRURDB: // Radiobutton text: "True"
  363.          {
  364.            cwCheckDlgItem(hWndDlg, TSTFUNFALRDB, FALSE) ;
  365.          }
  366.          break ;
  367.  
  368.          case TSTFUNFALRDB: // Radiobutton text: "False"
  369.          {
  370.            cwCheckDlgItem(hWndDlg, TSTFUNTRURDB, FALSE) ;
  371.          }
  372.          break ;
  373.  
  374.          case TSTFUNTYPDDL: // Entry field and combo box list: "TstFunType"
  375.          {
  376.            switch (SHORT2FROMMP(mp1)) // Switch on Notification Code
  377.            {
  378.              case CBN_EFCHANGE:
  379.                   {
  380.                     #include "TSTTYPE.INC"
  381.                   }
  382.                   break ;
  383.  
  384.              default: // Default other messages
  385.                   return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  386.                   break ;
  387.            }
  388.          }
  389.          break ;
  390.  
  391.          case TSTFUNNOTDDL: // Entry field and combo box: "TstFunNotation"
  392.          {
  393.            switch (SHORT2FROMMP(mp1)) // Switch on Notification Code
  394.            {
  395.              case CBN_EFCHANGE:
  396.                   {
  397.                     #include "TSTNOTAT.INC"
  398.                   }
  399.                   break ;
  400.  
  401.  
  402.              default: // Default other messages
  403.                   return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  404.                   break ;
  405.            }
  406.          }
  407.          break ;
  408.  
  409.          case TSTFUNINPFLD: // Entry field variable: "TstFunInput"
  410.          {
  411.            switch (SHORT2FROMMP(mp1)) // Switch on Notification Code
  412.            {
  413.              case EN_SETFOCUS:  // Entry field is receiving the focus
  414.                   #include "TSTINPUT.INC"
  415.                   break ;
  416.  
  417.              case EN_KILLFOCUS: // Entry field is losing the focus
  418.                   break ;
  419.            }
  420.          }
  421.          break ;
  422.  
  423.          case TSTFUNSMPFLD: // Entry field variable: "TstFunSample"
  424.          {
  425.            switch (SHORT2FROMMP(mp1)) // Sswitch on Notification Code
  426.            {
  427.              case EN_SETFOCUS:  // Entry field is receiving the focus
  428.                   break ;
  429.  
  430.              case EN_KILLFOCUS: // Entry field is losing the focus
  431.                   break ;
  432.            }
  433.          }
  434.          break ;
  435.        }
  436.      }
  437.      break ; // End of WM_CONTROL
  438.  
  439.      case WM_COMMAND:
  440.      {
  441.        switch (SHORT1FROMMP(mp1))
  442.        {
  443.          case TSTFUNCHKBUT: // Button text: "~Check value "
  444.               #include "TSTCHECK.INC"
  445.               break ;
  446.  
  447.          case TSTFUNEXIBUT: // Button text: "E~xit"
  448.               #include "TSTEXIT.INC"
  449.               break ;
  450.        }
  451.      }
  452.      break ; // End of WM_COMMAND
  453.  
  454.      case WM_CLOSE:
  455.           WinDismissDlg(hWndDlg, FALSE) ;
  456.           break ; // End of WM_CLOSE
  457.  
  458.      case WM_FAILEDVALIDATE:
  459.           return((MRESULT)TRUE) ;
  460.           break ;
  461.  
  462.      default:
  463.           return(WinDefDlgProc(hWndDlg, message, mp1, mp2)) ;
  464.           break ;
  465.    }
  466.    return FALSE ;
  467.  }
  468.  
  469. /* ------------------------------------------------------------------------ */
  470.  
  471. /*
  472. **  cwRegisterClass Function
  473. **
  474. **  The following function registers all the classes of all the windows
  475. **  associated with this application. The function returns TRUE if it is
  476. **  successful, otherwise it returns FALSE.
  477. **
  478. */
  479.  INT cwRegisterClass(VOID)
  480.  {
  481.    APIRET rc ;
  482.  
  483.    WinLoadString(hAB, 0, IDS_APP_NAME, 80, szAppName) ; // Program name
  484.  
  485.    rc = WinRegisterClass (hAB,              // Anchor block handle
  486.                           (PCH)szAppName,   // Name of class being registered
  487.                           (PFNWP)WndProc,   // Window procedure for class
  488.                           CS_SIZEREDRAW ,
  489.                           1*sizeof(char*)) ;
  490.    if (rc == FALSE) return(FALSE) ;
  491.  
  492.    return(TRUE) ;
  493.  }
  494.  
  495. /* ------------------------------------------------------------------------ */
  496.  
  497. /*
  498. **  cwCreateWindow Function
  499. **
  500. **  The following function is used to create a window (the main window,
  501. **  a child window, an icon window, etc.) and set it's initial size and
  502. **  position. It returns the handle to the frame window.
  503. **
  504. */
  505.  HWND cwCreateWindow
  506.  (
  507.    HWND   hWndParent,  // Handle to the parent of the window to be created
  508.    ULONG  ctldata,     // Frame control flags for the window
  509.    PCH    appname,     // Class name of the window
  510.    PCH    title,       // Title of the window
  511.    ULONG  ResID,       // Resource id value
  512.    INT    x,           // Initial horizontal and vertical location
  513.    INT    y,           //
  514.    INT    cx,          // Initial width and height of the window
  515.    INT    cy,          //
  516.    PHWND  hWndClient,  // Handle to the client area of the window
  517.    ULONG  lfStyle,     // Frame window style
  518.    USHORT uSizeStyle   // User defined size and location flags
  519.  )
  520.  {
  521.    ULONG  rc ;            // Accepts return codes from function calls
  522.    HWND   hWndFrame ;     // Local handle to created window frame
  523.    ULONG  SizeStyle ;     // Local window positioning options
  524.    CHAR   MsgBuffer[80] ; // Buffer for error messages
  525.    HPS    hPS ;           // Handle to a presentation space
  526.    int    xmod, ymod ;    // Modifiers for sizing
  527.    #define DLGXMOD  4     // Dialog units X modulo
  528.    #define DLGYMOD  8     // Dialog units Y modulo
  529.    FONTMETRICS fm ;       // Structure for determing modifiers
  530.  
  531.   /*
  532.   **  Create the frame window
  533.   */
  534.    hWndFrame = WinCreateStdWindow(hWndParent,  // Parent of window
  535.                                   lfStyle,     // Frame window style
  536.                                   &ctldata,    // Frame flags
  537.                                   appname,     // Class name
  538.                                   title,       // Window title
  539.                                   0L,          // Client window style
  540.                                   0,           // Module for resources
  541.                                   ResID,       // Resource id
  542.                                   (HWND *)hWndClient) ; // Client handle
  543.  
  544.   /*
  545.   **  If hWndFrame is NULL, an error occured when opening the window,
  546.   **  notify the user and exit this function
  547.   */
  548.    if(hWndFrame == 0)
  549.    {
  550.      WinLoadString(hAB, 0, IDS_ERR_WINDOW_CREATE, 80, MsgBuffer) ;
  551.      WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  552.                    0, 0, MB_OK|MB_ICONEXCLAMATION) ;
  553.      return ((HWND)0) ;
  554.    }
  555.  
  556.   /*
  557.   **  Set up size options
  558.   */
  559.    SizeStyle = SWP_ACTIVATE | SWP_ZORDER | uSizeStyle ;
  560.  
  561.   /*
  562.   **  If the height, width, intial x or initial y values are non-zero,
  563.   **  then we will need to set up the modifiers for size and location
  564.   */
  565.    if((cx > 0) || (cy > 0) || (x != 0)  || (y != 0))
  566.    {
  567.      hPS = WinGetPS(HWND_DESKTOP) ;
  568.      GpiQueryFontMetrics(hPS, (LONG)sizeof(FONTMETRICS), &fm) ;
  569.      xmod = (INT)fm.lAveCharWidth ;
  570.      ymod = (INT)fm.lMaxBaselineExt ;
  571.      WinReleasePS(hPS) ;
  572.    }
  573.  
  574.   /*
  575.   **  If either the width or the height are non-zero, then the size of the
  576.   **  created window will be changed, set SizeStyle accordingly
  577.   */
  578.    if((cx > 0) || (cy > 0) || (x != 0) || (y != 0))
  579.    {
  580.      SizeStyle |= SWP_SIZE ;
  581.      SizeStyle |= SWP_MOVE ;
  582.    }
  583.  
  584.   /*
  585.   **  Set the size and position of the window and activate it
  586.   */
  587.    rc = WinSetWindowPos(hWndFrame, HWND_TOP,
  588.                         ((x * xmod)/DLGXMOD),
  589.                         ((y * ymod)/DLGYMOD),
  590.                         ((cx * xmod)/DLGXMOD),
  591.                         ((cy * ymod)/DLGYMOD), SizeStyle) ;
  592.  
  593.   /*
  594.   **  If rc is not set to TRUE then WinSetWindowPos failed, notify the user
  595.   **  and exit this function
  596.   */
  597.    if(!rc)
  598.    {
  599.      WinLoadString(hAB, 0, IDS_ERR_WINDOW_POS, 80, MsgBuffer) ;
  600.      WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  601.                    0, 0, MB_OK|MB_ICONEXCLAMATION) ;
  602.      return((HWND)0) ;
  603.    }
  604.  
  605.   /*
  606.   **  Return the handle to the frame window
  607.   */
  608.    return(hWndFrame) ;
  609.  }
  610.  
  611. /* ------------------------------------------------------------------------ */
  612.  
  613. /*
  614. **  cwCenter Function
  615. **
  616. **  Centers a dialog box on the client area of the caller
  617. **
  618. **  hWnd       - handle of the window to be centered
  619. **  hWndParent - handle of the window on which to center
  620. **
  621. */
  622.  INT cwCenter
  623.  (
  624.    HWND hWnd       ,
  625.    HWND hWndParent
  626.  )
  627.  {
  628.    LONG   SrcX, SrcY ;                // Center of parent
  629.    LONG   x, y ;                      // Destination points
  630.    SWP    DlgSwp, ParentSwp ;         // Set window position structures
  631.    LONG   ScreenWidth, ScreenHeight ; // Dimensions of the DESKTOP
  632.    POINTL pt ;                        // Point
  633.  
  634.   /*
  635.   **  Determine the width and height of the DESKTOP so the dialog box
  636.   **  will not be positioned to a point off of the screen.
  637.   */
  638.    ScreenWidth  = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) ;
  639.    ScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN) ;
  640.  
  641.   /*
  642.   **  Query width and depth of dialog box
  643.   */
  644.    WinQueryWindowPos(hWnd, (PSWP)&DlgSwp) ;
  645.  
  646.   /*
  647.   **  Query width and depth of caller
  648.   */
  649.    WinQueryWindowPos(hWndParent, (PSWP)&ParentSwp) ;
  650.  
  651.   /*
  652.   **  Map the point parent points to the Desktop
  653.   */
  654.    pt.x = ParentSwp.x ;
  655.    pt.y = ParentSwp.y ;
  656.  
  657.   /*
  658.   **  Convert the point from having our window as the origin to having
  659.   **  the DESKTOP as the origin
  660.   */
  661.    WinMapWindowPoints(hWndParent, HWND_DESKTOP, &pt, 1) ;
  662.  
  663.    SrcX = pt.x + (ParentSwp.cx / 2) ;
  664.    SrcY = pt.y + (ParentSwp.cy / 2) ;
  665.  
  666.   /*
  667.   **  Determine the point to move the dialog box to
  668.   */
  669.    x = (SrcX - (DlgSwp.cx / 2)) ;
  670.    y = (SrcY - (DlgSwp.cy / 2)) ;
  671.  
  672.   /*
  673.   **  If either point is less than zero, then set that point to zero
  674.   **  so the dialog box will not be positoned off of the window
  675.   */
  676.    x = (x < 0L) ? 0L : x ;
  677.    y = (y < 0L) ? 0L : y ;
  678.  
  679.   /*
  680.   **  If either point plus the height or width of the dialog box is
  681.   **  greater than the height or width of the screen adjust point
  682.   */
  683.    if ((x + DlgSwp.cx) > ScreenWidth)  x = ScreenWidth - DlgSwp.cx ;
  684.    if ((y + DlgSwp.cy) > ScreenHeight) y = ScreenHeight - DlgSwp.cy ;
  685.  
  686.   /*
  687.   **  Move the dialog box
  688.   */
  689.    return(WinSetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_MOVE)) ;
  690.  }
  691.  
  692. /* ------------------------------------------------------------------------ */
  693.  
  694. /*
  695. **  This function allocates memory for dialog box variables and initializes
  696. **  the state of any initially selected radio buttons and check boxes.
  697. */
  698.  INT cwSetInitDlgStatus(HWND hWnd)
  699.  {
  700.    TSTFUNStruct *Tstfun ;
  701.  
  702.    OFFSETOF(Tstfun) = 0 ;
  703.    DosAllocMem(((PPVOID)&Tstfun), sizeof(TSTFUNStruct), fALLOC) ;
  704.    memset(Tstfun, 0x00, sizeof(TSTFUNStruct)) ;
  705.    WinSetWindowULong(hWnd, OFFSET_TSTFUN, (ULONG)Tstfun) ;
  706.  
  707.   return(0) ;
  708.  }
  709.  
  710. /* ------------------------------------------------------------------------ */
  711.  
  712.  INT cwFreeDlgMemory(HWND hWnd)
  713.  {
  714.    TSTFUNStruct *Tstfun ;
  715.  
  716.    Tstfun = (TSTFUNStruct *)WinQueryWindowULong(hWnd, OFFSET_TSTFUN) ;
  717.    DosFreeMem((PVOID)(Tstfun)) ;
  718.  
  719.    return(0) ;
  720.  }
  721.  
  722. /* ------------------------------------------------------------------------ */
  723.  
  724.  void lmemset(void FAR *memptr, CHAR value, INT size)
  725.  {
  726.    char FAR *chrptr = memptr ;
  727.  
  728.    while (size--) *chrptr++ = value ;
  729.  }
  730.  
  731. /* ------------------------------------------------------------------------ */
  732.  
  733.  LONG cwCheckDlgItem(HWND hWndDlg, LONG id, LONG state)
  734.  {
  735.   return((INT)(ULONG)WinSendDlgItemMsg (hWndDlg, id, BM_SETCHECK,
  736.                                         MPFROMLONG(state), 0L)) ;
  737.  }
  738.  
  739. /* ------------------------------------------------------------------------ */
  740.  
  741.