none
HWND and Windows Form RRS feed

  • Question

  • Hi,

    I am writing an application that mixes Windows Form and HWND. Basically, I have a Form class that has controls on it and I want to instantiate it somewhere else and manipulate it via a handle.

    MyForm win;
    
    	 
    
    HWND hWnd = (HWND)win->Handle.ToPointer();
    
    
    //win.Show();
    ShowWindow(hWnd, 3); 
        
    
    MSG msg = { };
    while (GetMessage(&msg, NULL, 0, 0))
    {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
    }

    The problem is that when I display the window using the ShowWindow on the HANDLE, the Form shows up but with no control on it, whereas the win.Show() displays the Form with all the controls.

    Does anyone have an idea about why?

    Many thanks

    Sunday, September 15, 2013 2:54 PM

Answers

  • I think that your experiment reveals the fact that the forms cannot be manipulated in such manner. The skipped Show function probably performs certain required initialization routines.

    Maybe your problems can be solved differently. For example if you want to process some Windows messages, you can do it inside the WndProc of Form.

    • Marked as answer by Damon Bu - MSFT Wednesday, September 25, 2013 9:10 AM
    Sunday, September 15, 2013 4:36 PM
  • Hi aloukces,

    I agree with Viorel_.

    I would suggest you have a look at the document of MSDN Library and check the sample code via the link below.

    http://msdn.microsoft.com/en-US/library/system.windows.forms.control.wndproc(v=vs.85).aspx

    Regards,

    Damon


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Damon Bu - MSFT Wednesday, September 25, 2013 9:11 AM
    Sunday, September 22, 2013 4:13 AM

All replies

  • I think that your experiment reveals the fact that the forms cannot be manipulated in such manner. The skipped Show function probably performs certain required initialization routines.

    Maybe your problems can be solved differently. For example if you want to process some Windows messages, you can do it inside the WndProc of Form.

    • Marked as answer by Damon Bu - MSFT Wednesday, September 25, 2013 9:10 AM
    Sunday, September 15, 2013 4:36 PM
  • Hi, Thanks for the reply. Although I am not sure I understood what you meant. Would you have an example?
    Sunday, September 15, 2013 5:56 PM
  • Hi aloukces,

    I agree with Viorel_.

    I would suggest you have a look at the document of MSDN Library and check the sample code via the link below.

    http://msdn.microsoft.com/en-US/library/system.windows.forms.control.wndproc(v=vs.85).aspx

    Regards,

    Damon


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Damon Bu - MSFT Wednesday, September 25, 2013 9:11 AM
    Sunday, September 22, 2013 4:13 AM