15,471
社区成员
发帖
与我相关
我的任务
分享
int step = 0;
CRITICAL_SECTION c;
//////////////
/////。。。
///////////////
BOOL CcriticalDlg::OnInitDialog()
{
/////////
//......
////////
InitializeCriticalSection(&c);
/////////
//......
////////
}
DWORD F1(LPVOID l)
{
EnterCriticalSection(&c);
step++;
HWND h1 = ::GetDlgItem (dlg,IDC_EDIT1);
::SetFocus (h1);
LeaveCriticalSection(&c);
return 1;
}
DWORD F2(LPVOID l)
{
EnterCriticalSection(&c);
step++;
::keybd_event (VK_ADD,0,0,0);
LeaveCriticalSection(&c);
return 1;
}
DWORD F3(LPVOID l)
{
EnterCriticalSection(&c);
step++;
HWND h2 = ::GetDlgItem (dlg,IDC_EDIT1);
::SetFocus (h2);
LeaveCriticalSection(&c);
return 1;
}
void CcriticalDlg::OnEnChangeEdit2()
{
::AfxBeginThread ((AFX_THREADPROC)F1,NULL);
::AfxBeginThread ((AFX_THREADPROC)F2,NULL);
::AfxBeginThread ((AFX_THREADPROC)F3,NULL);
}
DWORD K(LPVOID l)
{
::Sleep (100);
keybd_event(VK_ADD,0,0,0);
keybd_event(VK_ADD,0,KEYEVENTF_KEYUP,0);
return 1;
}
DWORD ThreadId = NULL;
HANDLE hThread = NULL;
e1.SetFocus ();
hThread = ::CreateThread (NULL,0,(LPTHREAD_START_ROUTINE)K,NULL,0,&ThreadId);
::WaitForSingleObject (hThread,INFINITE);
e2.SetFocus ();