Multy3Dlg.cpp
上传用户:shenmao
上传日期:2014-12-06
资源大小:238k
文件大小:5k
源码类别:

进程与线程

开发平台:

Visual C++

  1. // Multy3Dlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Multy3.h"
  5. #include "Multy3Dlg.h"
  6. #include "UIThread.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. UINT ThreadFunc(LPVOID lpParam) {
  15.  threadInfo* pInfo=(threadInfo*)lpParam;
  16.  for(int i=0;i<100;i++)
  17.  {
  18.   int nTemp=pInfo->nMilliSecond;
  19.   pInfo->pctrlProgress->SetPos(i);
  20.   Sleep(nTemp);
  21.  }
  22.  return 0;
  23. }
  24. threadInfo Info;
  25. class CAboutDlg : public CDialog
  26. {
  27. public:
  28. CAboutDlg();
  29. // Dialog Data
  30. //{{AFX_DATA(CAboutDlg)
  31. enum { IDD = IDD_ABOUTBOX };
  32. //}}AFX_DATA
  33. // ClassWizard generated virtual function overrides
  34. //{{AFX_VIRTUAL(CAboutDlg)
  35. protected:
  36. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  37. //}}AFX_VIRTUAL
  38. // Implementation
  39. protected:
  40. //{{AFX_MSG(CAboutDlg)
  41. //}}AFX_MSG
  42. DECLARE_MESSAGE_MAP()
  43. };
  44. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  45. {
  46. //{{AFX_DATA_INIT(CAboutDlg)
  47. //}}AFX_DATA_INIT
  48. }
  49. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CAboutDlg)
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  56. //{{AFX_MSG_MAP(CAboutDlg)
  57. // No message handlers
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CMulty3Dlg dialog
  62. CMulty3Dlg::CMulty3Dlg(CWnd* pParent /*=NULL*/)
  63. : CDialog(CMulty3Dlg::IDD, pParent)
  64. {
  65. //{{AFX_DATA_INIT(CMulty3Dlg)
  66. m_nMilliSecond = 0;
  67. //}}AFX_DATA_INIT
  68. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  69. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  70. }
  71. void CMulty3Dlg::DoDataExchange(CDataExchange* pDX)
  72. {
  73. CDialog::DoDataExchange(pDX);
  74. //{{AFX_DATA_MAP(CMulty3Dlg)
  75. DDX_Control(pDX, IDC_PROGRESS1, m_ctrlProgress);
  76. DDX_Text(pDX, IDC_MILLISECOND, m_nMilliSecond);
  77. //}}AFX_DATA_MAP
  78. }
  79. BEGIN_MESSAGE_MAP(CMulty3Dlg, CDialog)
  80. //{{AFX_MSG_MAP(CMulty3Dlg)
  81. ON_WM_SYSCOMMAND()
  82. ON_WM_PAINT()
  83. ON_WM_QUERYDRAGICON()
  84. ON_BN_CLICKED(IDC_START, OnStart)
  85. //}}AFX_MSG_MAP
  86. END_MESSAGE_MAP()
  87. /////////////////////////////////////////////////////////////////////////////
  88. // CMulty3Dlg message handlers
  89. BOOL CMulty3Dlg::OnInitDialog()
  90. {
  91. CDialog::OnInitDialog();
  92. // Add "About..." menu item to system menu.
  93. // IDM_ABOUTBOX must be in the system command range.
  94. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  95. ASSERT(IDM_ABOUTBOX < 0xF000);
  96. CMenu* pSysMenu = GetSystemMenu(FALSE);
  97. if (pSysMenu != NULL)
  98. {
  99. CString strAboutMenu;
  100. strAboutMenu.LoadString(IDS_ABOUTBOX);
  101. if (!strAboutMenu.IsEmpty())
  102. {
  103. pSysMenu->AppendMenu(MF_SEPARATOR);
  104. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  105. }
  106. }
  107. // Set the icon for this dialog.  The framework does this automatically
  108. //  when the application's main window is not a dialog
  109. SetIcon(m_hIcon, TRUE); // Set big icon
  110. SetIcon(m_hIcon, FALSE); // Set small icon
  111. // TODO: Add extra initialization here
  112.  m_ctrlProgress.SetRange(0,99);
  113.  m_nMilliSecond=10;
  114.  UpdateData(FALSE);
  115. return TRUE;  // return TRUE  unless you set the focus to a control
  116. }
  117. void CMulty3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  118. {
  119. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  120. {
  121. CAboutDlg dlgAbout;
  122. dlgAbout.DoModal();
  123. }
  124. else
  125. {
  126. CDialog::OnSysCommand(nID, lParam);
  127. }
  128. }
  129. // If you add a minimize button to your dialog, you will need the code below
  130. //  to draw the icon.  For MFC applications using the document/view model,
  131. //  this is automatically done for you by the framework.
  132. void CMulty3Dlg::OnPaint() 
  133. {
  134. if (IsIconic())
  135. {
  136. CPaintDC dc(this); // device context for painting
  137. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  138. // Center icon in client rectangle
  139. int cxIcon = GetSystemMetrics(SM_CXICON);
  140. int cyIcon = GetSystemMetrics(SM_CYICON);
  141. CRect rect;
  142. GetClientRect(&rect);
  143. int x = (rect.Width() - cxIcon + 1) / 2;
  144. int y = (rect.Height() - cyIcon + 1) / 2;
  145. // Draw the icon
  146. dc.DrawIcon(x, y, m_hIcon);
  147. }
  148. else
  149. {
  150. CDialog::OnPaint();
  151. }
  152. }
  153. // The system calls this to obtain the cursor to display while the user drags
  154. //  the minimized window.
  155. HCURSOR CMulty3Dlg::OnQueryDragIcon()
  156. {
  157. return (HCURSOR) m_hIcon;
  158. }
  159. void CMulty3Dlg::OnStart() 
  160. {
  161. /* UpdateData(TRUE);
  162.  Info.nMilliSecond=m_nMilliSecond;
  163.  Info.pctrlProgress=&m_ctrlProgress;
  164.  hThread=CreateThread(NULL,
  165.   0,
  166.   (LPTHREAD_START_ROUTINE)ThreadFunc,
  167.   &Info,
  168.   0,
  169.   &ThreadID);
  170. */
  171. /* UpdateData(TRUE);
  172.  Info.nMilliSecond=m_nMilliSecond;
  173.  Info.pctrlProgress=&m_ctrlProgress;
  174.  pThread=AfxBeginThread(ThreadFunc,
  175.   &Info);
  176. */
  177.  CUIThread* pThread=new CUIThread();
  178.  pThread->CreateThread();
  179. /*
  180.  GetDlgItem(IDC_START)->EnableWindow(FALSE);
  181.  WaitForSingleObject(hThread,INFINITE);
  182.  GetDlgItem(IDC_START)->EnableWindow(TRUE);
  183. */
  184. }