CaCertInfoPage.cpp
上传用户:dengkfang
上传日期:2008-12-30
资源大小:5233k
文件大小:20k
源码类别:

CA认证

开发平台:

Visual C++

  1. // CaCertInfoPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "minica.h"
  5. #include "CaCertInfoPage.h"
  6. #include "MiniMainDlg.h"
  7. #include ".GenericClassLanguage.h"
  8. #include "minict.h"
  9. #define _WIN32_WINNT  0x0400
  10. #include "WinCrypt.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CCaCertInfoPage property page
  18. IMPLEMENT_DYNCREATE(CCaCertInfoPage, CPropertyPage)
  19. CCaCertInfoPage::CCaCertInfoPage() : CPropertyPage(CCaCertInfoPage::IDD)
  20. {
  21. //{{AFX_DATA_INIT(CCaCertInfoPage)
  22. m_RadioDisk = 0;
  23. m_Day = 0;
  24. m_Pwd = _T("");
  25. //}}AFX_DATA_INIT
  26. m_IniPathName = ((CMiniCaApp *)AfxGetApp())->GetAppPath() +  "\MiniCA.ini";
  27. m_CertFormat = DER;
  28. }
  29. CCaCertInfoPage::~CCaCertInfoPage()
  30. {
  31. //清除链表内容
  32. m_ArrayInside.RemoveAll();
  33. }
  34. void CCaCertInfoPage::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPage::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CCaCertInfoPage)
  38. // DDX_Control(pDX, IDC_EDIT_CONT, m_XpEditCont);
  39. DDX_Control(pDX, IDC_LIST, m_CheckList);
  40. // DDX_Control(pDX, IDC_EDIT_PWD, m_XpEditReq);
  41. // DDX_Control(pDX, IDC_EDIT_PATH, m_XpEdit);
  42. // DDX_Control(pDX, IDC_EDIT_DAY, m_XpEditDay);
  43. DDX_Control(pDX, IDC_COMBO_CSP, m_CspBox);
  44. DDX_Radio(pDX, IDC_RADIO_DISK, m_RadioDisk);
  45. DDX_Text(pDX, IDC_EDIT_DAY, m_Day);
  46. DDV_MinMaxUInt(pDX, m_Day, 1, 3650);
  47. DDX_Text(pDX, IDC_EDIT_PWD, m_Pwd);
  48. DDV_MaxChars(pDX, m_Pwd, 8);
  49. //}}AFX_DATA_MAP
  50.     DDX_FileEditCtrl(pDX, IDC_EDIT_PATH, m_XpEdit, FEC_FOLDER);
  51. }
  52. BEGIN_MESSAGE_MAP(CCaCertInfoPage, CPropertyPage)
  53. //{{AFX_MSG_MAP(CCaCertInfoPage)
  54. ON_BN_CLICKED(IDC_R_CSP, OnRCsp)
  55. ON_BN_CLICKED(IDC_RADIO_DISK, OnRadioDisk)
  56. ON_BN_CLICKED(IDC_CAINFO_RADIODER, OnCainfoRadioder)
  57. ON_BN_CLICKED(IDC_CAINFO_RADIOPEM, OnCainfoRadiopem)
  58. //}}AFX_MSG_MAP
  59. ON_NOTIFY_EX(TTN_NEEDTEXT, 0, OnToolTipNotify)
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CCaCertInfoPage message handlers
  63. BOOL CCaCertInfoPage::OnToolTipNotify( UINT id, NMHDR * pTTTStruct, LRESULT * pResult )
  64. {
  65. TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;    
  66.     UINT nID = pTTTStruct->idFrom;
  67. BOOL bRadioDisk = ((CButton * )GetDlgItem(IDC_RADIO_DISK))->GetCheck();
  68. BOOL bRadioCsp = ((CButton * )GetDlgItem(IDC_R_CSP))->GetCheck();
  69. BOOL bPkcs12 = ((CButton * )GetDlgItem(IDC_STATIC_CAINFO21))->GetCheck();
  70. BOOL bDer = ((CButton * )GetDlgItem(IDC_CAINFO_RADIODER))->GetCheck();
  71. CString strPwd(""),strText;
  72. GetDlgItemText(IDC_EDIT_PWD, strPwd);
  73. switch(nID)
  74. {
  75. case IDC_EDIT_PATH:
  76. if(bRadioDisk)
  77. {
  78. strText = CMiniCaApp::NormalCode("证书存储路径");
  79. }
  80. else
  81. {
  82. strText = "";
  83. }
  84. _tcscpy(pTTT->szText, strText);//设置
  85. return TRUE;
  86. case IDC_COMBO_CSP:
  87. if(bRadioCsp)
  88. {
  89. strText = CMiniCaApp::NormalCode("CSP名称");
  90. }
  91. else
  92. {
  93. strText = "";
  94. }
  95. _tcscpy(pTTT->szText,strText);//设置
  96. return TRUE;
  97. case IDC_EDIT_CONT:
  98. if(bRadioCsp)
  99. {
  100. strText = CMiniCaApp::NormalCode("密钥容器名称");
  101. }
  102. else
  103. {
  104. strText = "";
  105. }
  106. _tcscpy(pTTT->szText,strText);//设置
  107. return TRUE;
  108. case IDC_CAINFO_RADIODER:
  109. case IDC_CAINFO_RADIOPEM:
  110. if(bDer)
  111. {
  112. strText = "证书格式r当前DER格式";
  113. }
  114. else
  115. {
  116. strText = "证书格式r当前PEM格式";
  117. }
  118. _tcscpy(pTTT->szText,strText);//设置
  119. return TRUE;
  120. case IDC_STATIC_CAINFO21: //PKCS12
  121. if(bPkcs12)
  122. {
  123. strText = "是否生成PFX包r当前生成";
  124. }
  125. else
  126. {
  127. strText = "是否生成PFX包r当前不生成";
  128. }
  129. _tcscpy(pTTT->szText,strText);//设置
  130. return TRUE;
  131. case IDC_EDIT_PWD:
  132. if(!strPwd.IsEmpty())
  133. {
  134. _tcscpy(pTTT->szText, "私钥和PFX包密码r密码有效");//设置
  135. }
  136. else
  137. {
  138. _tcscpy(pTTT->szText, "私钥和PFX包密码r密码无效");//设置
  139. }
  140. return TRUE;
  141. }
  142. return FALSE;
  143. }
  144. BOOL CCaCertInfoPage::OnInitDialog() 
  145. {
  146. CPropertyPage::OnInitDialog();
  147. // TODO: Add extra initialization here
  148. //默认选中PFX
  149. ((CButton * )GetDlgItem(IDC_STATIC_CAINFO21))->SetCheck(1);
  150. ((CButton * )GetDlgItem(IDC_CAINFO_RADIODER))->SetCheck(1);
  151. if(!((CMiniCaApp *)AfxGetApp())->IsXpStyle())
  152. {
  153. ClassXP(GetDlgItem(IDC_CAINFO_RADIODER)->m_hWnd,TRUE);
  154. ClassXP(GetDlgItem(IDC_CAINFO_RADIOPEM)->m_hWnd,TRUE);
  155. ClassXP(GetDlgItem(IDC_STATIC_CAINFO21)->m_hWnd,TRUE);
  156. ClassXP(GetDlgItem(IDC_COMBO_L)->m_hWnd,TRUE);
  157. ClassXP(GetDlgItem(IDC_RADIO_DISK)->m_hWnd,TRUE);
  158. ClassXP(GetDlgItem(IDC_R_CSP)->m_hWnd,TRUE);
  159. ClassXP(GetDlgItem(IDC_COMBO_CSP)->m_hWnd,TRUE);
  160. ClassXP(GetDlgItem(IDC_EDIT_CONT)->m_hWnd,TRUE);
  161. ClassXP(GetDlgItem(IDC_EDIT_PWD)->m_hWnd,TRUE);
  162. ClassXP(GetDlgItem(IDC_EDIT_DAY)->m_hWnd,TRUE);
  163. }
  164.     HANDLE handle = ::LoadImage(AfxGetInstanceHandle(),
  165.                                 MAKEINTRESOURCE(IDI_ICON_DIR),
  166.                                 IMAGE_ICON,
  167.                                 0,
  168.                                 0,
  169.                                 LR_DEFAULTCOLOR);
  170.     m_XpEdit.SetButtonImage(handle, PJAI_ICON | PJAI_AUTODELETE | PJAI_STRETCHED );
  171. m_XpEdit.SetButtonWidth(18);
  172. //CMiniCaApp::NormalCode(buf);
  173. CImageList * pImgList = ((CMiniCaApp *)AfxGetApp())->GetImgList();
  174. m_CheckList.SetImageList(pImgList,LVSIL_SMALL);//用来改变LISTCTRL行宽度
  175. ListView_SetExtendedListViewStyle(m_CheckList.m_hWnd, LVS_EX_CHECKBOXES | LVS_EX_SUBITEMIMAGES |
  176. LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  177. CRect rect;
  178. m_CheckList.GetClientRect(rect);
  179. int width = rect.Width();
  180. m_CheckList.InsertColumn(0, MiniCT_0300, LVCFMT_LEFT, width/3); //MiniCT_0300 "字段名称"
  181. m_CheckList.InsertColumn(1, MiniCT_0301, LVCFMT_LEFT, width*2/3 - 15); //MiniCT_0301 "内容"
  182. GetIniInfo(m_IniPathName);
  183. char buf[256] = {0};
  184. GetPrivateProfileString("CA", "RSALEN","2048",buf,50, m_IniPathName);
  185. //查找加载项是否有效512 768 1024 1536 2048
  186. int index = ((CComboBox *)GetDlgItem(IDC_COMBO_L))->FindString(-1,buf);
  187. if(index == -1)
  188. index = 2;
  189. ((CComboBox *)GetDlgItem(IDC_COMBO_L))->SetCurSel(index);
  190. GetPrivateProfileString("CA", "DAY","365",buf,50, m_IniPathName);
  191. SetDlgItemText(IDC_EDIT_DAY,buf);
  192. GetPrivateProfileString("CA", "SN","1",buf,50, m_IniPathName);
  193. SetDlgItemText(IDC_EDIT_SN,buf);
  194. GetPrivateProfileString("CA", "KEYPWD","MiniCA",buf,50, m_IniPathName);
  195. SetDlgItemText(IDC_EDIT_PWD,buf);
  196. // m_PathName = ((CMiniCaApp *)AfxGetApp())->GetAppPath() +  "\Cert\";
  197. // SetDlgItemText(IDC_EDIT_PATH,m_PathName);
  198. // GetPrivateProfileString("PATH", "Cert","",m_PathName.GetBuffer(256),255, m_IniPathName);
  199. // m_PathName.ReleaseBuffer();//在 GetBuffer 和 ReleaseBuffer 之间这个范围,一定不能使用你要操作的这个缓冲的 CString 对象的任何方法
  200. /* CMiniMainDlg * pMain = (CMiniMainDlg *)AfxGetMainWnd();
  201. CCertDbPage * pSetup = (CCertDbPage *)(pMain->GetPage("CCertDbPage"));
  202. if(pSetup) 
  203. {
  204. CString m_PathName = pSetup->GetCertPath(2);
  205. SetDlgItemText(IDC_EDIT_PATH,m_PathName);
  206. }*/
  207. //BE98E302-2CAA-ED1A-93CF-A77559FEC4AC
  208. SetDlgItemText(IDC_EDIT_CONT,"BE98E302-2CAA-ED1A-93CF-A77559FEC4AC");
  209. // CG: The following block was added by the ToolTips component. { // Create the ToolTip control. m_toolTip.Create(this);
  210. m_toolTip.AddTool(GetDlgItem(IDC_RADIO_DISK), CMiniCaApp::NormalCode("磁盘证书"));
  211. m_toolTip.AddTool(GetDlgItem(IDC_EDIT_DAY), CMiniCaApp::NormalCode("证书有效期限r从申请时刻计起"));
  212. m_toolTip.AddTool(GetDlgItem(IDC_COMBO_L), CMiniCaApp::NormalCode("密钥长度r生成高强度密钥可能要很长时间"));
  213. m_toolTip.AddTool(GetDlgItem(IDC_R_CSP), CMiniCaApp::NormalCode("CSP证书"));
  214. m_toolTip.AddTool(GetDlgItem(IDC_LIST), "证书基本信息列表r详细设置请转到配置选项卡");
  215. m_toolTip.AddTool(GetDlgItem(IDC_EDIT_PATH), LPSTR_TEXTCALLBACK);
  216. m_toolTip.AddTool(GetDlgItem(IDC_COMBO_CSP), LPSTR_TEXTCALLBACK);
  217. m_toolTip.AddTool(GetDlgItem(IDC_EDIT_CONT), LPSTR_TEXTCALLBACK);
  218. m_toolTip.AddTool(GetDlgItem(IDC_CAINFO_RADIODER), LPSTR_TEXTCALLBACK);
  219. m_toolTip.AddTool(GetDlgItem(IDC_CAINFO_RADIOPEM), LPSTR_TEXTCALLBACK);
  220. m_toolTip.AddTool(GetDlgItem(IDC_STATIC_CAINFO21), LPSTR_TEXTCALLBACK);
  221. m_toolTip.AddTool(GetDlgItem(IDC_EDIT_PWD), LPSTR_TEXTCALLBACK);
  222. }
  223. return TRUE;  // return TRUE unless you set the focus to a control
  224.               // EXCEPTION: OCX Property Pages should return FALSE
  225. }
  226. void CCaCertInfoPage::OnRadioDisk() //磁盘文件
  227. {
  228. // TODO: Add your control notification handler code here
  229. m_CspBox.EnableWindow(FALSE);
  230. GetDlgItem(IDC_EDIT_PATH)->EnableWindow();
  231. // GetDlgItem(IDC_STATIC1)->EnableWindow(FALSE);
  232. GetDlgItem(IDC_EDIT_CONT)->EnableWindow(FALSE);
  233. }
  234. void CCaCertInfoPage::OnRCsp() //枚举CSP
  235. {
  236. // TODO: Add your control notification handler code here
  237. m_CspBox.EnableWindow();
  238. GetDlgItem(IDC_EDIT_PATH)->EnableWindow(FALSE);
  239. // GetDlgItem(IDC_STATIC1)->EnableWindow();
  240. GetDlgItem(IDC_EDIT_CONT)->EnableWindow();
  241. CString csp;
  242. GetDlgItemText(IDC_COMBO_CSP,csp);
  243. if(csp.IsEmpty())
  244. {
  245. m_CspBox.ResetContent();
  246. EnumCsp();
  247. CString str = GetDefaultCsp();
  248. int select = m_CspBox.FindString(-1,str);
  249. if(select!=-1)
  250. m_CspBox.SetCurSel(select);
  251. }
  252. }
  253. BOOL CCaCertInfoPage::EnumCsp()
  254. {
  255. DWORD       cbName;
  256.     DWORD       dwType;
  257.     DWORD       dwIndex;
  258.     CHAR        *pszName = NULL; 
  259.     // Loop through enumerating providers.
  260.     dwIndex = 0;
  261.     while(CryptEnumProviders(
  262. dwIndex,
  263. NULL,
  264. 0,
  265. &dwType,
  266. NULL,
  267. &cbName
  268. ))
  269.     {
  270.         //--------------------------------------------------------------------
  271.         //  cbName returns the length of the name of the next provider.
  272.         //  Allocate memory in a buffer to retrieve that name.
  273.         if (!(pszName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbName)))
  274.         {
  275. return FALSE;
  276.         }
  277.         //--------------------------------------------------------------------
  278.         //  Get the provider name.
  279.         if (CryptEnumProviders(
  280. dwIndex++,
  281. NULL,
  282. 0,
  283. &dwType,
  284. pszName,
  285. &cbName
  286. ))
  287.         {
  288. if(PROV_RSA_FULL == dwType)
  289. m_CspBox.AddString(pszName);
  290.    //         printf ("     %4.0dt%sn",dwType, pszName);
  291.         }
  292.         LocalFree(pszName);
  293.     } // End of while loop
  294. return FALSE;
  295. }
  296. CString CCaCertInfoPage::GetDefaultCsp()
  297. {
  298. DWORD       cbProvName=0;
  299.     LPTSTR      pbProvName=NULL;
  300. CString str;
  301.     // Get the length of the RSA_FULL default provider name.
  302.     if (!(CryptGetDefaultProvider(
  303. PROV_RSA_FULL, 
  304. NULL, 
  305. CRYPT_MACHINE_DEFAULT,
  306. NULL, 
  307. &cbProvName))) 
  308.     { 
  309. return "";
  310.     }
  311.     // Allocate local memory for the name of the default provider.
  312.     if (!(pbProvName = (LPTSTR)LocalAlloc(LMEM_ZEROINIT, cbProvName)))
  313.     {
  314. return "";
  315.     }
  316.     // Get the default provider name.
  317.     if (CryptGetDefaultProvider(
  318.         PROV_RSA_FULL, 
  319.         NULL, 
  320.         CRYPT_MACHINE_DEFAULT,
  321.         pbProvName,
  322.         &cbProvName)) 
  323.     {
  324. str = pbProvName;
  325.     }
  326.     else
  327.     {
  328. str = "";
  329.     }
  330.     // Free resouces when done.
  331.     LocalFree(pbProvName);
  332. return str;
  333. }
  334. BOOL CCaCertInfoPage::GetCertInfo(CStaticTreeCtrl * p_WizardTree,
  335.  HTREENODE & hInfoBase, 
  336.  HTREENODE &  hInfoHold, 
  337.  HTREENODE &  hInfoSave)
  338. {
  339. BOOL bFull = FALSE;//信息是否完整,是否可以制作数证
  340. CString info,name,matter,temp,pkcs,error,format;
  341. CString sInfoBase;
  342. HTREENODE hTemp;
  343. COLORREF colError = RGB(255,0,0);
  344. //数证基本信息
  345. CString str;
  346. int nCount = m_CheckList.GetItemCount();
  347. DWORD dData = 0;
  348. for(int i = nCount -1; i >= 0; i--)
  349. {
  350. //检查状态
  351. if(ListView_GetCheckState(m_CheckList.m_hWnd,i))//此项选中
  352. {
  353. name = m_CheckList.GetItemText(i,0);
  354. matter = m_CheckList.GetItemText(i,1);
  355. if(name.IsEmpty() || matter.IsEmpty())
  356. continue;
  357. sInfoBase.Format("%s: %s",name, matter);
  358. hTemp = p_WizardTree->InsertChild( hInfoBase, sInfoBase);
  359. /* if(name == "CN" || name == "commonName" && matter.IsEmpty())
  360. {
  361. p_WizardTree->SetNodeColor(hTemp, colError);
  362. }*/
  363. bFull = TRUE;
  364. }
  365. }
  366. if(!bFull)
  367. {
  368. p_WizardTree->SetNodeColor(hInfoBase, colError);
  369. }
  370. //数证约束信息
  371. //密钥长度,
  372. //证书有效期
  373. //私鈅保护
  374. GetDlgItemText(IDC_EDIT_PWD, matter);
  375. name = MiniCT_0302; //MiniCT_0302 "私钥保护:"
  376. CString strTemp;
  377. if(matter.IsEmpty())
  378. {
  379. strTemp = MiniCT_0303; //MiniCT_0303 "未保护"
  380. temp.Format("%s%s",name, strTemp);
  381. }
  382. else
  383. {
  384. strTemp = MiniCT_0304; //MiniCT_0304 "保护"
  385. temp.Format("%s%s",name, strTemp);
  386. }
  387. p_WizardTree->InsertChild( hInfoHold, CMiniCaApp::NormalCode(temp));
  388. GetDlgItemText(IDC_STATIC_CAINFO15, name);
  389. GetDlgItemText(IDC_EDIT_DAY, matter); //   10 - 
  390. sInfoBase.Format("%s %s",name,matter);
  391. hTemp = p_WizardTree->InsertChild( hInfoHold, sInfoBase);
  392. if(matter.IsEmpty())
  393. {
  394. p_WizardTree->SetNodeColor(hTemp, colError);
  395. bFull = FALSE;
  396. }
  397. GetDlgItemText(IDC_STATIC_CAINFO16, name);
  398. GetDlgItemText(IDC_COMBO_L, matter); //   10 - 
  399. sInfoBase.Format("%s %s",name,matter);
  400. hTemp = p_WizardTree->InsertChild( hInfoHold, sInfoBase);
  401. if(matter.IsEmpty())
  402. {
  403. p_WizardTree->SetNodeColor(hTemp, colError);
  404. bFull = FALSE;
  405. }
  406. //约束信息
  407. //数证格式
  408. if(((CButton*)GetDlgItem(IDC_CAINFO_RADIODER))->GetCheck())//选中,DER格式
  409. {
  410. format.Format("%s: DER", MiniCT_0305); //MiniCT_0305 证书格式
  411. m_CertFormat = DER;
  412. }
  413. else 
  414. {
  415. format.Format("%s: PEM", MiniCT_0305); //MiniCT_0305
  416. m_CertFormat = PEM;
  417. }
  418. p_WizardTree->InsertChild( hInfoHold, CMiniCaApp::NormalCode(format));
  419. if(((CButton*)GetDlgItem(IDC_STATIC_CAINFO21))->GetCheck())//选中
  420. {
  421. pkcs.Format("Pkcs#12%s", MiniCT_0306); //MiniCT_0306 "包: 附带"
  422. }
  423. else
  424. {
  425. pkcs.Format("Pkcs#12%s", MiniCT_0307); //MiniCT_0307 "包: 不附带"
  426. }
  427. p_WizardTree->InsertChild( hInfoHold, CMiniCaApp::NormalCode(pkcs));
  428. //存储信息
  429. if(((CButton*)GetDlgItem(IDC_RADIO_DISK))->GetCheck())//磁盘文件
  430. {
  431. CString str;
  432. GetDlgItemText(IDC_EDIT_PATH,temp);
  433. //尝试建立目录
  434. //测试路径是否存在
  435. BOOL bDir = FALSE;
  436. // if(_mkdir(temp) == -1 && errno != EEXIST)
  437. temp += "\";
  438. if(!CMiniCaApp::MakeSureDirectoryPathExists(temp))
  439. {
  440. str.Format("%s %s", MiniCT_0308, temp);  //MiniCT_0308 存储路径无效
  441. bFull = FALSE;
  442. }
  443. else
  444. {
  445. str.Format("%s %s",MiniCT_0309, temp); //MiniCT_0309 存储路径: 
  446. bDir = TRUE;
  447. }
  448. str.Replace("\", "\ ");
  449. HTREENODE hTemp = p_WizardTree->InsertChild( hInfoSave, CMiniCaApp::NormalCode(str));
  450. if(!bDir)
  451. p_WizardTree->SetNodeColor(hTemp, RGB(255,0,0));
  452. }
  453. else if(((CButton*)GetDlgItem(IDC_R_CSP))->GetCheck())//CSP
  454. {
  455. BOOL bDir = FALSE;
  456. CString str;
  457. GetDlgItemText(IDC_COMBO_CSP,str);
  458. temp.Format("%s %s", MiniCT_0310, str); //MiniCT_0310 CSP名称:
  459. p_WizardTree->InsertChild( hInfoSave, CMiniCaApp::NormalCode(temp));
  460. GetDlgItemText(IDC_EDIT_CONT,temp);
  461. if(temp.IsEmpty())
  462. {
  463. str.Format(MiniCT_0311); ////MiniCT_0311 "密钥容器无效"
  464. bFull = FALSE;
  465. bDir = FALSE;
  466. }
  467. else
  468. {
  469. str.Format("%s %sn", MiniCT_0312, temp); //MiniCT_0312 密钥容器:
  470. bDir = TRUE;
  471. }
  472. HTREENODE hTemp = p_WizardTree->InsertChild( hInfoSave, CMiniCaApp::NormalCode(str));
  473. if(!bDir)
  474. p_WizardTree->SetNodeColor(hTemp, RGB(255,0,0));
  475. }
  476. return bFull;
  477. }
  478. void CCaCertInfoPage::GetCert(stuSUBJECT *& pCERT, stuCERTINFO & certInfo)
  479. {
  480. CString str;
  481. int nCount = m_CheckList.GetItemCount();
  482. CString strName;
  483. DWORD dData = 0;
  484. for(int i = 0;i<nCount;i++)
  485. {
  486. //检查状态
  487. if(ListView_GetCheckState(m_CheckList.m_hWnd,i))//此项选中
  488. {
  489. strName = m_CheckList.GetItemText(i,1);
  490. pCERT->Add(pCERT,m_ArrayInside[i], strName);
  491. }
  492. }
  493. certInfo.uCertLen = GetDlgItemInt(IDC_COMBO_L);
  494. certInfo.uCertDay = GetDlgItemInt(IDC_EDIT_DAY);
  495. certInfo.uCertFormat = m_CertFormat;
  496. certInfo.bCertP12 = ((CButton*)GetDlgItem(IDC_STATIC_CAINFO21))->GetCheck();
  497. GetDlgItemText(IDC_EDIT_PWD,str);
  498. strncpy(certInfo.cCertPwd,str.GetBuffer(0),sizeof(certInfo.cCertPwd));
  499. str.ReleaseBuffer();
  500. if(((CButton*)GetDlgItem(IDC_RADIO_DISK))->GetCheck())//选中磁盘
  501. {
  502. GetDlgItemText(IDC_EDIT_PATH,str);
  503. strncpy(certInfo.cCertDir,str.GetBuffer(0),sizeof(certInfo.cCertDir));
  504. str.ReleaseBuffer();
  505. }
  506. else
  507. {
  508. GetDlgItemText(IDC_COMBO_CSP,str);
  509. strncpy(certInfo.cCertCsp,str.GetBuffer(0),sizeof(certInfo.cCertCsp));
  510. str.ReleaseBuffer();
  511. GetDlgItemText(IDC_EDIT_CONT,str);
  512. strncpy(certInfo.cCertCon,str.GetBuffer(0),sizeof(certInfo.cCertCon));
  513. str.ReleaseBuffer();
  514. }
  515. }
  516. BOOL CCaCertInfoPage::PreTranslateMessage(MSG* pMsg)
  517. {
  518. // CG: The following block was added by the ToolTips component. { // Let the ToolTip process this message. m_toolTip.RelayEvent(pMsg); } return CPropertyPage::PreTranslateMessage(pMsg); // CG: This was added by the ToolTips component.
  519. }
  520. void CCaCertInfoPage::SetNamePath(const CString &strPath)
  521. {
  522. if(!strPath.IsEmpty())
  523. {
  524. SetDlgItemText(IDC_EDIT_PATH,strPath);
  525. //更新报告信息
  526. CMiniMainDlg * pMain = (CMiniMainDlg *)AfxGetMainWnd();
  527. CCaCertWizardSheet * pWizard = (CCaCertWizardSheet *)(pMain->GetPage("CCaCertWizardSheet"));
  528. if(pWizard)
  529. {
  530. CCaCertReportPage * pReportPage = (CCaCertReportPage *)(pWizard->GetPage("CCaCertReportPage"));
  531. if(pReportPage)
  532. pReportPage->ViewWizardInfo();
  533. }
  534. }
  535. }
  536. void CCaCertInfoPage::SetLVCheck (WPARAM ItemIndex, BOOL bCheck)
  537. {
  538. ListView_SetItemState(m_CheckList.m_hWnd, ItemIndex, 
  539. UINT((int(bCheck) + 1) << 12), LVIS_STATEIMAGEMASK);
  540. }
  541. void CCaCertInfoPage::GetIniInfo(CString strIniPath)
  542. {
  543. //删除原来内容
  544. m_CheckList.DeleteAllItems();
  545. //清除链表内容
  546. m_ArrayInside.RemoveAll();
  547. char buf[255] = {0};
  548. char info[255] = {0};
  549. char inside[255] = {0};
  550. GetPrivateProfileString("TOTAL", "ToTal","0",buf,50, m_IniPathName);
  551. CString strIndex;
  552. int uMax = atoi(buf);
  553. for(int i = 0, j = 0; i<uMax; i++)
  554. {
  555. strIndex.Format("INFO%d",i+1);
  556. //首先读取是否显示标志
  557. GetPrivateProfileString(strIndex, "IsDisp","0",buf,50, m_IniPathName);
  558. if(atoi(buf) <= 0)
  559. continue;
  560. GetPrivateProfileString(strIndex, "InsideName","0",inside,254, m_IniPathName);//内部名称
  561. if(strlen(inside) == 0)
  562. continue;
  563. else
  564. m_ArrayInside.Add(inside);
  565. GetPrivateProfileString(strIndex, "DispName","0",buf,254, m_IniPathName);
  566. if(strlen(buf) == 0)
  567. continue;
  568. GetPrivateProfileString(strIndex, "Info","0",info,254, m_IniPathName);
  569. if(strlen(info) == 0)
  570. continue;
  571. m_CheckList.InsertItem(j, buf, 7);
  572. m_CheckList.SetItemText(j, 1, info);
  573. GetPrivateProfileString(strIndex, "IsCheck","78",buf,50, m_IniPathName);//是否选中
  574. SetLVCheck (j, atoi(buf));
  575. j++;
  576. }
  577. }
  578. void CCaCertInfoPage::TranslateCT()
  579. {
  580. CHeaderCtrl * pHeader = m_CheckList.GetHeaderCtrl();
  581. if (pHeader)
  582. {
  583. CString str = MiniCT_0300;
  584. HDITEM hdi;
  585. hdi.mask = HDI_TEXT;
  586. hdi.pszText = (LPTSTR)((LPCTSTR)str);
  587. pHeader->SetItem(0, &hdi);
  588. str = MiniCT_0301;
  589. hdi.pszText = (LPTSTR)((LPCTSTR)str);
  590. pHeader->SetItem(1, &hdi);
  591. }
  592. //翻译STATIC
  593. SetDlgItemText(IDC_STATIC_CAINFO1, MiniCT_10301); 
  594. SetDlgItemText(IDC_STATIC_CAINFO12, MiniCT_10302); 
  595. SetDlgItemText(IDC_STATIC_CAINFO13, MiniCT_10303); 
  596. SetDlgItemText(IDC_STATIC_CAINFO14, MiniCT_10304); 
  597. SetDlgItemText(IDC_STATIC_CAINFO15, MiniCT_10305); 
  598. SetDlgItemText(IDC_STATIC_CAINFO16, MiniCT_10306); 
  599. SetDlgItemText(IDC_STATIC_CAINFO17, MiniCT_10307); 
  600. SetDlgItemText(IDC_STATIC_CAINFO18, MiniCT_10308); 
  601. SetDlgItemText(IDC_STATIC_CAINFO19, MiniCT_10309); 
  602. SetDlgItemText(IDC_STATIC_CAINFO20, MiniCT_10310); 
  603. SetDlgItemText(IDC_STATIC_CAINFO21, MiniCT_10311); 
  604. SetDlgItemText(IDC_STATIC_CAINFO22, MiniCT_10312); 
  605. SetDlgItemText(IDC_STATIC_CAINFO23, MiniCT_10313); 
  606. SetDlgItemText(IDC_CAINFO_RADIODER, MiniCT_10314); 
  607. SetDlgItemText(IDC_CAINFO_RADIOPEM, MiniCT_10315); 
  608. SetDlgItemText(IDC_RADIO_DISK, MiniCT_10316); 
  609. SetDlgItemText(IDC_R_CSP, MiniCT_10317); 
  610. }
  611. void CCaCertInfoPage::OnCainfoRadioder() 
  612. {
  613. // TODO: Add your control notification handler code here
  614. m_CertFormat = DER;
  615. }
  616. void CCaCertInfoPage::OnCainfoRadiopem() 
  617. {
  618. // TODO: Add your control notification handler code here
  619. m_CertFormat = PEM;
  620. }