Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. Dialog
  5. File Name:
  6. Dialog.cpp
  7. Abstract:
  8. Simple property sheet application skeleton. All page resource are in a common
  9. resource file, but each page implementation is in a separate source file.
  10. Author:
  11. Environment:
  12. Win32, C++
  13. Revision History:
  14. none
  15. Notes:
  16. --*/
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <commdlg.h>
  22. #include <commctrl.h>
  23. #include <ole2.h>
  24. #include <stdio.h>
  25. #include "support.h"
  26. #include "utils.h"
  27. #include "res.h"
  28. // Page currently active - set on the page activate notification. used to prevent
  29. // processing of the apply message except for the page currently shown when the
  30. // user hits OK.
  31. INT iCurrent = 0;
  32. // The unblock challenge has been acquired from the card, and the user has entered
  33. // a response to it. This mode should be left by cancel or finishing the unblock.
  34. BOOL fUnblockActive = FALSE;
  35. #define MODALPROPSHEET 0
  36. #define numpages 2
  37. HINSTANCE ghInstance = NULL;
  38. HWND hwndContainer = NULL;
  39. INT_PTR CALLBACK PageProc1(
  40. HWND hwnd,
  41. UINT msg,
  42. WPARAM wparam,
  43. LPARAM lparam);
  44. INT_PTR CALLBACK PageProc2(
  45. HWND hwnd,
  46. UINT msg,
  47. WPARAM wparam,
  48. LPARAM lparam);
  49. /* ---------------------------------------------------------------------
  50. HelpHandler
  51. Part of the implementation for context sensitive help. This function is called with
  52. the control ID, which needs to be mapped to a string and displayed in a popup.
  53. --------------------------------------------------------------------- */
  54. void HelpHandler(LPARAM lp)
  55. {
  56. HELPINFO *pH = (HELPINFO *) lp;
  57. UINT ControlID;
  58. WCHAR szTemp[200];
  59. ControlID = pH->iCtrlId;
  60. swprintf(szTemp,L"Help request for control %d\n",ControlID);
  61. OutputDebugString(szTemp);
  62. }
  63. /* ---------------------------------------------------------------------
  64. CreateFontY
  65. Create the font used on the property page UI.
  66. --------------------------------------------------------------------- */
  67. HFONT CreateFontY(LPCTSTR pszFontName,LONG lWeight,LONG lHeight)
  68. {
  69. NONCLIENTMETRICS ncm = {0};
  70. if (NULL == pszFontName)
  71. {
  72. return NULL;
  73. }
  74. if (0 == lHeight)
  75. {
  76. return NULL;
  77. }
  78. ncm.cbSize = sizeof(ncm);
  79. if (!SystemParametersInfo(SPI_GETNONCLIENTMETRICS,0,&ncm,0))
  80. {
  81. return NULL;
  82. }
  83. LOGFONT TitleLogFont = ncm.lfMessageFont;
  84. TitleLogFont.lfWeight = lWeight;
  85. lstrcpyn(TitleLogFont.lfFaceName,pszFontName,LF_FACESIZE);
  86. HDC hdc = GetDC(NULL);
  87. if (NULL == hdc)
  88. {
  89. return NULL;
  90. }
  91. INT FontSize = lHeight;
  92. TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc,LOGPIXELSY) * FontSize / 72;
  93. HFONT h = CreateFontIndirect(&TitleLogFont);
  94. ReleaseDC(NULL,hdc);
  95. return h;
  96. }
  97. /* ---------------------------------------------------------------------
  98. InitPropertyPage
  99. More of a macro, really... Performs some routine structure initalization functions to
  100. set up a page in an array of pages to be passed when starting up the property
  101. sheet.
  102. --------------------------------------------------------------------- */
  103. void InitPropertyPage( PROPSHEETPAGE* psp,
  104. INT idDlg,
  105. DLGPROC pfnDlgProc,
  106. DWORD dwFlags,
  107. LPARAM lParam)
  108. {
  109. memset((LPVOID)psp,0,sizeof(PROPSHEETPAGE));
  110. psp->dwFlags = dwFlags;
  111. psp->pszTemplate = MAKEINTRESOURCE(idDlg);
  112. psp->pfnDlgProc = pfnDlgProc;
  113. psp->dwSize = sizeof(PROPSHEETPAGE);
  114. psp->hInstance = ghInstance;
  115. }
  116. /* ---------------------------------------------------------------------
  117. ShowPropertySheet
  118. Initializes the property sheet header, sets up the pages, and displays the
  119. property sheet.
  120. --------------------------------------------------------------------- */
  121. void APIENTRY ShowPropertySheet(HWND hwndOwner)
  122. {
  123. PROPSHEETPAGE psp[numpages];
  124. HPROPSHEETPAGE hpsp[numpages];
  125. PROPSHEETHEADER psh;
  126. HFONT hTitleFont = NULL;
  127. INT_PTR iRet;
  128. #if MODALPROPSHEET
  129. if (NULL == hwndOwner)
  130. {
  131. hwndOwner = GetForegroundWindow();
  132. }
  133. #endif
  134. hTitleFont = CreateFontY(L"MS Shell Dlg",FW_BOLD,12);
  135. InitPropertyPage( &psp[0], IDD_PAGE1, PageProc1, PSP_DEFAULT, 0);
  136. InitPropertyPage( &psp[1], IDD_PAGE2, PageProc2, PSP_DEFAULT, 0);
  137. for (INT j=0;j<numpages;j++)
  138. {
  139. hpsp[j] = CreatePropertySheetPage((LPCPROPSHEETPAGE) &psp[j]);
  140. }
  141. psh.dwSize = sizeof(PROPSHEETHEADER);
  142. psh.dwFlags = PSH_HEADER | PSH_NOAPPLYNOW;
  143. psh.hwndParent = hwndOwner;
  144. psh.pszCaption = (LPCTSTR)IDS_APP_NAME;
  145. psh.nPages = numpages;
  146. psh.nStartPage = 0;
  147. psh.phpage = (HPROPSHEETPAGE *) hpsp;
  148. psh.pszbmWatermark = NULL;
  149. psh.pszbmHeader = NULL;
  150. psh.hInstance = ghInstance;
  151. // modal property sheet
  152. SetErrorMode(0);
  153. iRet = PropertySheet(&psh);
  154. if (hTitleFont)
  155. {
  156. DeleteObject (hTitleFont);
  157. }
  158. return;
  159. }
  160. /* ---------------------------------------------------------------------
  161. WinMain
  162. Entry point for the application.
  163. It is here that the smart card context is entered and left.
  164. --------------------------------------------------------------------- */
  165. int WINAPI WinMain (
  166. HINSTANCE hInstance,
  167. HINSTANCE hPrevInstance,
  168. LPSTR lpszCmdParam,
  169. int nCmdShow)
  170. {
  171. ghInstance = hInstance;
  172. INITCOMMONCONTROLSEX stICC;
  173. BOOL fICC;
  174. stICC.dwSize = sizeof(INITCOMMONCONTROLSEX);
  175. stICC.dwICC = ICC_WIN95_CLASSES | ICC_STANDARD_CLASSES;
  176. fICC = InitCommonControlsEx(&stICC);
  177. DWORD dwRet = DoAcquireCardContext();
  178. if (0 == dwRet)
  179. {
  180. ShowPropertySheet(NULL);
  181. DoLeaveCardContext();
  182. }
  183. else if (ERROR_REVISION_MISMATCH == dwRet)
  184. {
  185. PresentMessageBox(IDS_BADMODULE, MB_ICONHAND);
  186. }
  187. }