| 12
 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
 
 |  
 
//globales variables
	//Worker thread
	#define WM_USER_THREAD_FINISHED (WM_USER+0x100) 
	#define WM_USER_THREAD_UPDATE_PROGRESS (WM_USER+0x101)
 
	UINT MyThreadFunc(LPVOID lParam); 
	int progressindex =0;
 
	typedef struct THREADINFOSTRUCT {
	HWND hWnd;
	CString someData;
 
	} THREADINFOSTRUCT;
	//Worker thread
 
	UINT MyThreadProc(LPVOID pParam);
 
 
//codes
BOOL CDlg_2::OnInitDialog() 
{
	CDialog::OnInitDialog();
 
	...
 
 
	m_progress2.SetRange(1, 100);
	m_progress2.SetPos(0);
 
	connected =false;
	SetTimer(3,100,0);
    GetDlgItem(IDC_BUTTON_CAMERA2)->EnableWindow(false); 
 
	return TRUE; 
}
 
 
LRESULT CDlg_2::OnThreadFinished(WPARAM wParam,LPARAM lParam)
{
AfxMessageBox("Thread has exited");
connected=1;
return 0;
}
 
LRESULT CDlg_2::OnThreadUpdateProgress(WPARAM wParam,LPARAM lParam)
{
	//OnButtonBegin() ;
	return 0;
}
 
//Worker thread
UINT MyThreadFunc(LPVOID lParam)
{
	THREADINFOSTRUCT* tis=(THREADINFOSTRUCT*)lParam;
 
	while(connected!=1)
	{
		AfxMessageBox("In the Thread");
 
		connected=cp.Init("192.0.2.2"); //CHANGES
		Sleep(1000); //sleep between call blockinfg function
	}
	PostMessage(tis->hWnd,WM_USER_THREAD_FINISHED,0,0);
 
	delete tis;
	return 0;
}
 
 
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
	{	
		RedrawWindow();
 
		if (posprogress2==100)
		{
			posprogress2=10;  		
		}
		else
		{
			posprogress2+=10;
		}
 
		m_progress2.SetPos(posprogress2);
 
		if ((connected==1) && (already_pass==false))
		{
 
			m_progress2.SetPos(0);
			first_msg =false;
			m_static_msg1.SetWindowText(NULL);
			already_pass =true;
 
		}
		else if (forcetest==0)
		{
 
		OnButtonBegin(); //CHANGES
 
		}
	}
 
	UpdateData(FALSE);
	CDialog::OnTimer(nIDEvent);
}
 
void CDlg_2::OnButtonBegin() 
{
	// TODO: Add your control notification handler code here
	CWaitCursor();
 
	THREADINFOSTRUCT *tis=new THREADINFOSTRUCT; //CHANGES
	tis->hWnd=m_hWnd;
	tis->someData="This is in a thread.";
 
 
	if (process_0)
	{
			process_0 =false;
			process_1= true;
 
			CWinThread *pThread = AfxBeginThread(MyThreadFunc,tis,
			THREAD_PRIORITY_NORMAL,0,0);  
	}
	else if (process_1)
	{
		//try
			{
 
				//connected=cp.Init("192.0.2.2"); //
 
			}
		//	catch(...)
			{
					//MessageBox("Problem of Init Fxcam", "Exception Message");
					//KillTimer(3);
					//m_progress2.SetPos(0);
					//GetDlgItem(IDC_BUTTON_CAMERA2)->EnableWindow(true); 
			}
			if (connected==1)
			{
							process_1 =false;
							process_2= true;
 
							CFont *m_Font_step2_label = new CFont;
							m_Font_step2_label->CreateFont(14, 0, 0, 0, 700,
							FALSE, FALSE, FALSE, 900, 
							OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,   
							DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Verdana");							
							m_step2_label.SetFont(m_Font_step2_label);
			}
 
	}
 
	else if (process_2)
	{
	...
	}
 
	...
	...
} | 
Partager