home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / SHARE / os2 / edm2 / common / snippets / display.txt < prev    next >
Encoding:
Text File  |  1997-03-26  |  3.0 KB  |  106 lines

  1. Larry Salomon, Jr.:
  2.  
  3. SHORT winDisplayMessage(HWND hwndParent,
  4.                         HWND hwndOwner,
  5.                         ULONG ulStyle,
  6.                         HMODULE hmDll,
  7.                         USHORT usId,
  8.                         USHORT usHelpId,...)
  9. //------------------------------------------------
  10.  
  11. // This function puts a message to the screen in
  12. // PM mode (using WinMessageBox).
  13.  
  14. // The title of the message box is assumed to have
  15. // the message id usId|0x8000.
  16.  
  17. //
  18. // Input:  hwndParent - handle of the parent window
  19. //         hwndOwner - handle of the owning window
  20. //         ulStyle - specifies the WinMessageBox styles
  21. //         hmDll - handle of the DLL containing the message
  22. //         usId - specifies the id of the message to load
  23. //         usHelpId - specifies the id of the
  24.                       corresponding help panel
  25. // Returns:  TRUE if successful, FALSE otherwise
  26. //------------------------------------------------
  27. {
  28.    CHAR achMsg[1024];
  29.    CHAR achTitle[256];
  30.    va_list vlArgs;
  31.    CHAR achBuf[2048];
  32.    ULONG ulRc;
  33.  
  34.    if (ulStyle==0L) {
  35.       ulStyle=MB_INFORMATION | MB_OK;
  36.    } /* endif */
  37.  
  38.    if ((ulStyle & MB_SYSTEMMODAL)==0) {
  39.       ulStyle|=MB_APPLMODAL;
  40.    } /* endif */
  41.  
  42.    if (usHelpId!=0) {
  43.       ulStyle|=MB_HELP;
  44.    } /* endif */
  45.  
  46.    ulStyle|=MB_MOVEABLE;
  47.  
  48.    //----------------------------------------------
  49.    // Load the message box text and title
  50.    //----------------------------------------------
  51.    if (WinLoadString(NULLHANDLE,
  52.                      hmDll,
  53.                      usId,
  54.                      sizeof(achMsg),
  55.                      achMsg)==0) {
  56.       return MBID_ERROR;
  57.    } /* endif */
  58.  
  59.    if (WinLoadString(NULLHANDLE,
  60.                      hmDll,
  61.                      usId | 0x8000,
  62.                      sizeof(achTitle),
  63.                      achTitle)==0) {
  64.       return MBID_ERROR;
  65.    } /* endif */
  66.  
  67.    //----------------------------------------------
  68.    // Format the message and display it
  69.    //----------------------------------------------
  70.    va_start(vlArgs,usHelpId);
  71.    vsprintf(achBuf,achMsg,vlArgs);
  72.    va_end(vlArgs);
  73.  
  74.    ulRc=WinMessageBox(hwndParent,
  75.                       hwndOwner,
  76.                       achBuf,
  77.                       achTitle,
  78.                       usHelpId,
  79.                       ulStyle);
  80.    return ulRc;
  81. }
  82.  
  83. VOID winCenterWindow(HWND hwndCenter)
  84. //------------------------------------------------
  85. // This function centers the window within its parent
  86. //
  87. // Input:  hwndCenter - handle of the window to center
  88. //-----------------------------------------------
  89. {
  90.    SWP swpCenter;
  91.    RECTL rclParent;
  92.  
  93.    WinQueryWindowPos(hwndCenter,&swpCenter);
  94.    WinQueryWindowRect(WinQueryWindow(hwndCenter,QW_PARENT),
  95.                       &rclParent);
  96.  
  97.    swpCenter.x=(rclParent.xRight-swpCenter.cx)/2;
  98.    swpCenter.y=(rclParent.yTop-swpCenter.cy)/2;
  99.  
  100.  
  101. WinSetWindowPos(hwndCenter,NULLHANDLE,swpCenter.x,
  102.                 swpCenter.y,0,0,SWP_MOVE);
  103.  
  104. }
  105.  
  106.