Re: PostMessage from thread to PropertyPage and MessageBox
Thanks a lot for the replies. Some clarifications.
1) I am sure that the AfxGetMainWnd is returning the handle to login
dialog whereas I want the handle of the current active window. How do
I get handle to current active window? AfxGetApp()->m_pMainWnd-
PostMessage(...) didnt help. :(
2) I am not issuing MessageBox in the thread as I alsoknow it would be
a design error. I am issuing it in Message Handler code.
3) The login dialog is the parent dialog of my PropertySheet.
Sharing my code, so that I can be more clear
//Thread to poll for wifi cnnectivity status
UINT WINAPI WifiThread(LPVOID value)
{
CWiFi* wifi = (CWiFi*)value;
int i;
for(;;)
{
i = wifi->GetConnectStatus(0);
if(i == -1)
{
AfxGetApp()->m_pMainWnd->PostMessage(MY_WM_MESSAGE, (WPARAM)0,
(LPARAM)0);
return -1;
}
else
{
Sleep(5000);
}
}
}
CWiFi* wi = new CWiFi;
CWinThread *pThread = AfxBeginThread(WifiThread,wi) ;
// Open the next dialog based on successful registration.
Control = new CPropertySheetCtrl(L"ImSmartFone");
pDialApp->pSheetCtrl = Control;
Control->m_psh.dwFlags |= PSH_NOAPPLYNOW;
int nResponse = Control->DoModal();
// Client has quit.. Send an UnRegister message.
phUnregister(userid, regserver);
// Close the client
EndDialog(nResponse);