CreateProcess and SetParent
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: CreateProcess and SetParent

  1. #1
    Join Date
    Mar 2003
    Location
    Colorado
    Posts
    15

    Talking CreateProcess and SetParent

    There seems to be a bunch of people who are interested in doing this kind of thing, but I haven't found a good solution looking around on the web, this formum, the faq's, etc.

    Basically I'm starting up another application (that I don't have source for) using CreateProcess, using EnumWindows to find a window handle to the main window in the new process, and using SetParent to attach the main window of the new process to my own SDI client area. Seems simple enough, but the painting of the new client window gets all messed up (not really surprizing in hind sight). I've tried sending the new client window WM_PAINT messages to no avail. Seems like the OS and the new client window just loose touch with one another. I've also tried changing the style of the new client window to WS_CHILD, which doesn't help either. Is this a solvable problem?

    Thanks in advance for any ideas or suggestions!

  2. #2
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917
    You are probably setting wrong parent. SDI applications client area is a view. Try this:

    Code:
    void CMainFrame::OnSetParent()
    {
      HWND hWnd = ::FindWindow("Notepad", NULL); //find notepad
    
      ::SetParent(hWnd, GetActiveView()->m_hWnd);
      ::UpdateWindow(hWnd);
    }
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Mar 2003
    Location
    Colorado
    Posts
    15
    Thanks for the reply, but it didn't help. I also tried adding

    ::SendMessage( hWnd, WM_CHANGEUISTATE, UIS_INITIALIZE, NULL);

    to make sure that Windows is happy with the window hierarchy. So here is the code I have now:

    CreateProcess ...

    Sleep(1000);

    HWND hNewChildWnd = FindProcessMainWindow(pi.dwProcessId);
    ::SetWindowText(hNewChildWnd, "Jim Was Here");
    ::SetWindowLong(hNewChildWnd, GWL_EXSTYLE, WS_CHILD);
    HWND hParentWnd = GetActiveView()->m_hWnd;
    ::SetParent(hNewChildWnd, hParentWnd);
    ::SendMessage( hWnd, WM_CHANGEUISTATE, UIS_INITIALIZE, NULL);
    ::UpdateWindow(hNewChildWnd);

    The painting in the child window is still all messed up. If I click around in the SDI client area, I can get the window frame and some of the UI of the child window to show up. It responds to the "OK" button fine, but the other UI elements don't paint properly.

  4. #4
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917
    I have tested it in 2K and it worked fine, in XP does not. I will try to find out what is going on.

    What OS are you using?
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Join Date
    Mar 2003
    Location
    Colorado
    Posts
    15
    Hmmm, very interesting - I've got XP. I wonder what the difference is?

  6. #6
    Join Date
    Mar 2003
    Location
    Colorado
    Posts
    15
    I tested on W2K and it does work, though there is still an initial painting problem. After I minimize and restore the parent app, the painting works fine. A co-worker said that XP owns the application windows rather than the application, as under W2K.

  7. #7
    Join Date
    Jul 2001
    Location
    Germany, near Frankfurt
    Posts
    135

    I have the same problem

    Hi, I have the same problem, but I have the source for the 2 applications. Is there a solution possible?
    I can't set WS_CHILD for the child application, because then its menu is gone.

  8. #8
    Join Date
    Jul 2005
    Location
    Russian Federation. Moscow
    Posts
    152

    Cool Re: CreateProcess and SetParent

    in CYourView::PreCreateWindow() write this:
    cs.style |= WS_CLIPCHILDREN;

  9. #9
    Join Date
    Jul 2001
    Location
    Germany, near Frankfurt
    Posts
    135

    Re: CreateProcess and SetParent

    In the parent application? But I want only one window within the parent application to be "mother" of my child application. The child application is a MDI.

  10. #10
    Join Date
    Jul 2005
    Location
    Russian Federation. Moscow
    Posts
    152

    Cool Re: CreateProcess and SetParent

    If i understand your ploblem right? See the attachment (.NET 2002 project)

  11. #11
    Join Date
    Jul 2001
    Location
    Germany, near Frankfurt
    Posts
    135

    Re: CreateProcess and SetParent

    1000 Thanx! With your code it looks good. I didn't notice any difference between W2000 and XP.

  12. #12
    Join Date
    Apr 2006
    Posts
    2

    Re: CreateProcess and SetParent

    Quote Originally Posted by Acidy
    If i understand your ploblem right? See the attachment (.NET 2002 project)
    Hello Acidy,

    I cannot find the attachment (.NET 2002 project) about "CreateProcess and SetParent".
    Where can I get this files...?
    Would you mind send it for me to jucyblue@gmail.com.

    Thanks a lot...

    from jucy

    ------------------
    Re: CreateProcess and SetParent

    --------------------------------------------------------------------------------

    If i understand your ploblem right? See the attachment (.NET 2002 project)

  13. #13
    Join Date
    Oct 2008
    Posts
    1

    Re: CreateProcess and SetParent

    Quote Originally Posted by Acidy
    in CYourView::PreCreateWindow() write this:
    cs.style |= WS_CLIPCHILDREN;
    I have the same problem but i can't see the attachment. Where is it now?

  14. #14
    Join Date
    Nov 2010
    Posts
    1

    Re: CreateProcess and SetParent

    I've got the same problem too. Does anyone have the previously attached code?

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,785

    Re: CreateProcess and SetParent

    Quote Originally Posted by jbaekken View Post
    I've got the same problem too. Does anyone have the previously attached code?
    Please, describe *your* problem.
    What "attached code" do you mean?
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


HTML5 Development Center