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