Source code of Windows XP (NT5)
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.

440 lines
12 KiB

  1. #include "precomp.h"
  2. /****************************************************************************
  3. *
  4. * FILE: UPropDlg.cpp
  5. *
  6. * CREATED: Chris Pirich (ChrisPi) 6-18-96
  7. *
  8. * CONTENTS: CUserPropertiesDlg object
  9. *
  10. ****************************************************************************/
  11. #include "resource.h"
  12. #include "UPropDlg.h"
  13. #include "certui.h"
  14. #include "conf.h"
  15. /****************************************************************************
  16. *
  17. * CLASS: CUserPropertiesDlg
  18. *
  19. * MEMBER: CUserPropertiesDlg()
  20. *
  21. * PURPOSE: Constructor - initializes variables
  22. *
  23. ****************************************************************************/
  24. CUserPropertiesDlg::CUserPropertiesDlg( HWND hwndParent,
  25. UINT uIcon):
  26. m_hwndParent (hwndParent),
  27. m_uIcon (uIcon),
  28. m_pCert (NULL)
  29. {
  30. DebugEntry(CUserPropertiesDlg::CUserPropertiesDlg);
  31. m_hIcon = ::LoadIcon( ::GetInstanceHandle(),
  32. MAKEINTRESOURCE(m_uIcon));
  33. DebugExitVOID(CUserPropertiesDlg::CUserPropertiesDlg);
  34. }
  35. /****************************************************************************
  36. *
  37. * CLASS: CUserPropertiesDlg
  38. *
  39. * MEMBER: DoModal()
  40. *
  41. * PURPOSE: Brings up the modal dialog box
  42. *
  43. ****************************************************************************/
  44. INT_PTR CUserPropertiesDlg::DoModal
  45. (
  46. PUPROPDLGENTRY pUPDE,
  47. int nProperties,
  48. LPTSTR pszName,
  49. PCCERT_CONTEXT pCert
  50. )
  51. {
  52. int i;
  53. DBGENTRY(CUserPropertiesDlg::DoModal);
  54. m_pUPDE = pUPDE;
  55. m_nProperties = nProperties;
  56. m_pszName = pszName;
  57. m_pCert = pCert;
  58. PROPSHEETPAGE psp[PSP_MAX];
  59. for (i = 0; i < PSP_MAX; i++)
  60. {
  61. InitStruct(&psp[i]);
  62. }
  63. psp[0].dwFlags = PSP_DEFAULT;
  64. psp[0].hInstance = ::GetInstanceHandle();
  65. psp[0].pszTemplate = MAKEINTRESOURCE(IDD_USER_PROPERTIES);
  66. psp[0].pfnDlgProc = CUserPropertiesDlg::UserPropertiesDlgProc;
  67. psp[0].lParam = (LPARAM) this;
  68. i = 1;
  69. if (pCert)
  70. {
  71. psp[i].dwFlags = PSP_DEFAULT;
  72. psp[i].hInstance = ::GetInstanceHandle();
  73. psp[i].pszTemplate = MAKEINTRESOURCE(IDD_USER_CREDENTIALS);
  74. psp[i].pfnDlgProc = CUserPropertiesDlg::UserCredentialsDlgProc;
  75. psp[i].lParam = (LPARAM) this;
  76. i++;
  77. }
  78. PROPSHEETHEADER psh;
  79. InitStruct(&psh);
  80. psh.dwFlags = PSH_NOAPPLYNOW | PSH_PROPTITLE | PSH_PROPSHEETPAGE;
  81. psh.hwndParent = m_hwndParent;
  82. psh.hInstance = ::GetInstanceHandle();
  83. psh.pszCaption = m_pszName;
  84. psh.nPages = i;
  85. ASSERT(0 == psh.nStartPage);
  86. psh.ppsp = psp;
  87. return ::PropertySheet(&psh);
  88. }
  89. /****************************************************************************
  90. *
  91. * CLASS: CUserPropertiesDlg
  92. *
  93. * MEMBER: UserPropertiesDlgProc()
  94. *
  95. * PURPOSE: Dialog Proc - handles all messages
  96. *
  97. ****************************************************************************/
  98. INT_PTR CALLBACK CUserPropertiesDlg::UserPropertiesDlgProc(HWND hDlg,
  99. UINT uMsg,
  100. WPARAM wParam,
  101. LPARAM lParam)
  102. {
  103. BOOL bMsgHandled = FALSE;
  104. // uMsg may be any value.
  105. // wparam may be any value.
  106. // lparam may be any value.
  107. ASSERT(IS_VALID_HANDLE(hDlg, WND));
  108. switch (uMsg)
  109. {
  110. case WM_INITDIALOG:
  111. {
  112. ASSERT(NULL != lParam);
  113. CUserPropertiesDlg* pupd = (CUserPropertiesDlg*)
  114. ((PROPSHEETPAGE*) lParam)->lParam;
  115. ASSERT(NULL != pupd);
  116. pupd->m_hwnd = hDlg;
  117. bMsgHandled = pupd->OnInitPropertiesDialog();
  118. break;
  119. }
  120. default:
  121. {
  122. #if 0
  123. CUserPropertiesDlg* pupd = (CUserPropertiesDlg*) ::GetWindowLongPtr(
  124. hDlg,
  125. DWLP_USER);
  126. if (NULL != pupd)
  127. {
  128. bMsgHandled = pupd->OnPropertiesMessage(uMsg, wParam, lParam);
  129. }
  130. #endif // 0
  131. }
  132. }
  133. return bMsgHandled;
  134. }
  135. /****************************************************************************
  136. *
  137. * CLASS: CUserPropertiesDlg
  138. *
  139. * MEMBER: UserCredentialsDlgProc()
  140. *
  141. * PURPOSE: Dialog Proc - handles all messages
  142. *
  143. ****************************************************************************/
  144. INT_PTR CALLBACK CUserPropertiesDlg::UserCredentialsDlgProc(HWND hDlg,
  145. UINT uMsg,
  146. WPARAM wParam,
  147. LPARAM lParam)
  148. {
  149. BOOL bMsgHandled = FALSE;
  150. // uMsg may be any value.
  151. // wparam may be any value.
  152. // lparam may be any value.
  153. ASSERT(IS_VALID_HANDLE(hDlg, WND));
  154. switch (uMsg)
  155. {
  156. case WM_INITDIALOG:
  157. {
  158. ASSERT(NULL != lParam);
  159. CUserPropertiesDlg* pupd = (CUserPropertiesDlg*)
  160. ((PROPSHEETPAGE*) lParam)->lParam;
  161. ASSERT(NULL != pupd);
  162. pupd->m_hwnd = hDlg;
  163. ::SetWindowLongPtr(hDlg, DWLP_USER, (DWORD_PTR)pupd);
  164. bMsgHandled = pupd->OnInitCredentialsDialog();
  165. break;
  166. }
  167. default:
  168. {
  169. CUserPropertiesDlg* pupd = (CUserPropertiesDlg*) ::GetWindowLongPtr(
  170. hDlg,
  171. DWLP_USER);
  172. if (NULL != pupd)
  173. {
  174. bMsgHandled = pupd->OnCredentialsMessage(uMsg, wParam, lParam);
  175. }
  176. }
  177. }
  178. return bMsgHandled;
  179. }
  180. /****************************************************************************
  181. *
  182. * CLASS: CUserPropertiesDlg
  183. *
  184. * MEMBER: OnInitPropertiesDialog()
  185. *
  186. * PURPOSE: processes WM_INITDIALOG
  187. *
  188. ****************************************************************************/
  189. BOOL CUserPropertiesDlg::OnInitPropertiesDialog()
  190. {
  191. ASSERT(m_hwnd);
  192. // Set the proper font (for DBCS systems)
  193. ::SendDlgItemMessage(m_hwnd, IDC_UPROP_NAME, WM_SETFONT, (WPARAM) g_hfontDlg, 0);
  194. ::SetDlgItemText(m_hwnd, IDC_UPROP_NAME, m_pszName);
  195. ::SendDlgItemMessage( m_hwnd,
  196. IDC_UPROP_ICON,
  197. STM_SETIMAGE,
  198. IMAGE_ICON,
  199. (LPARAM) m_hIcon);
  200. TCHAR szBuffer[MAX_PATH];
  201. for (int i = 0; i < m_nProperties; i++)
  202. {
  203. // Fill in property:
  204. if (::LoadString( ::GetInstanceHandle(),
  205. m_pUPDE[i].uProperty,
  206. szBuffer,
  207. ARRAY_ELEMENTS(szBuffer)))
  208. {
  209. // NOTE: relies on consecutive control ID's
  210. ::SetDlgItemText(m_hwnd, IDC_UP_PROP1 + i, szBuffer);
  211. }
  212. ::SendDlgItemMessage(m_hwnd, IDC_UP_VALUE1 + i, WM_SETFONT,
  213. (WPARAM) g_hfontDlg, 0);
  214. // Fill in value:
  215. ASSERT(NULL != m_pUPDE[i].pszValue);
  216. if (0 == HIWORD(m_pUPDE[i].pszValue))
  217. {
  218. if (::LoadString( ::GetInstanceHandle(),
  219. PtrToUint(m_pUPDE[i].pszValue),
  220. szBuffer,
  221. ARRAY_ELEMENTS(szBuffer)))
  222. {
  223. // NOTE: relies on consecutive control ID's
  224. ::SetDlgItemText(m_hwnd, IDC_UP_VALUE1 + i, szBuffer);
  225. }
  226. }
  227. else
  228. {
  229. // NOTE: relies on consecutive control ID's
  230. ::SetDlgItemText(m_hwnd, IDC_UP_VALUE1 + i, m_pUPDE[i].pszValue);
  231. }
  232. }
  233. return TRUE;
  234. }
  235. /****************************************************************************
  236. *
  237. * CLASS: CUserPropertiesDlg
  238. *
  239. * MEMBER: OnInitCredentialsDialog()
  240. *
  241. * PURPOSE: processes WM_INITDIALOG
  242. *
  243. ****************************************************************************/
  244. BOOL CUserPropertiesDlg::OnInitCredentialsDialog()
  245. {
  246. ASSERT(m_hwnd);
  247. // Set the proper font (for DBCS systems)
  248. ::SendDlgItemMessage(m_hwnd, IDC_UPROP_NAME, WM_SETFONT, (WPARAM) g_hfontDlg, 0);
  249. ::SetDlgItemText(m_hwnd, IDC_UPROP_NAME, m_pszName);
  250. ::SendDlgItemMessage( m_hwnd,
  251. IDC_UPROP_ICON,
  252. STM_SETIMAGE,
  253. IMAGE_ICON,
  254. (LPARAM) m_hIcon);
  255. ASSERT(m_pCert != NULL);
  256. if ( TCHAR * pSecText = FormatCert ( m_pCert->pbCertEncoded,
  257. m_pCert->cbCertEncoded ))
  258. {
  259. ::SetDlgItemText(m_hwnd, IDC_AUTH_EDIT, pSecText );
  260. delete pSecText;
  261. }
  262. else
  263. {
  264. ERROR_OUT(("OnInitCredentialsDialog: FormatCert failed"));
  265. }
  266. return TRUE;
  267. }
  268. /****************************************************************************
  269. *
  270. * CLASS: CUserPropertiesDlg
  271. *
  272. * MEMBER: OnPropertiesMessage()
  273. *
  274. * PURPOSE: processes all messages except WM_INITDIALOG
  275. *
  276. ****************************************************************************/
  277. BOOL CUserPropertiesDlg::OnPropertiesMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  278. {
  279. BOOL bRet = FALSE;
  280. ASSERT(m_hwnd);
  281. switch (uMsg)
  282. {
  283. case WM_COMMAND:
  284. {
  285. switch (LOWORD(wParam))
  286. {
  287. case IDOK:
  288. {
  289. bRet = OnOk();
  290. break;
  291. }
  292. case IDCANCEL:
  293. {
  294. // ::EndDialog(m_hwnd, LOWORD(wParam));
  295. bRet = TRUE;
  296. break;
  297. }
  298. }
  299. break;
  300. }
  301. default:
  302. break;
  303. }
  304. return bRet;
  305. }
  306. /****************************************************************************
  307. *
  308. * CLASS: CUserPropertiesDlg
  309. *
  310. * MEMBER: OnCredentialsMessage()
  311. *
  312. * PURPOSE: processes all messages except WM_INITDIALOG
  313. *
  314. ****************************************************************************/
  315. BOOL CUserPropertiesDlg::OnCredentialsMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  316. {
  317. BOOL bRet = FALSE;
  318. ASSERT(m_hwnd);
  319. switch (uMsg)
  320. {
  321. case WM_COMMAND:
  322. {
  323. switch (LOWORD(wParam))
  324. {
  325. case IDOK:
  326. {
  327. bRet = OnOk();
  328. break;
  329. }
  330. case IDCANCEL:
  331. {
  332. // ::EndDialog(m_hwnd, LOWORD(wParam));
  333. bRet = TRUE;
  334. break;
  335. }
  336. case IDC_SEC_VIEWCREDS:
  337. {
  338. ViewCertDlg ( m_hwnd, m_pCert );
  339. break;
  340. }
  341. }
  342. break;
  343. }
  344. default:
  345. break;
  346. }
  347. return bRet;
  348. }
  349. /****************************************************************************
  350. *
  351. * CLASS: CUserPropertiesDlg
  352. *
  353. * MEMBER: OnOk()
  354. *
  355. * PURPOSE: processes the WM_COMMAND,IDOK message
  356. *
  357. ****************************************************************************/
  358. BOOL CUserPropertiesDlg::OnOk()
  359. {
  360. DebugEntry(CUserPropertiesDlg::OnOk);
  361. BOOL bRet = TRUE;
  362. DebugExitBOOL(CUserPropertiesDlg::OnOk, bRet);
  363. return bRet;
  364. }
  365.