studyDlg.cpp
上传用户:sufang1998
上传日期:2022-07-24
资源大小:3327k
文件大小:4k
源码类别:

数学计算

开发平台:

Visual C++

  1. // studyDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "study.h"
  5. #include "studyDlg.h"
  6. #include ".studydlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  11. class CAboutDlg : public CDialog
  12. {
  13. public:
  14. CAboutDlg();
  15. // 对话框数据
  16. enum { IDD = IDD_ABOUTBOX };
  17. protected:
  18. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
  19. // 实现
  20. protected:
  21. DECLARE_MESSAGE_MAP()
  22. };
  23. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  24. {
  25. }
  26. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. }
  30. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  31. END_MESSAGE_MAP()
  32. // CstudyDlg 对话框
  33. CstudyDlg::CstudyDlg(CWnd* pParent /*=NULL*/)
  34. : CDialog(CstudyDlg::IDD, pParent)
  35. {
  36. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  37. }
  38. void CstudyDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. }
  42. BEGIN_MESSAGE_MAP(CstudyDlg, CDialog)
  43. ON_WM_SYSCOMMAND()
  44. ON_WM_PAINT()
  45. ON_WM_QUERYDRAGICON()
  46. //}}AFX_MSG_MAP
  47. ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
  48. ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
  49. END_MESSAGE_MAP()
  50. // CstudyDlg 消息处理程序
  51. BOOL CstudyDlg::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. // 将“关于...”菜单项添加到系统菜单中。
  55. // IDM_ABOUTBOX 必须在系统命令范围内。
  56. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  57. ASSERT(IDM_ABOUTBOX < 0xF000);
  58. CMenu* pSysMenu = GetSystemMenu(FALSE);
  59. if (pSysMenu != NULL)
  60. {
  61. CString strAboutMenu;
  62. strAboutMenu.LoadString(IDS_ABOUTBOX);
  63. if (!strAboutMenu.IsEmpty())
  64. {
  65. pSysMenu->AppendMenu(MF_SEPARATOR);
  66. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  67. }
  68. }
  69. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  70. //  执行此操作
  71. SetIcon(m_hIcon, TRUE); // 设置大图标
  72. SetIcon(m_hIcon, FALSE); // 设置小图标
  73. // TODO: 在此添加额外的初始化代码
  74. return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
  75. }
  76. void CstudyDlg::OnSysCommand(UINT nID, LPARAM lParam)
  77. {
  78. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  79. {
  80. CAboutDlg dlgAbout;
  81. dlgAbout.DoModal();
  82. }
  83. else
  84. {
  85. CDialog::OnSysCommand(nID, lParam);
  86. }
  87. }
  88. // 如果向对话框添加最小化按钮,则需要下面的代码
  89. //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  90. //  这将由框架自动完成。
  91. void CstudyDlg::OnPaint() 
  92. {
  93. if (IsIconic())
  94. {
  95. CPaintDC dc(this); // 用于绘制的设备上下文
  96. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  97. // 使图标在工作矩形中居中
  98. int cxIcon = GetSystemMetrics(SM_CXICON);
  99. int cyIcon = GetSystemMetrics(SM_CYICON);
  100. CRect rect;
  101. GetClientRect(&rect);
  102. int x = (rect.Width() - cxIcon + 1) / 2;
  103. int y = (rect.Height() - cyIcon + 1) / 2;
  104. // 绘制图标
  105. dc.DrawIcon(x, y, m_hIcon);
  106. }
  107. else
  108. {
  109. CDialog::OnPaint();
  110. }
  111. }
  112. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  113. HCURSOR CstudyDlg::OnQueryDragIcon()
  114. {
  115. return static_cast<HCURSOR>(m_hIcon);
  116. }
  117. void CstudyDlg::OnBnClickedButton2()
  118. {
  119. CTime time;
  120. int RanCheckNum = 0;
  121. char out[11];
  122. char keytemp[5]={0};
  123. char strtime[8]={0};
  124. char strGroupNum[8];
  125. char path[MAX_PATH]; 
  126. char old[11]={0};
  127. int intGroupNum;
  128. int intChong=0;
  129. CStdioFile myfile;
  130. CFileException  fx;
  131. memset(out,0x30,sizeof(out));
  132. out[10]=0x00;
  133. time = CTime::GetCurrentTime();
  134. srand((unsigned)time.GetTime());
  135. GetDlgItem(IDC_GROUPNUM)->GetWindowText(strGroupNum,10);
  136. intGroupNum = atoi(strGroupNum);
  137. GetCurrentDirectory(MAX_PATH,path); 
  138. strcat(path,"\random.txt");
  139. if(!myfile.Open(path,CFile::modeCreate|CFile::modeReadWrite,&fx))
  140. {
  141.   TCHAR buf[255];
  142.           fx.GetErrorMessage(buf, 255);
  143.           CString strPrompt(buf);
  144.           AfxMessageBox(strPrompt);
  145.   return;
  146. }
  147. for(int i = 0;i<intGroupNum;i++ )
  148. {
  149. for(int i=0;i <2;i++)
  150. {
  151. RanCheckNum = rand();//产生随机数
  152. _itoa(RanCheckNum,keytemp,16);//将随机数转换成16进制
  153. memcpy( &out[i*4],keytemp,strlen(keytemp));
  154. }
  155. out[8]=0x0d;
  156. out[9]=0x0a;
  157. myfile.begin;
  158. //while(myfile.ReadString(old,10))
  159. //{
  160. // if(::strcmp(old,out)==0)
  161. // intChong ++;
  162. //}
  163. myfile.WriteString(out);
  164. }
  165. myfile.Close();
  166. UpdateData(FALSE);
  167. AfxMessageBox("ok");
  168. }
  169. void CstudyDlg::OnBnClickedButton3()
  170. {
  171. char path[MAX_PATH];
  172. HWND   handle;
  173. GetCurrentDirectory(MAX_PATH,path); 
  174. strcat(path,"\random.txt");
  175. ShellExecute(this->m_hWnd,   "open",   path,   NULL,   NULL,   SW_SHOWNORMAL);     
  176. }