WinCE7.0_FindWindow函数在线程中调用卡死的现象(2)

上接:WinCE7.0_FindWindow函数在线程中调用卡死的现象


/*

 * 对于同一句FindWindow(NULL,L"TestFindWindow");

 * 在按键响应中执行耗时约为: 5ms

 * 在线程中执行由于按键响应中有 Sleep 存在耗时约为: 10020ms

 * Win32 框架下执行的结果与 MFC 相同

 *

 * 按键按下响应后的执行 LOG 如下:

 starttest FindWindow: CSmartDeviceMFCDlg::OnBnClickedButton2

 end of test FindWindow:CSmartDeviceMFCDlg::OnBnClickedButton2,tick: 5

 start test FindWindow:TestFindWindowThreadProc

 Sleep 0

 Sleep 1

 Sleep 2

 Sleep 3

 Sleep 4

 Sleep 5

 Sleep 6

 Sleep 7

 Sleep 8

 Sleep 9

 end of test FindWindow:TestFindWindowThreadProc(10020)

 线程'TestFindWindowThreadProc' (0x45e0336) 已退出返回值为 0 (0x0)

*/

DWORDWINAPI TestFindWindowThreadProc(void * pParam) // 查找Window句柄线程
{
    DWORD dwTick = GetTickCount();
    printf("\r\nstart test FindWindow:%s\r\n",__FUNCTION__);
    // 在线程中调用FindWindow,但实际的执行动作以SendMessage 方式发送到窗口进程来执行(如果主窗体阻塞???)
    // 从此测试代码发现,Button 按键响应中的Sleep 阻塞了 FindWindow 的执行; 直接Sleep 结束才执行了 FindWindow 操作
    FindWindow(NULL,L"TestFindWindow");
    printf("\r\nend of test FindWindow:%s(%d)\r\n",__FUNCTION__,GetTickCount() - dwTick);
 
    return 0;
}
 
voidCSmartDeviceMFCDlg::OnBnClickedButton2()
{
    // TODO: 在此添加控件通知处理程序代码
    DWORD dwTick = GetTickCount();
    printf("\r\nstart test FindWindow:%s\r\n",__FUNCTION__);
    FindWindow(NULL,L"TestFindWindow");
    printf("\r\nend of test FindWindow:%s,tick: %d\r\n",__FUNCTION__,GetTickCount() - dwTick);
    CloseHandle(CreateThread(NULL,0,TestFindWindowThreadProc,NULL,0,0));
 
    for(int i = 0;i < 10;i++)
    {
           Sleep(1000);
           printf("Sleep %d\r\n",i);
    }
}



你可能感兴趣的:(WinCE7.0_FindWindow函数在线程中调用卡死的现象(2))