1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
BOOL CDlg_2::OnInitDialog()
{
....
THREADINFOSTRUCT *tis=new THREADINFOSTRUCT;
tis->hWnd=m_hWnd;
tis->someData="This is in a thread.";
//call to thread for bar progress
CWinThread *pThread = AfxBeginThread(MyThreadFunc,tis,
THREAD_PRIORITY_HIGHEST,0,0); // THREAD_PRIORITY_NORMAL THREAD_PRIORITY_HIGHEST
connected =false;
SetTimer(3,1000,0); //call to OnTImer
return TRUE; // return TRUE unless you set the focus to a control
}
UINT MyThreadFunc(LPVOID lParam)
{
THREADINFOSTRUCT* tis=(THREADINFOSTRUCT*)lParam;
if(wrong_exit==true)
good_finish ==true;
while(good_finish==false)
{
int i=3;
SendMessage(tis->hWnd,WM_USER_THREAD_UPDATE_PROGRESS,i,100); //SendMessage PostMessage
DoEvents();
Sleep(100);
}
if(good_finish ==true)
PostMessage(tis->hWnd,WM_USER_THREAD_FINISHED,0,0);
delete tis;
return 0;
}
LRESULT CDlg_2::OnThreadFinished(WPARAM wParam,LPARAM lParam)
{
//AfxMessageBox("Thread has exited");
return 0;
}
LRESULT CDlg_2::OnThreadUpdateProgress(WPARAM wParam,LPARAM lParam)
{
RedrawWindow(); //for trying to refresh window dialog
if(progressindex ==100)
progressindex=0;
else
progressindex+=10;
m_progress2.SetPos(progressindex);
return 0;
}
int DoEvents()
{
MSG msg;
int nCount = 0;
while ( ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
{
nCount++;
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return nCount;
}
void CDlg_2::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
UpdateData(TRUE);
..
if (nIDEvent ==3) //timer for progress bar
{
//KillTimer(3);
GetDlgItem(IDC_BUTTON_CAMERA2)->EnableWindow(false);
//commented because trying to done by MyThreadFunc
/*
if (posprogress2==100)
{
//091002
posprogress2=10;
}
else
{
//091002
posprogress2+=10;
}
//091002
m_progress2.SetPos(posprogress2);
*/
if ((connected==1) && (already_pass==false))
{
//091002
//GetDlgItem(IDC_BUTTON_CAMERA2)->EnableWindow(true);
m_progress2.SetPos(0);
first_msg =false;
m_static_msg1.SetWindowText(NULL);
already_pass =true;
}
else if (forcetest==0)
{
OnButtonBegin(); //this function contain a system function that slow the application
}
}
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
void CDlg_2::OnButtonBegin()
{
// TODO: Add your control notification handler code here
CWaitCursor();
SHELLEXECUTEINFO sei5; //091001
DWORD dw; //091001
KillTimer(3);
GetDlgItem(IDC_BUTTON_CAMERA2)->EnableWindow(false);
if (process_0)
{
process_0 =false;
process_1= true;
}
else if (process_1)
{
//MessageBox("in process1");
//try //
{
connected=cp.Init("192.0.2.2"); //This calling blocks the application. When removing the
//barporgress run well otherwise it the barprogress is very slow.
}
// catch(...)
{
//MessageBox("Problem of Init Fxcam", "Exception Message");
//KillTimer(3);
//m_progress2.SetPos(0);
//GetDlgItem(IDC_BUTTON_CAMERA2)->EnableWindow(true);
}
if (connected==1)
{
...
}
else if (process_2)
{
..
}
....
if(good_finish==true)
KillTimer(3);
else
SetTimer(3,200,0);
} |
Partager