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.

217 lines
9.2 KiB

  1. /*
  2. SHEET1.CPP
  3. Implements the property sheet page's behaviors.
  4. */
  5. #include <nt.h>
  6. #include <ntrtl.h>
  7. #include <nturtl.h>
  8. #include <windows.h>
  9. #include <commdlg.h>
  10. #include <commctrl.h>
  11. #include <ole2.h>
  12. #include <stdio.h>
  13. #include "support.h"
  14. #include "helpers.h"
  15. #include "res.h"
  16. #include "utils.h"
  17. extern BOOL fUnblockActive;
  18. extern INT iCurrent;
  19. extern HINSTANCE ghInstance;
  20. extern HWND hwndContainer;
  21. void HelpHandler(LPARAM lp);
  22. /* ---------------------------------------------------------------------
  23. PageProc1
  24. Page procedure for the first page, the PIN change page.
  25. --------------------------------------------------------------------- */
  26. INT_PTR CALLBACK PageProc1(
  27. HWND hwnd,
  28. UINT msg,
  29. WPARAM wparam,
  30. LPARAM lparam)
  31. {
  32. INT_PTR ret;
  33. HWND hwndCred = NULL;
  34. BOOL gfSuccess = FALSE;
  35. switch (msg)
  36. {
  37. case WM_HELP:
  38. {
  39. HelpHandler(lparam);
  40. break;
  41. };
  42. case WM_NOTIFY:
  43. {
  44. NMHDR *pHdr = (NMHDR *)lparam;
  45. switch (pHdr->code)
  46. {
  47. case PSN_SETACTIVE:
  48. // A good place to capture the hwnd of the enclosing property sheet
  49. iCurrent = 1;
  50. if (NULL == hwndContainer)
  51. {
  52. hwndContainer = pHdr->hwndFrom;
  53. ASSERT(hwndContainer);
  54. }
  55. if (fUnblockActive)
  56. {
  57. // If sheet 2 still active force the UI back there.
  58. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,IDD_PAGE2);
  59. return TRUE;
  60. }
  61. // return 0 to permit activation to proceed on this page.
  62. return 0;
  63. break;
  64. case PSN_KILLACTIVE:
  65. //User hit OK, or switched to another page
  66. //do validation, return FALSE if ok to lose focus, else TRUE
  67. return FALSE;
  68. break;
  69. case PSN_QUERYCANCEL:
  70. // Return TRUE to prevent cancel, FALSE to allow it.
  71. return FALSE;
  72. case PSN_APPLY:
  73. // Only process an apply for this page if it is the active page
  74. // Only process an apply for this page if sheet 2 is active
  75. // This will entail getting the two copies of the PIN, making sure they are
  76. // identical, and
  77. if (iCurrent != 1)
  78. {
  79. // If the user was looking at the other sheet when he hit OK, do
  80. // nothing with the page.
  81. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,PSNRET_NOERROR);
  82. return TRUE;
  83. }
  84. // buffers for old pin and 2 copies of new pin
  85. WCHAR szOld[100];
  86. WCHAR sz[100];
  87. WCHAR sz2[100];
  88. // SetWindowLong(DWL_MSGRESULT = PSNRET_INVALID if unable
  89. // PSN_INVALID_NOCHANGEPAGE looks the same
  90. // PSNRET_NOERROR - OK, page can be destroyed if OK
  91. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,PSNRET_NOERROR);
  92. GetWindowText(GetDlgItem(hwnd,IDC_OLDPIN),szOld,100);
  93. GetWindowText(GetDlgItem(hwnd,IDC_NEWPIN1),sz,100);
  94. GetWindowText(GetDlgItem(hwnd,IDC_NEWPIN2),sz2,100);
  95. // Do not process pin change unless the two copies entered by the user were the same
  96. if (0 != wcscmp(sz,sz2))
  97. {
  98. PresentModalMessageBox(hwnd, IDS_NOTSAME,MB_ICONHAND);
  99. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,PSNRET_INVALID);
  100. return TRUE;
  101. }
  102. else
  103. {
  104. // Do not process an attempt to change the pin to a blank pin
  105. if (wcslen(sz) == 0)
  106. {
  107. PresentModalMessageBox(hwnd, IDS_BADPIN,MB_ICONHAND);
  108. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,PSNRET_INVALID);
  109. return TRUE;
  110. }
  111. DWORD dwRet = DoChangePin(szOld,sz);
  112. if (0 == dwRet)
  113. {
  114. PresentModalMessageBox(hwnd,IDS_PINCHANGEOK,MB_OK);
  115. }
  116. else
  117. {
  118. switch(dwRet)
  119. {
  120. case SCARD_F_INTERNAL_ERROR:
  121. PresentModalMessageBox(hwnd, IDS_INTERROR ,MB_ICONHAND);
  122. break;
  123. case SCARD_E_CANCELLED:
  124. PresentModalMessageBox(hwnd, IDS_CANCELLED,MB_ICONHAND);
  125. break;
  126. case SCARD_E_NO_SERVICE:
  127. PresentModalMessageBox(hwnd, IDS_NOSERVICE,MB_ICONHAND);
  128. break;
  129. case SCARD_E_SERVICE_STOPPED:
  130. PresentModalMessageBox(hwnd, IDS_STOPPED,MB_ICONHAND);
  131. break;
  132. case SCARD_E_UNSUPPORTED_FEATURE:
  133. PresentModalMessageBox(hwnd, IDS_UNSUPPORTED,MB_ICONHAND);
  134. break;
  135. case SCARD_E_FILE_NOT_FOUND:
  136. PresentModalMessageBox(hwnd, IDS_NOTFOUND,MB_ICONHAND);
  137. break;
  138. case SCARD_E_WRITE_TOO_MANY:
  139. PresentModalMessageBox(hwnd, IDS_TOOMANY,MB_ICONHAND);
  140. break;
  141. case SCARD_E_INVALID_CHV:
  142. // !!! Note the mapping of invalid to wrong.
  143. // consult public\sdk\inc\scarderr.h @ 562
  144. PresentModalMessageBox(hwnd, IDS_WRONGCHV,MB_ICONHAND);
  145. break;
  146. case SCARD_W_UNSUPPORTED_CARD:
  147. PresentModalMessageBox(hwnd, IDS_UNSUPPORTED,MB_ICONHAND);
  148. break;
  149. case SCARD_W_UNRESPONSIVE_CARD:
  150. PresentModalMessageBox(hwnd, IDS_UNRESP ,MB_ICONHAND);
  151. break;
  152. case SCARD_W_REMOVED_CARD:
  153. PresentModalMessageBox(hwnd, IDS_REMOVED ,MB_ICONHAND);
  154. break;
  155. case SCARD_W_WRONG_CHV:
  156. PresentModalMessageBox(hwnd, IDS_WRONGCHV,MB_ICONHAND);
  157. break;
  158. case SCARD_W_CHV_BLOCKED:
  159. PresentModalMessageBox(hwnd, IDS_BLOCKEDCHV,MB_ICONHAND);
  160. break;
  161. default:
  162. PresentModalMessageBox(hwnd, IDS_PINCHANGEFAIL,MB_ICONHAND);
  163. break;
  164. }
  165. SetWindowLongPtr(hwnd,DWLP_MSGRESULT,PSNRET_INVALID);
  166. return TRUE;
  167. }
  168. }
  169. }
  170. return TRUE;
  171. }
  172. break;
  173. case WM_COMMAND:
  174. // Button clicks.
  175. switch(LOWORD(wparam))
  176. {
  177. case IDBUTTON1:
  178. if (HIWORD(wparam) == BN_CLICKED)
  179. {
  180. SendMessage(hwndContainer,PSM_CHANGED,(WPARAM)hwnd,(LPARAM)0);
  181. }
  182. break;
  183. default:
  184. break;
  185. }
  186. break;
  187. default:
  188. break;
  189. }
  190. return FALSE;
  191. }