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.

1026 lines
33 KiB

  1. /*******************************************************************************
  2. * Copyright (C) 1997 Gemplus International All Rights Reserved
  3. *
  4. * Name : GPKGUI.C
  5. *
  6. * Description : GUI used by Cryptographic Service Provider for GPK Card.
  7. *
  8. * Author : Laurent CASSIER
  9. *
  10. * Compiler : Microsoft Visual C 6.0
  11. *
  12. * Host : IBM PC and compatible machines under Windows 32 bit
  13. *
  14. * Release : 2.00.000
  15. *
  16. * Last Modif. :
  17. * 19/11/99: V2.xx.000 - Fixed bug #1797
  18. * 30/07/99: V2.xx.000 - Added function DisplayMessage()
  19. * - Added code to compile with UNICODE
  20. * - Renamed some resources ID, FP
  21. * 20/04/99: V2.00.000 - Merged versions of PKCS#11 and CSP, FJ
  22. * 20/04/99: V1.00.005 - Modification on supporting MBCS, JQ
  23. * 23/03/99: V1.00.004 - Replace KeyLen7 and KeyLen8 with KeyLen[], JQ
  24. * 05/01/98: V1.00.003 - Add Unblock PIN management.
  25. * 02/11/97: V1.00.002 - Separate code from GpkCsp Code.
  26. * 27/08/97: V1.00.001 - Begin implementation based on CSP kit.
  27. *
  28. ********************************************************************************
  29. *
  30. * Warning : This Version use the RsaBase CSP for software cryptography.
  31. *
  32. * Remark :
  33. *
  34. *******************************************************************************/
  35. #ifdef _UNICODE
  36. #define UNICODE
  37. #endif
  38. #include "gpkcsp.h"
  39. #define UM_CHANGE_TEXT WM_USER+1
  40. #include <stdlib.h>
  41. #include <stdio.h>
  42. #include <tchar.h>
  43. #include "../gpkrsrc/resource.h"
  44. #include "gpkgui.h"
  45. /*-----------------------------------------------------------------------------
  46. Global Variable and Declaration for PIN an Progress DialogBox management
  47. ------------------------------------------------------------------------------*/
  48. HINSTANCE g_hInstMod = 0;
  49. HINSTANCE g_hInstRes = 0;
  50. HWND g_hMainWnd = 0;
  51. /* PIN DialogBox */
  52. char szGpkPin[PIN_MAX+2]; // [JMR 02-04]
  53. TCHAR szGpkPinGUI[PIN_MAX+2];
  54. DWORD dwGpkPinLen;
  55. char szGpkNewPin[PIN_MAX+2]; // [JMR 02-04]
  56. TCHAR szGpkNewPinGUI[PIN_MAX+2];
  57. WORD wGpkNewPinLen;
  58. BOOL bChangePin = FALSE;
  59. BOOL NoDisplay = FALSE;
  60. BOOL bNewPin = FALSE;
  61. BOOL bHideChange = FALSE;//TRUE - Don't display change button
  62. BOOL bUnblockPin = FALSE; // Unblock admin pin
  63. BOOL bUser = TRUE; // User pin
  64. // Dialogue Management: share with gpkgui.c !! it was defined in gpkcsp.c
  65. BYTE KeyLenFile[MAX_REAL_KEY] = {64, 128}; // version 2.00.002
  66. BYTE KeyLenChoice;
  67. TCHAR szKeyType[20];
  68. TCHAR s1[MAX_STRING], s2[MAX_STRING], s3[MAX_STRING];
  69. DWORD CspFlags;
  70. DWORD ContainerStatus;
  71. /* ProgressText DialogBox */
  72. TCHAR szProgTitle[MAX_STRING];
  73. TCHAR szProgText[MAX_STRING];
  74. HWND hProgressDlg = NULL;
  75. FARPROC lpProgressDlg = NULL;
  76. HCURSOR hCursor, hCursor2;
  77. /* Progress DialogBox cancel button, PKCS#11 specific */
  78. TCHAR szProgButton[32];
  79. BOOL IsProgButtoned = FALSE;
  80. BOOL IsProgButtonClick = FALSE;
  81. // not used... [FP]
  82. /*static void wait(DWORD TimeOut)
  83. {
  84. DWORD begin, end, now;
  85. begin = GetTickCount();
  86. end = begin + TimeOut;
  87. do
  88. {
  89. now = GetTickCount();
  90. }
  91. while(now < end);
  92. }*/
  93. // This function is used for cosmetic purpose
  94. // It erase text displayed on DialogBox by strink,
  95. // and display new text with "camera" effect
  96. static void set_effect(HWND hDlg,
  97. DWORD Id,
  98. TCHAR *szText
  99. )
  100. {
  101. #ifdef _CAMERA_EFFECT_
  102. TCHAR Buff[256];
  103. TCHAR Text[256];
  104. long i, j;
  105. GetDlgItemText(hDlg, Id, Buff, sizeof(Buff) / sizeof(TCHAR));
  106. j = _tcslen(Buff);
  107. for (i = 0; i < (long)(_tcsclen(Buff)/2); i++)
  108. {
  109. _tcsset(Text, 0x00);
  110. _tcsncpy(Text, _tcsninc(Buff,i), j);
  111. j = j - 2;
  112. SetDlgItemText(hDlg, Id, Text);
  113. // wait(50);
  114. }
  115. _tcscpy(Buff, szText);
  116. _tcscat(Buff, TEXT(" "));
  117. j = 2;
  118. for (i = _tcsclen(Buff)/2; i >= 0; i--)
  119. {
  120. _tcsset(Text, 0x00);
  121. _tcsncpy(Text, _tcsninc(Buff,i), j);
  122. j = j + 2;
  123. SetDlgItemText(hDlg, Id, Text);
  124. // wait(50);
  125. }
  126. #else
  127. SetDlgItemText(hDlg, Id, szText);
  128. #endif
  129. }
  130. /*******************************************************************************
  131. Function to display a message box with a particular text
  132. *******************************************************************************/
  133. void DisplayMessage( LPTSTR szMsg, LPTSTR szCaption, void* pValue)
  134. {
  135. TCHAR szTmp[MAX_STRING];
  136. TCHAR szTmp2[MAX_STRING];
  137. TCHAR szText[MAX_STRING];
  138. LPTSTR szTitle;
  139. if (_tcscmp(TEXT("locked"), szMsg) == 0)
  140. {
  141. LoadString(g_hInstRes, IDS_GPKUI_CARDLOCKED, szText, sizeof(szText)/sizeof(TCHAR));
  142. }
  143. else if (_tcscmp(TEXT("badpin"), szMsg) == 0)
  144. {
  145. LoadString(g_hInstRes, IDS_GPKUI_BADPINCODE, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  146. LoadString(g_hInstRes, IDS_GPKUI_NBRTRYLEFT, szTmp2, sizeof(szTmp2)/sizeof(TCHAR));
  147. _tcscat(szTmp, TEXT("\n"));
  148. _tcscat(szTmp, szTmp2);
  149. _stprintf(szText, szTmp, *(DWORD *)pValue);
  150. }
  151. else
  152. {
  153. }
  154. szTitle = (LPTSTR)szCaption;
  155. MessageBox(NULL, szText, szTitle, MB_OK | MB_ICONEXCLAMATION);
  156. }
  157. #ifdef UNICODE
  158. //return true if all the wide character in szBuff are in the form 0x00XY, where XY
  159. //is an 8 bits ASCII character.
  160. //len is the number of TCHAR to check from szBuff
  161. int IsTextASCII16( const PTCHAR szBuff, unsigned int len )
  162. {
  163. unsigned int i;
  164. for( i = 0; i < len; i++ )
  165. {
  166. if( szBuff[i] & 0xFF00 )
  167. {
  168. return FALSE;
  169. }
  170. }
  171. return TRUE;
  172. }
  173. #endif
  174. /*------------------------------------------------------------------------------
  175. Functions for PIN Dialog Box Management
  176. ------------------------------------------------------------------------------*/
  177. LRESULT WINAPI PinDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  178. {
  179. static TCHAR Buff[PIN_MAX+2]; // [JMR 02-04]
  180. static TCHAR szPinMemo[PIN_MAX+2]; // [JMR 02-04]
  181. static WORD wPinMemoLen;
  182. TCHAR szCaption[MAX_STRING];
  183. #ifdef UNICODE
  184. static TCHAR szPreviousPin[PIN_MAX+2];
  185. static TCHAR szPreviousPin1[PIN_MAX+2];
  186. unsigned int len, CurOffset;
  187. #endif
  188. switch (message)
  189. {
  190. case WM_INITDIALOG:
  191. {
  192. TCHAR szUserPin[MAX_STRING];
  193. TCHAR szSOPin[MAX_STRING];
  194. /* Returns the size in bytes */
  195. LoadString(g_hInstRes, IDS_GPKUI_USERPIN, szUserPin, sizeof(szUserPin) / sizeof(TCHAR));
  196. LoadString(g_hInstRes, IDS_GPKUI_SOPIN, szSOPin, sizeof(szSOPin) / sizeof(TCHAR));
  197. set_effect(hDlg, IDC_PINDLGTXT1, TEXT(""));
  198. LoadString (g_hInstRes, IDS_CAPTION_CHANGEPIN, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  199. SetDlgItemText(hDlg, IDB_CHANGE, szCaption);
  200. LoadString (g_hInstRes, IDS_CAPTION_OK, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  201. SetDlgItemText(hDlg, IDOK, szCaption);
  202. LoadString (g_hInstRes, IDS_CAPTION_CANCEL, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  203. SetDlgItemText(hDlg, IDCANCEL, szCaption);
  204. if (bUser)
  205. {
  206. set_effect(hDlg, IDC_PINDLGTXT, szUserPin);
  207. }
  208. else
  209. {
  210. set_effect(hDlg, IDC_PINDLGTXT, szSOPin);
  211. }
  212. if (bHideChange)
  213. {
  214. ShowWindow(GetDlgItem(hDlg, IDB_CHANGE), FALSE);
  215. }
  216. if (bUnblockPin)
  217. {
  218. ShowWindow(GetDlgItem(hDlg, IDB_CHANGE), FALSE);
  219. if (bNewPin)
  220. {
  221. TCHAR szNewUserPin[256];
  222. TCHAR szNewSOPin[256];
  223. /* Returns the size in bytes */
  224. LoadString(g_hInstRes, IDS_GPKUI_NEWUSERPIN, szNewUserPin, sizeof(szNewUserPin) / sizeof(TCHAR));
  225. LoadString(g_hInstRes, IDS_GPKUI_NEWSOPIN, szNewSOPin, sizeof(szNewSOPin) / sizeof(TCHAR));
  226. ShowWindow(GetDlgItem(hDlg, IDC_PIN1), SW_SHOW);
  227. if (bUser)
  228. {
  229. set_effect(hDlg, IDC_PINDLGTXT, szNewUserPin);
  230. }
  231. else
  232. {
  233. set_effect(hDlg, IDC_PINDLGTXT, szNewSOPin);
  234. }
  235. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  236. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  237. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  238. }
  239. else
  240. {
  241. TCHAR szPinLocked[256];
  242. TCHAR szUnblockCode[256];
  243. /* Returns the size in bytes */
  244. LoadString(g_hInstRes, IDS_GPKUI_PINLOCKED, szPinLocked, sizeof(szPinLocked) / sizeof(TCHAR));
  245. LoadString(g_hInstRes, IDS_GPKUI_UNBLOCKCODE, szUnblockCode, sizeof(szUnblockCode) / sizeof(TCHAR));
  246. set_effect(hDlg, IDC_PINDLGTXT1, szPinLocked);
  247. set_effect(hDlg, IDC_PINDLGTXT, szUnblockCode);
  248. }
  249. }
  250. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  251. return(TRUE);
  252. }
  253. case WM_COMMAND:
  254. {
  255. switch(LOWORD(wParam))
  256. {
  257. case IDC_PIN:
  258. case IDC_PIN1:
  259. {
  260. WORD wPin1, wPin2;
  261. if ( (LOWORD(wParam) == IDC_PIN)
  262. &&(HIWORD(wParam) == EN_SETFOCUS)
  263. &&(bChangePin)
  264. )
  265. {
  266. TCHAR szNewUserPin[MAX_STRING];
  267. TCHAR szNewSOPin[MAX_STRING];
  268. /* Returns the size in bytes */
  269. LoadString(g_hInstRes, IDS_GPKUI_NEWUSERPIN, szNewUserPin, sizeof(szNewUserPin) / sizeof(TCHAR));
  270. LoadString(g_hInstRes, IDS_GPKUI_NEWSOPIN, szNewSOPin, sizeof(szNewSOPin) / sizeof(TCHAR));
  271. if (bUser)
  272. {
  273. set_effect(hDlg, IDC_PINDLGTXT, szNewUserPin);
  274. }
  275. else
  276. {
  277. set_effect(hDlg, IDC_PINDLGTXT, szNewSOPin);
  278. }
  279. // + [FP] In the change password case, the confirmation box must be cleared
  280. //SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  281. // - [FP]
  282. break;
  283. }
  284. if ( (LOWORD(wParam) == IDC_PIN1)
  285. &&(HIWORD(wParam) == EN_SETFOCUS)
  286. )
  287. {
  288. wPin1 = (WORD)GetDlgItemText(hDlg,
  289. IDC_PIN,
  290. Buff,
  291. sizeof(Buff)/sizeof(TCHAR)
  292. );
  293. if (wPin1)
  294. {
  295. TCHAR szConfirmNewUserPin[MAX_STRING];
  296. TCHAR szConfirmNewSOPin[MAX_STRING];
  297. LoadString(g_hInstRes, IDS_GPKUI_CONFIRMNEWUSERPIN, szConfirmNewUserPin, sizeof(szConfirmNewUserPin) / sizeof(TCHAR));
  298. LoadString(g_hInstRes, IDS_GPKUI_CONFIRMNEWSOPIN, szConfirmNewSOPin, sizeof(szConfirmNewSOPin) / sizeof(TCHAR));
  299. if (bUser)
  300. {
  301. set_effect(hDlg, IDC_PINDLGTXT, szConfirmNewUserPin);
  302. }
  303. else
  304. {
  305. set_effect(hDlg, IDC_PINDLGTXT, szConfirmNewSOPin);
  306. }
  307. // + [FP] This box should never be grayed out
  308. // EnableWindow(GetDlgItem(hDlg, IDC_PIN), FALSE);
  309. // - [FP]
  310. }
  311. // [FP] SCR #50 (MS #310718)
  312. //else
  313. //{
  314. // SetFocus(GetDlgItem(hDlg, IDC_PIN));
  315. //}
  316. break;
  317. }
  318. if (HIWORD(wParam) == EN_CHANGE)
  319. {
  320. wPin1 = (WORD)GetDlgItemText(hDlg,
  321. IDC_PIN,
  322. Buff,
  323. sizeof(Buff)/sizeof(TCHAR)
  324. );
  325. #ifdef UNICODE
  326. len = _tcsclen( Buff );
  327. //get the current offset of the cursor in the entry field
  328. SendDlgItemMessage( hDlg, IDC_PIN, EM_GETSEL, (WPARAM) NULL, (WPARAM)(LPDWORD)&CurOffset);
  329. //verify if there is a character that is not an ASCII 16 bits
  330. if( !IsTextASCII16( Buff, len ) )
  331. {
  332. //replace the new PIN in the dlg with the previous
  333. memcpy( Buff, szPreviousPin, sizeof(szPreviousPin) );
  334. MessageBeep( MB_ICONEXCLAMATION );
  335. set_effect( hDlg, IDC_PIN, Buff );
  336. //adjust the offset of the cursor
  337. CurOffset = CurOffset - (len - _tcsclen(szPreviousPin));
  338. SendDlgItemMessage( hDlg, IDC_PIN, EM_SETSEL, CurOffset, CurOffset );
  339. break;
  340. }
  341. else
  342. {
  343. //replace the previous PIN with the new
  344. memcpy( szPreviousPin, Buff, sizeof(Buff) );
  345. }
  346. #endif
  347. if ((bChangePin) || ((bUnblockPin) && (bNewPin)))
  348. {
  349. wPin2 = (WORD)GetDlgItemText(hDlg,
  350. IDC_PIN1,
  351. Buff,
  352. sizeof(Buff)/sizeof(TCHAR)
  353. );
  354. #ifdef UNICODE
  355. //verify if Buff contains a UNICODE character
  356. len = _tcsclen( Buff );
  357. //get the current offset of the cursor in the entry field
  358. SendDlgItemMessage( hDlg, IDC_PIN1, EM_GETSEL, (WPARAM) NULL, (WPARAM)(LPDWORD)&CurOffset);
  359. if( !IsTextASCII16( Buff, len ) )
  360. {
  361. //replace the new PIN in the dlg with the previous
  362. memcpy( Buff, szPreviousPin1, sizeof(szPreviousPin1) );
  363. MessageBeep( MB_ICONEXCLAMATION );
  364. set_effect( hDlg, IDC_PIN1, Buff );
  365. //adjust the offset of the cursor
  366. CurOffset = CurOffset - (len - _tcsclen(szPreviousPin1));
  367. SendDlgItemMessage( hDlg, IDC_PIN1, EM_SETSEL, CurOffset, CurOffset );
  368. break;
  369. }
  370. else
  371. {
  372. //replace the previous PIN with the new
  373. memcpy( szPreviousPin1, Buff, sizeof(Buff) );
  374. }
  375. #endif
  376. }
  377. else
  378. {
  379. wPin2 = 4;
  380. }
  381. if ((wPin1 >= 4) && (wPin2 >= 4) && (wPin1 <= 8) && (wPin2 <= 8))
  382. {
  383. EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
  384. EnableWindow(GetDlgItem(hDlg, IDB_CHANGE), TRUE);
  385. }
  386. else
  387. {
  388. EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
  389. EnableWindow(GetDlgItem(hDlg, IDB_CHANGE), FALSE);
  390. }
  391. }
  392. break;
  393. }
  394. case IDB_CHANGE:
  395. {
  396. TCHAR szNewUserPin[256];
  397. TCHAR szNewSOPin[256];
  398. /* Returns the size in bytes */
  399. LoadString(g_hInstRes, IDS_GPKUI_NEWUSERPIN, szNewUserPin, sizeof(szNewUserPin) / sizeof(TCHAR));
  400. LoadString(g_hInstRes, IDS_GPKUI_NEWSOPIN, szNewSOPin, sizeof(szNewSOPin) / sizeof(TCHAR));
  401. ShowWindow(GetDlgItem(hDlg, IDB_CHANGE), SW_HIDE);
  402. dwGpkPinLen = (DWORD)GetDlgItemText(hDlg, IDC_PIN, szGpkPinGUI, PIN_MAX+1);
  403. #ifdef UNICODE
  404. wcstombs(szGpkPin, szGpkPinGUI, dwGpkPinLen);
  405. #else
  406. strcpy(szGpkPin, szGpkPinGUI);
  407. #endif
  408. bChangePin = TRUE;
  409. ShowWindow(GetDlgItem(hDlg, IDC_PIN1), SW_SHOW);
  410. if (bUser)
  411. {
  412. set_effect(hDlg, IDC_PINDLGTXT, szNewUserPin);
  413. }
  414. else
  415. {
  416. set_effect(hDlg, IDC_PINDLGTXT, szNewSOPin);
  417. }
  418. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  419. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  420. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  421. return(TRUE);
  422. }
  423. case IDOK:
  424. {
  425. if ((bChangePin) || ((bUnblockPin) && (bNewPin)))
  426. {
  427. TCHAR szWrongConfirm[MAX_STRING];
  428. TCHAR szChangePin[MAX_STRING];
  429. wPinMemoLen = (WORD)GetDlgItemText(hDlg, IDC_PIN, szPinMemo, PIN_MAX+1);
  430. wGpkNewPinLen = (WORD)GetDlgItemText(hDlg, IDC_PIN1, szGpkNewPinGUI, PIN_MAX+1);
  431. #ifdef UNICODE
  432. wcstombs(szGpkNewPin, szGpkNewPinGUI, wGpkNewPinLen);
  433. #else
  434. strcpy(szGpkNewPin, szGpkNewPinGUI);
  435. #endif
  436. if ( (wPinMemoLen != wGpkNewPinLen)
  437. ||(_tcscmp(szPinMemo, szGpkNewPinGUI))
  438. )
  439. {
  440. /* Returns the size in bytes */
  441. LoadString(g_hInstRes, IDS_GPKUI_WRONGCONFIRM, szWrongConfirm, sizeof(szWrongConfirm) / sizeof(TCHAR));
  442. LoadString(g_hInstRes, IDS_GPKUI_CHANGEPIN, szChangePin, sizeof(szChangePin) / sizeof(TCHAR));
  443. MessageBeep(MB_ICONASTERISK);
  444. MessageBox(hDlg,
  445. szWrongConfirm,
  446. szChangePin,
  447. MB_OK | MB_ICONEXCLAMATION
  448. );
  449. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  450. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  451. // EnableWindow(GetDlgItem(hDlg, IDC_PIN), TRUE);
  452. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  453. break;
  454. }
  455. // [JMR 02-04] begin
  456. else
  457. {
  458. TCHAR szPinWrongLength[MAX_STRING];
  459. TCHAR szChangePin[MAX_STRING];
  460. TCHAR szText[50];
  461. if ((wPinMemoLen > PIN_MAX) || (wPinMemoLen < PIN_MIN))
  462. {
  463. LoadString (g_hInstRes, IDS_GPKUI_PINWRONGLENGTH, szPinWrongLength, sizeof(szPinWrongLength) / sizeof(TCHAR));
  464. _stprintf(szText, szPinWrongLength, PIN_MIN, PIN_MAX);
  465. LoadString (g_hInstRes, IDS_GPKUI_CHANGEPIN, szChangePin, sizeof(szChangePin) / sizeof(TCHAR));
  466. MessageBeep(MB_ICONASTERISK);
  467. MessageBox(hDlg,
  468. szText,
  469. szChangePin,
  470. MB_OK | MB_ICONEXCLAMATION
  471. );
  472. SetDlgItemText(hDlg, IDC_PIN, TEXT(""));
  473. SetDlgItemText(hDlg, IDC_PIN1, TEXT(""));
  474. // EnableWindow(GetDlgItem(hDlg, IDC_PIN), TRUE);
  475. SetFocus(GetDlgItem(hDlg, IDC_PIN));
  476. break;
  477. }
  478. }
  479. }
  480. // [JMR 02-04] end
  481. else
  482. {
  483. dwGpkPinLen = (DWORD)GetDlgItemText(hDlg, IDC_PIN, szGpkPinGUI, PIN_MAX+1);
  484. #ifdef UNICODE
  485. wcstombs(szGpkPin, szGpkPinGUI, dwGpkPinLen);
  486. #else
  487. strcpy(szGpkPin, szGpkPinGUI);
  488. #endif
  489. }
  490. EndDialog(hDlg, wParam);
  491. return(TRUE);
  492. }
  493. case IDCANCEL:
  494. {
  495. strcpy(szGpkPin, "");
  496. dwGpkPinLen = 0;
  497. strcpy(szGpkNewPin, "");
  498. wGpkNewPinLen = 0;
  499. bChangePin = FALSE;
  500. MessageBeep(MB_ICONASTERISK);
  501. EndDialog(hDlg, wParam);
  502. return(TRUE);
  503. }
  504. }
  505. }
  506. case WM_DESTROY:
  507. {
  508. break;
  509. }
  510. }
  511. return(FALSE);
  512. }
  513. /*------------------------------------------------------------------------------
  514. Functions for Container Dialogue Management
  515. ------------------------------------------------------------------------------*/
  516. LRESULT WINAPI ContDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  517. {
  518. TCHAR szContinue[MAX_STRING];
  519. TCHAR szCaption[MAX_STRING];
  520. switch (message)
  521. {
  522. case WM_INITDIALOG:
  523. {
  524. LoadString (g_hInstRes, IDS_GPKUI_CONTINUE, szContinue, sizeof(szContinue)/sizeof(TCHAR));
  525. SetDlgItemText(hDlg, IDC_CONTDLGTXT, szContinue);
  526. LoadString (g_hInstRes, IDS_CAPTION_YES, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  527. SetDlgItemText(hDlg, IDYES, szCaption);
  528. LoadString (g_hInstRes, IDS_CAPTION_NO, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  529. SetDlgItemText(hDlg, IDNO, szCaption);
  530. SetFocus(GetDlgItem(hDlg, IDNO));
  531. return(TRUE);
  532. }
  533. case WM_COMMAND:
  534. {
  535. switch(LOWORD(wParam))
  536. {
  537. case IDYES:
  538. {
  539. ContainerStatus = ACCEPT_CONTAINER;
  540. EndDialog(hDlg, wParam);
  541. return(TRUE);
  542. }
  543. case IDNO:
  544. {
  545. ContainerStatus = ABORT_OPERATION;
  546. EndDialog(hDlg, wParam);
  547. return(TRUE);
  548. }
  549. }
  550. }
  551. case WM_DESTROY:
  552. {
  553. break;
  554. }
  555. }
  556. return(FALSE);
  557. }
  558. /*------------------------------------------------------------------------------
  559. Functions for Container Dialogue Management
  560. ------------------------------------------------------------------------------*/
  561. LRESULT WINAPI KeyDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  562. {
  563. TCHAR StrLen07[10];
  564. TCHAR StrLen08[10];
  565. TCHAR szMsg[300];
  566. TCHAR szChooseLength[MAX_STRING];
  567. TCHAR szCaption[MAX_STRING];
  568. switch (message)
  569. {
  570. case WM_INITDIALOG:
  571. {
  572. LoadString (g_hInstRes, IDS_GPKUI_CHOOSEKEYLENGTH, szChooseLength, sizeof(szChooseLength)/sizeof(TCHAR));
  573. _tcscpy(szMsg, szChooseLength);
  574. _tcscat(szMsg, szKeyType);
  575. // TT 12/10/99: If we get here, it means that we have 512 and 1024 bits
  576. // keys available. Don't use the length of the first two key files!
  577. //_stprintf(StrLen07, TEXT("%4d"), KeyLenFile[0]*8);
  578. //_stprintf(StrLen08, TEXT("%4d"), KeyLenFile[1]*8);
  579. _stprintf(StrLen07, TEXT("%4d"), 1024 );
  580. _stprintf(StrLen08, TEXT("%4d"), 512 );
  581. // TT: End
  582. // FP 05/11/99: Write text in the caption of the radio button
  583. //SetDlgItemText(hDlg, IDC_KEYLENGTH, StrLen07);
  584. //SetDlgItemText(hDlg, IDC_KEYLENGTH1, StrLen08);
  585. SetWindowText(GetDlgItem(hDlg, IDB_KEYLENGTH), StrLen07);
  586. SetWindowText(GetDlgItem(hDlg, IDB_KEYLENGTH1), StrLen08);
  587. // FP: End
  588. SetDlgItemText(hDlg, IDC_KEYDLGTXT, szMsg);
  589. KeyLenChoice = 1024/8;//KeyLenFile[0];
  590. CheckDlgButton(hDlg, IDB_KEYLENGTH, BST_CHECKED);
  591. LoadString (g_hInstRes, IDS_CAPTION_OK, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  592. SetDlgItemText(hDlg, IDOK, szCaption);
  593. LoadString (g_hInstRes, IDS_CAPTION_ABORT, szCaption, sizeof(szCaption)/sizeof(TCHAR));
  594. SetDlgItemText(hDlg, IDABORT, szCaption);
  595. SetFocus(GetDlgItem(hDlg, IDOK));
  596. return(TRUE);
  597. }
  598. case WM_COMMAND:
  599. {
  600. switch(LOWORD(wParam))
  601. {
  602. case IDB_KEYLENGTH:
  603. {
  604. ShowWindow(GetDlgItem(hDlg, IDB_KEYLENGTH), SW_SHOW);
  605. KeyLenChoice = 1024/8;//TT 12/10/99 KeyLenFile[0];
  606. break;
  607. }
  608. case IDB_KEYLENGTH1:
  609. {
  610. ShowWindow(GetDlgItem(hDlg, IDB_KEYLENGTH1), SW_SHOW);
  611. KeyLenChoice = 512/8;//KeyLenFile[1];
  612. break;
  613. }
  614. case IDOK:
  615. {
  616. EndDialog(hDlg, wParam);
  617. return(TRUE);
  618. }
  619. case IDABORT:
  620. {
  621. KeyLenChoice = 0;
  622. EndDialog(hDlg, wParam);
  623. return(TRUE);
  624. }
  625. }
  626. }
  627. case WM_DESTROY:
  628. {
  629. break;
  630. }
  631. }
  632. return(FALSE);
  633. }
  634. /*------------------------------------------------------------------------------
  635. Functions for Progress Dialog Box Management
  636. ------------------------------------------------------------------------------*/
  637. /*******************************************************************************
  638. * void Wait (DWORD ulStep,
  639. * DWORD ulMaxStep,
  640. * DWORD ulSecond)
  641. *
  642. * Description : Change Progress Box Text.
  643. *
  644. * Remarks : Nothing.
  645. *
  646. * In : ulStep = Current step number.
  647. * ulMaxStep = Maximum step number.
  648. * ulSecond =
  649. *
  650. * Out : Nothing.
  651. *
  652. * Response : Nothing.
  653. *
  654. *******************************************************************************/
  655. void Wait(DWORD ulStep, DWORD ulMaxStep, DWORD ulSecond)
  656. {
  657. ULONG ulStart, ulEnd, ulBase, ulCur;
  658. TCHAR szTitle[MAX_STRING];
  659. TCHAR szText[MAX_STRING];
  660. TCHAR szTmp[MAX_STRING];
  661. LoadString(g_hInstRes, IDS_GPK4K_KEYGEN, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  662. _stprintf(szTitle, szTmp, ulStep, ulMaxStep);
  663. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTITLE, szText, sizeof(szText)/sizeof(TCHAR));
  664. ShowProgress(NULL, szTitle, szText, NULL);
  665. #ifdef _TEST
  666. Sleep(1000); // Allow the tester to see the text displayed in the dialog box
  667. #endif
  668. ulStart = GetTickCount();
  669. ulEnd = ulStart + (ulSecond * 1000);
  670. ulBase = ulSecond * 10;
  671. ulCur = 0;
  672. while (GetTickCount() < ulEnd)
  673. {
  674. Yield();
  675. if (((GetTickCount() - ulStart) / ulBase) > ulCur)
  676. {
  677. ulCur++;
  678. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSPERCENT, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  679. _stprintf(szText, szTmp, ulCur, (ulEnd-GetTickCount())/1000);
  680. ChangeProgressText(szText);
  681. }
  682. }
  683. DestroyProgress();
  684. }
  685. /*******************************************************************************/
  686. void ShowProgressWrapper(WORD wKeySize)
  687. {
  688. TCHAR szTmp[MAX_STRING];
  689. TCHAR szTitle[MAX_STRING];
  690. TCHAR szText[MAX_STRING];
  691. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTEXT, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  692. _stprintf(szTitle, szTmp, wKeySize);
  693. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTITLE, szText, sizeof(szText)/sizeof(TCHAR));
  694. ShowProgress(GetActiveWindow(), szTitle, szText, NULL);
  695. }
  696. /*******************************************************************************/
  697. void ChangeProgressWrapper(DWORD dwTime)
  698. {
  699. TCHAR szTmp[MAX_STRING];
  700. TCHAR szText[MAX_STRING];
  701. LoadString(g_hInstRes, IDS_GPK4K_PROGRESSTIME, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  702. _stprintf(szText, szTmp, dwTime);
  703. ChangeProgressText(szText);
  704. }
  705. /*******************************************************************************
  706. * void ShowProgress (HWND hWnd,
  707. * LPTSTR lpstrTitle,
  708. * LPTSTR lpstrText,
  709. * LPTSTR lpstrButton
  710. *
  711. * Description : Initialize Progress dialog box CALLBACK.
  712. *
  713. * Remarks : If lpstrButton is null, then don't display cancel button
  714. *
  715. * In : hWnd = Handle of parent window.
  716. * lpstrTitle = Pointer to Title of dialog box.
  717. * lpstrText = Pointer to Text of dialog box.
  718. * lpstrButton = Pointer to Text of button.
  719. *
  720. * Out : Nothing.
  721. *
  722. * Response : Nothing.
  723. *
  724. *******************************************************************************/
  725. void ShowProgress (HWND hWnd,
  726. LPTSTR lpstrTitle,
  727. LPTSTR lpstrText,
  728. LPTSTR lpstrButton
  729. )
  730. {
  731. if (!(CspFlags & CRYPT_SILENT))
  732. {
  733. if ((!hProgressDlg) && (!NoDisplay))
  734. {
  735. _tcscpy(szProgTitle, lpstrTitle);
  736. _tcscpy(szProgText, lpstrText);
  737. _tcscpy(szProgButton, TEXT(""));
  738. if (lpstrButton == NULL)
  739. {
  740. IsProgButtoned = FALSE;
  741. IsProgButtonClick = FALSE;
  742. lpProgressDlg = MakeProcInstance((FARPROC)ProgressDlgProc, g_hInstRes);
  743. hProgressDlg = CreateDialog(g_hInstRes,
  744. TEXT("PROGDIALOG"),
  745. GetActiveWindow(),
  746. (DLGPROC)lpProgressDlg
  747. );
  748. hCursor=SetCursor(LoadCursor(NULL,IDC_WAIT));
  749. }
  750. else
  751. {
  752. IsProgButtoned = TRUE;
  753. IsProgButtonClick = FALSE;
  754. _tcscpy(szProgButton, lpstrButton);
  755. DialogBox(g_hInstRes,
  756. TEXT("PROGDIALOG"),
  757. GetActiveWindow(),
  758. (DLGPROC)ProgressDlgProc
  759. );
  760. hProgressDlg = NULL;
  761. }
  762. }
  763. }
  764. }
  765. /*******************************************************************************
  766. * void ChangeProgressText (LPTSTR lpstrText)
  767. *
  768. * Description : Change Progress Box Text.
  769. *
  770. * Remarks : Nothing.
  771. *
  772. * In : lpstrText = Pointer to Text of dialog box.
  773. *
  774. * Out : Nothing.
  775. *
  776. * Response : Nothing.
  777. *
  778. *******************************************************************************/
  779. void ChangeProgressText (LPTSTR lpstrText)
  780. {
  781. if (hProgressDlg)
  782. {
  783. _tcscpy(szProgText, lpstrText);
  784. SendMessage(hProgressDlg,UM_CHANGE_TEXT,(WPARAM)NULL,(LPARAM)NULL);
  785. }
  786. }
  787. /*******************************************************************************
  788. * void DestroyProgress (void)
  789. *
  790. * Description : Destroy Progress dialog box CALLBACK.
  791. *
  792. * Remarks : Nothing.
  793. *
  794. * In : Nothing.
  795. *
  796. * Out : Nothing.
  797. *
  798. * Response : Nothing.
  799. *
  800. *******************************************************************************/
  801. void DestroyProgress (void)
  802. {
  803. if (!(CspFlags & CRYPT_SILENT))
  804. {
  805. if ((hProgressDlg) && (!NoDisplay))
  806. {
  807. DestroyWindow(hProgressDlg);
  808. FreeProcInstance(lpProgressDlg);
  809. hProgressDlg = NULL;
  810. SetCursor(hCursor);
  811. }
  812. }
  813. }
  814. /*******************************************************************************
  815. * BOOL EXPORT CALLBACK ProgressDlgProc(HWND hDlg,
  816. * UINT message,
  817. * WPARAM wParam,
  818. * LPARAM lParam
  819. * )
  820. *
  821. * Description : CALLBACK for management of Progess Dialog Box.
  822. *
  823. * Remarks : Nothing.
  824. *
  825. * In : hDlg = Window handle.
  826. * message = Type of message.
  827. * wParam = Word message-specific information.
  828. * lParam = Long message-specific information.
  829. *
  830. * Out : Nothing.
  831. *
  832. * Responses : If everything is OK :
  833. * G_OK
  834. * If an condition error is raised:
  835. *
  836. *******************************************************************************/
  837. BOOL CALLBACK ProgressDlgProc(HWND hDlg,
  838. UINT message,
  839. WPARAM wParam,
  840. LPARAM lParam
  841. )
  842. {
  843. #ifdef _DISPLAY
  844. switch (message)
  845. {
  846. /* Initialize Dialog box */
  847. case WM_INITDIALOG:
  848. {
  849. SetWindowText(hDlg,(LPTSTR)szProgTitle);
  850. SetDlgItemText(hDlg,IDC_PROGDLGTXT,(LPCTSTR)szProgText);
  851. if (IsProgButtoned)
  852. {
  853. hProgressDlg = hDlg;
  854. ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW);
  855. SetWindowText(GetDlgItem(hDlg, IDCANCEL),(LPTSTR)szProgButton);
  856. }
  857. else
  858. {
  859. ShowWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
  860. }
  861. }
  862. return(TRUE);
  863. break;
  864. case UM_CHANGE_TEXT:
  865. {
  866. SetDlgItemText(hDlg,IDC_PROGDLGTXT,(LPTSTR)szProgText);
  867. }
  868. break;
  869. case WM_COMMAND:
  870. {
  871. switch(LOWORD(wParam))
  872. {
  873. case IDCANCEL:
  874. {
  875. IsProgButtonClick = TRUE;
  876. EndDialog(hDlg, wParam);
  877. return(TRUE);
  878. }
  879. }
  880. }
  881. break;
  882. default:
  883. return(FALSE);
  884. }
  885. #endif
  886. return (FALSE);
  887. }
  888. /*******************************************************************************
  889. Functions to set/unset cursor in wait mode
  890. *******************************************************************************/
  891. void BeginWait(void)
  892. {
  893. hCursor2=SetCursor(LoadCursor(NULL,IDC_WAIT));
  894. }
  895. void EndWait(void)
  896. {
  897. SetCursor(hCursor2);
  898. }