在线程里开启等待对话框,在主线程里发送关闭消息,FindWindow得不到等待框的句柄!
int InitDlgRes;
static LRESULT CALLBACK InitDlgProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_INITDIALOG:
{
CWnd::FromHandle(hwnd)->CenterWindow(); //AfxGetMainWnd()->CenterWindow(hwnd);
return TRUE;
}
case WM_CLOSE:
{
EndDialog(hwnd,InitDlgRes);// InitDlgRes TRUE
return TRUE;
}
}
return FALSE;
}
DWORD WINAPI InitDlgThreadProc(LPVOID lpParameter)//pApp->m_instanceDIALOG_
{
InitDlgRes = DialogBox(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDD_INITDLG),AfxGetMainWnd()->m_hWnd, (DLGPROC) InitDlgProc);
return TRUE;
}
void ShowInitDlg()
{
LPSECURITY_ATTRIBUTES lpta = NULL;
DWORD dwsz = 0;
LPTHREAD_START_ROUTINE lpsr = InitDlgThreadProc;
LPVOID lpp = NULL;
DWORD dwcf = 0;
DWORD lptid;
HANDLE handle = CreateThread(
lpta, // pointer to security attributes
dwsz, // initial thread stack size
lpsr, // pointer to thread function
lpp, // argument for new thread
dwcf, // creation flags
&lptid // pointer to receive thread ID
);
}
void EndInitDlg()
{
Sleep(2000);
HWND hwnd = FindWindowEx(AfxGetMainWnd()->m_hWnd,NULL,NULL,_T("123"));
if(hwnd)
{
PostMessage(hwnd,WM_CLOSE,0,0);
}
}