home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / tool / various / skelet / skelabt.cpp < prev    next >
Text File  |  1994-08-14  |  5KB  |  184 lines

  1.  
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Filename:     skelabt.cpp
  5. //
  6. // Description:  Skeleton Visual Basic Custom Control.
  7. //
  8. //               This module displays the control's about box.
  9. //
  10. // Date Created: <Date>
  11. //
  12. // Author:       <Your Name>
  13. //
  14. // Copyright (c) <Your Company Name> 1994
  15. //
  16. //               Portions of this product are based on original
  17. //                  source code from Anton Software Limited.
  18. //
  19. //////////////////////////////////////////////////////////////////////////////
  20.  
  21. #include <windows.h>
  22. #include <vbapi.h>
  23.  
  24. #include "skeleton.hpp"
  25. #include "skelexp.hpp"
  26. #include "skelext.hpp"
  27.  
  28. //////////////////////////////////////////////////////////////////////////////
  29. //
  30. // Function Name: AboutDlgProc
  31. //
  32. // Description:   The about box's window (dialog) procedure.
  33. //
  34. // Parameters:    hwnd - Window handle
  35. //                msg  - message
  36. //                wp   - word parameter
  37. //                lp   - long parameter
  38. //
  39. // Return Code:   0 for processed messages, the result from the default window
  40. //                procedure otherwise.
  41. //
  42. //////////////////////////////////////////////////////////////////////////////
  43.  
  44. BOOL CALLBACK _export AboutDlgProc
  45. (
  46.     HWND   hwndDlg, // window handle
  47.     USHORT msg,     // message
  48.     USHORT wp,      // word parameter
  49.     LONG   lp       // long parameter
  50. )
  51. {
  52.     static HBRUSH hbr;  // brush handle (must be static)
  53.  
  54.     // Process the message...
  55.     switch (msg)
  56.     {
  57.         case WM_INITDIALOG:
  58.         {
  59.             RECT rect;       // rectangle
  60.             int  left;       // new x
  61.             int  top;        // new y
  62.             int  width;      // width
  63.             int  height;     // height
  64.  
  65.             // Position the about box centrally.
  66.             GetWindowRect(hwndDlg, &rect);
  67.  
  68.             width  = rect.right - rect.left;
  69.             height = rect.bottom - rect.top;
  70.             left   = (GetSystemMetrics(SM_CXSCREEN) - width)  / 2;
  71.             top    = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
  72.  
  73.             MoveWindow(hwndDlg, left, top, width, height, FALSE);
  74.  
  75.             //Create the background colour brush (light grey).
  76.             hbr = CreateSolidBrush(0x00C0C0C0);
  77.  
  78.             // Set the input focus.
  79.             return TRUE;
  80.  
  81.         } // end case WM_INITDIALOG
  82.  
  83.         case WM_CTLCOLOR:
  84.  
  85.             // Switch on the control type...
  86.             switch (HIWORD(lp))
  87.             {
  88.                 case CTLCOLOR_DLG:
  89.                     SetBkColor((HDC)wp, hbr);
  90.                     return (BOOL)hbr;
  91.  
  92.                 case CTLCOLOR_BTN:
  93.                 case CTLCOLOR_STATIC:
  94.                     SetBkMode((HDC)wp, TRANSPARENT);
  95.                     return (BOOL)hbr;
  96.  
  97.             } // end switch on the control type
  98.  
  99.             break;
  100.  
  101.         case WM_COMMAND:
  102.  
  103.             // Switch on the control...
  104.             switch (wp)
  105.             {
  106.                 // OK button clicked on About box
  107.                 case IDOK:
  108.  
  109.                     // FALSE returned from AboutDlgProc.
  110.                     EndDialog(hwndDlg, FALSE);
  111.                     return 0L;
  112.  
  113.             } // end switch on the control
  114.  
  115.             break;
  116.  
  117.         case WM_CLOSE:
  118.         case WM_DESTROY:
  119.  
  120.             // Get rid of the brush.
  121.             DeleteObject(hbr);
  122.             EndDialog(hwndDlg, FALSE);
  123.  
  124.      } // end switch on the message
  125.  
  126.      // Return FALSE.
  127.      return FALSE;
  128.  
  129. } // AboutDlgProc
  130.  
  131. //////////////////////////////////////////////////////////////////////////////
  132. //
  133. // Function Name: AboutWndProc
  134. //
  135. // Description:   Window procedure of the about box's invisible controlling
  136. //                parent window.
  137. //
  138. // Parameters:    hwnd - Window handle
  139. //                msg  - message
  140. //                wp   - word parameter
  141. //                lp   - long parameter
  142. //
  143. // Return Code:   0 for processed messages, the result from the default window
  144. //                procedure otherwise.
  145. //
  146. //////////////////////////////////////////////////////////////////////////////
  147.  
  148. LONG CALLBACK _export AboutWndProc
  149. (
  150.     HWND   hwnd,    // window handle
  151.     USHORT msg,     // message
  152.     USHORT wp,      // word parameter
  153.     LONG   lp       // long parameter
  154. )
  155. {
  156.     // Process the message...
  157.     switch (msg)
  158.     {
  159.         case WM_SHOWWINDOW:
  160.  
  161.             // Don't show the window, just post a message to open the dialog
  162.             // box.
  163.             if (wp)
  164.             {
  165.                 PostMessage(hwnd, WM_USER, 0, 0L);
  166.                 return 0L;
  167.             }
  168.  
  169.             break;
  170.  
  171.         case WM_USER:
  172.  
  173.             // Can now show the about box window.
  174.             VBDialogBoxParam(hmodDLL, "ABOUTBOX", (FARPROC)AboutDlgProc, 0L);
  175.             return 0L;
  176.  
  177.     } // end switch on the message
  178.  
  179.     // Return the result from the default window procedure.
  180.     return DefWindowProc(hwnd, msg, wp, lp);
  181.  
  182. } // AboutWndProc
  183.  
  184.