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