home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / winsock / ipxchat / about.c next >
C/C++ Source or Header  |  1997-10-05  |  8KB  |  272 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1997  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26. #include <wsipx.h>              // IPX Sockets defs
  27. #include "globals.h"            // prototypes specific to this application
  28.  
  29. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  30. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  31. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  32. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  33.  
  34. // About dialog message table definition.
  35. MSD rgmsdAbout[] =
  36. {
  37.     {WM_COMMAND,    MsgAboutCommand},
  38.     {WM_INITDIALOG, MsgAboutInit}
  39. };
  40.  
  41. MSDI msdiAbout =
  42. {
  43.     sizeof(rgmsdAbout) / sizeof(MSD),
  44.     rgmsdAbout,
  45.     edwpNone
  46. };
  47.  
  48. // About dialog command table definition.
  49. CMD rgcmdAbout[] =
  50. {
  51.     {IDOK,     CmdAboutDone},
  52.     {IDCANCEL, CmdAboutDone}
  53. };
  54.  
  55. CMDI cmdiAbout =
  56. {
  57.     sizeof(rgcmdAbout) / sizeof(CMD),
  58.     rgcmdAbout,
  59.     edwpNone
  60. };
  61.  
  62. // Module specific "globals"  Used when a variable needs to be
  63. // accessed in more than on handler function.
  64.  
  65. HFONT hFontCopyright;
  66.  
  67. //
  68. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  69. //
  70. //  PURPOSE: Displays the "About" dialog box
  71. //
  72. //  PARAMETERS:
  73. //    hwnd      - Window handle
  74. //    wCommand  - IDM_ABOUT (unused)
  75. //    wNotify   - Notification number (unused)
  76. //    hwndCtrl  - NULL (unused)
  77. //
  78. //  RETURN VALUE:
  79. //
  80. //    Always returns 0 - Message handled
  81. //
  82. //  COMMENTS:
  83. //    To process the IDM_ABOUT message, call DialogBox() to display the
  84. //    about dialog box.
  85.  
  86. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  87. {
  88.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  89.     return 0;
  90. }
  91.  
  92.  
  93. //
  94. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  95. //
  96. //  PURPOSE:  Processes messages for "About" dialog box.
  97. //
  98. //  PARAMETERS:
  99. //    hdlg - window handle of the dialog box
  100. //    wMessage - type of message
  101. //    wparam - message-specific information
  102. //    lparam - message-specific information
  103. //
  104. //  RETURN VALUE:
  105. //    TRUE - message handled
  106. //    FALSE - message not handled
  107. //
  108. //  COMMENTS:
  109. //
  110. //     Display version information from the version section of the
  111. //     application resource.
  112. //
  113. //     Wait for user to click on "Ok" button, then close the dialog box.
  114. //
  115.  
  116. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  117. {
  118.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  119. }
  120.  
  121.  
  122. //
  123. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  124. //
  125. //  PURPOSE: To initialize the about box with version info from resources.
  126. //
  127. //  PARAMETERS:
  128. //    hwnd - The window handing the message.
  129. //    uMessage - The message number. (unused).
  130. //    wparam - Message specific data (unused).
  131. //    lparam - Message specific data (unused).
  132. //
  133. //  RETURN VALUE:
  134. //    Always returns 0 - message handled.
  135. //
  136. //  COMMENTS:
  137. //    Uses the version apis to retrieve version information for
  138. //    each of the static text boxes in the about box.
  139. //
  140.  
  141. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  142. {
  143.     #define POINTSIZE 8
  144.  
  145.     char  szFullPath[256];
  146.     DWORD dwVerHnd;
  147.     DWORD dwVerInfoSize;
  148.     HDC   hDC;
  149.     int   iLogPixelsY, iPointSize;
  150.  
  151.     // Center the dialog over the application window
  152.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  153.  
  154.     // Set the copyright font to something smaller than default
  155.     hDC = GetDC(hdlg);
  156.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  157.     ReleaseDC(hdlg, hDC);
  158.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  159.     iPointSize *= -1;
  160.  
  161.     hFontCopyright = CreateFont(iPointSize,
  162.                                 0, 0, 0,
  163.                                 FW_DONTCARE,
  164.                                 0, 0, 0, 0,
  165.                                 0, 0, 0, 0,
  166.                                 "System");
  167.  
  168.     SendDlgItemMessage(hdlg, 
  169.                        IDD_VERLAST, 
  170.                        WM_SETFONT, 
  171.                        (WPARAM)hFontCopyright,
  172.                        0L);
  173.  
  174.     // Get version information from the application
  175.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  176.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  177.     if (dwVerInfoSize)
  178.     {
  179.         // If we were able to get the information, process it:
  180.         HANDLE  hMem;
  181.         LPVOID  lpvMem;
  182.         char    szGetName[256];
  183.         int     cchRoot;
  184.         int     i;
  185.  
  186.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  187.         lpvMem = GlobalLock(hMem);
  188.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  189.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  190.         cchRoot = lstrlen(szGetName);
  191.  
  192.         // Walk through the dialog items that we want to replace:
  193.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  194.         {
  195.             BOOL  fRet;
  196.             UINT  cchVer = 0;
  197.             LPSTR lszVer = NULL;
  198.             char  szResult[256];
  199.  
  200.             GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  201.             lstrcpy(&szGetName[cchRoot], szResult);
  202.             fRet = VerQueryValue(lpvMem, szGetName, &lszVer, &cchVer);
  203.  
  204.             if (fRet && cchVer && lszVer)
  205.             {
  206.                 // Replace dialog item text with version info
  207.                 lstrcpy(szResult, lszVer);
  208.                 SetDlgItemText(hdlg, i, szResult);
  209.             }
  210.         }
  211.         GlobalUnlock(hMem);
  212.         GlobalFree(hMem);
  213.     }
  214.     return TRUE;
  215. }
  216.  
  217. //
  218. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  219. //
  220. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  221. //
  222. //  PARAMETERS:
  223. //    hwnd - The window handing the message.
  224. //    uMessage - The message number. (unused).
  225. //    wparam - Message specific data (unused).
  226. //    lparam - Message specific data (unused).
  227. //
  228. //  RETURN VALUE:
  229. //    Always returns 0 - message handled.
  230. //
  231. //  COMMENTS:
  232. //    Uses this DipsCommand function defined in wndproc.c combined
  233. //    with the cmdiAbout structure defined in this file to handle
  234. //    the command messages for the about dialog box.
  235. //
  236.  
  237. LRESULT MsgAboutCommand(HWND   hwnd, 
  238.                         UINT   uMessage, 
  239.                         WPARAM wparam, 
  240.                         LPARAM lparam)
  241. {
  242.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  243. }
  244.  
  245. //
  246. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  247. //
  248. //  PURPOSE: Free the about box and related data.
  249. //
  250. //  PARAMETERS:
  251. //    hwnd - The window handling the command.
  252. //    wCommand - The command to be handled (unused).
  253. //    wNotify   - Notification number (unused)
  254. //    hwndCtrl - NULL (unused).
  255. //
  256. //  RETURN VALUE:
  257. //    Always returns TRUE.
  258. //
  259. //  COMMENTS:
  260. //    Calls EndDialog to finish the dialog session.
  261. //
  262.  
  263. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  264. {
  265.     if (hFontCopyright)
  266.        DeleteObject(hFontCopyright);
  267.  
  268.     EndDialog(hdlg, TRUE);          // Exit the dialog
  269.     return TRUE;
  270. }
  271.  
  272.