-
March 10th, 2003, 04:14 PM
#1
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!
-
March 10th, 2003, 04:38 PM
#2
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.
-
March 10th, 2003, 05:57 PM
#3
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.
-
March 11th, 2003, 12:35 AM
#4
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.
-
March 11th, 2003, 12:21 PM
#5
Hmmm, very interesting - I've got XP. I wonder what the difference is?
-
March 11th, 2003, 03:22 PM
#6
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.
-
August 19th, 2005, 03:12 AM
#7
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.
-
August 19th, 2005, 04:00 AM
#8
Re: CreateProcess and SetParent
in CYourView::PreCreateWindow() write this:
cs.style |= WS_CLIPCHILDREN;
-
August 19th, 2005, 04:10 AM
#9
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.
-
August 19th, 2005, 04:37 AM
#10
Re: CreateProcess and SetParent
If i understand your ploblem right? See the attachment (.NET 2002 project)
-
August 19th, 2005, 07:11 AM
#11
Re: CreateProcess and SetParent
1000 Thanx! With your code it looks good. I didn't notice any difference between W2000 and XP.
-
April 7th, 2006, 06:29 PM
#12
Re: CreateProcess and SetParent
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)
-
October 24th, 2008, 09:46 AM
#13
Re: CreateProcess and SetParent
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?
-
November 9th, 2010, 04:48 AM
#14
Re: CreateProcess and SetParent
I've got the same problem too. Does anyone have the previously attached code?
-
November 9th, 2010, 05:25 AM
#15
Re: CreateProcess and SetParent
Originally Posted by jbaekken
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|