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