How do i get the HWND for PostMessage
-
I have a main Dialog application wich instantiate a new Dialog Like this... m_pThread= AfxBeginThread(RUNTIME_CLASS(CMultiThread)); CMultiThread is a CWinThread . This one takes care of Showing the new dialog box on the screen BOOL CMultiThread::InitInstance() { CPostDialog Dlg; //CoInitializeEx(0, COINIT_APARTMENTTHREADED); CoInitializeEx(0, COINIT_MULTITHREADED); m_pMainWnd= &Dlg; Dlg.DoModal(); return TRUE; } Everythings is working fine. On the ExitInstance() of this thread i want to post a message to the caller (Main Dialog) that CPostDialog is now over. The problem is no matter what i try i can't get the HWND of the caller. I think that i should get the HWND in the InitInstance What i did so far in the main dialog is to declare a public variable like this HWND m_LocalWnd; Then on the OnInitDialog() of the main dialog m_LocalWnd =m_hWnd; Then i change the InitInstance of my CWinThread like this BOOL CMultiThread::InitInstance() { CMessageTestDlg pApp; m_HwndSource = pApp.m_hWnd; CPostDialog Dlg; //CoInitializeEx(0, COINIT_APARTMENTTHREADED); CoInitializeEx(0, COINIT_MULTITHREADED); m_pMainWnd= &Dlg; Dlg.DoModal(); return TRUE; } CMessageTestDlg is already running and i should be able to get the HWND.. but it always return 0 What is it wrong. Yves Lessard
-
I have a main Dialog application wich instantiate a new Dialog Like this... m_pThread= AfxBeginThread(RUNTIME_CLASS(CMultiThread)); CMultiThread is a CWinThread . This one takes care of Showing the new dialog box on the screen BOOL CMultiThread::InitInstance() { CPostDialog Dlg; //CoInitializeEx(0, COINIT_APARTMENTTHREADED); CoInitializeEx(0, COINIT_MULTITHREADED); m_pMainWnd= &Dlg; Dlg.DoModal(); return TRUE; } Everythings is working fine. On the ExitInstance() of this thread i want to post a message to the caller (Main Dialog) that CPostDialog is now over. The problem is no matter what i try i can't get the HWND of the caller. I think that i should get the HWND in the InitInstance What i did so far in the main dialog is to declare a public variable like this HWND m_LocalWnd; Then on the OnInitDialog() of the main dialog m_LocalWnd =m_hWnd; Then i change the InitInstance of my CWinThread like this BOOL CMultiThread::InitInstance() { CMessageTestDlg pApp; m_HwndSource = pApp.m_hWnd; CPostDialog Dlg; //CoInitializeEx(0, COINIT_APARTMENTTHREADED); CoInitializeEx(0, COINIT_MULTITHREADED); m_pMainWnd= &Dlg; Dlg.DoModal(); return TRUE; } CMessageTestDlg is already running and i should be able to get the HWND.. but it always return 0 What is it wrong. Yves Lessard
The line
CMessageTestDlg pApp;
<\PRE>
makes a new instance of the CMessageTestDlg class - it does not give you access to the global CWinApp derivative in your main thread. Use AfxGetApp() instead (I'm pretty sure it works across threads, but you may check to be absolutely sure). You can, however, not use AfxGetMainWnd() as this is thread-specific.Cheers
Steen."To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
-
The line
CMessageTestDlg pApp;
<\PRE>
makes a new instance of the CMessageTestDlg class - it does not give you access to the global CWinApp derivative in your main thread. Use AfxGetApp() instead (I'm pretty sure it works across threads, but you may check to be absolutely sure). You can, however, not use AfxGetMainWnd() as this is thread-specific.Cheers
Steen."To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
&#&/¤#(#)(/!!=?¤(¤%&!!!!!! I thought I finally got those tags right! Instead I just made my reply like 4 monitors wide! What did I do wrong? Sorry about this. Cheers Steen. "To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"