Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do i get the HWND for PostMessage

How do i get the HWND for PostMessage

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yves
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • Y Yves

      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

      S Offline
      S Offline
      Steen Krogsgaard
      wrote on last edited by
      #2

      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"

      S 1 Reply Last reply
      0
      • S Steen Krogsgaard

        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"

        S Offline
        S Offline
        Steen Krogsgaard
        wrote on last edited by
        #3

        &#&/¤#(#)(/!!=?¤(¤%&!!!!!! 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"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups