Page 1 of 1

ParentWindowID in OpenWindow()

Posted: Thu Jan 08, 2015 12:01 pm
by drahneir
In a few Windows applications I expand the functionality by positioning own windows on the application window.
On these windows gadgets with the desired functions are placed. That works for me, but when the main window is
moved, the additional windows stay where they are.
Then I had the idea, to use the optional parameter ParentWindowID in OpenWindow(), but there was no change.
But when I use the API function SetParent(), it works. My own windows are moved with the program window.
Now I wonder which function performs the ParentWindowID parameter in OpenWindow().

Re: ParentWindowID in OpenWindow()

Posted: Thu Jan 08, 2015 4:06 pm
by Kukulkan
Have you given the parameter with WindowID() function? The submitted parent window id of PureBasic must get used together with WindowID(). The WindowID() function seems to return the Windows-API handle of the window.

Re: ParentWindowID in OpenWindow()

Posted: Thu Jan 08, 2015 5:59 pm
by RASHAD
I prefer to use Parentwindowid over SetParent_() for many reasons
Control the movement with Windows CallBack or BindEvent()

Believe me :)

Re: ParentWindowID in OpenWindow()

Posted: Fri Jan 09, 2015 8:33 am
by drahneir
@Kukulkan

the parent window is not a PB window. I had to use the API function FindWindow() to get the handle.

Re: ParentWindowID in OpenWindow()

Posted: Fri Jan 09, 2015 8:38 am
by drahneir
@RASHAD

The use of Window callback makes my simple program too complicated.

Re: ParentWindowID in OpenWindow()

Posted: Mon Jan 12, 2015 10:46 pm
by netmaestro
The parent parameter in the OpenWindow command doesn't set a parent-child relationship like SetParent does. It's about zorder and what gets drawn in front of what. Try this little test:

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
;OpenWindow(1,0,0,320,240,"",0, WindowID(0))
OpenWindow(1,0,0,320,240,"")

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
1. We begin by creating two windows in different locations. We did not use the ParentID parameter.
2. Drag the larger window to the top corner of the screen. Note that it draws over top of the second window.
3. Close the program and move the comment to the other OpenWindow command. Now we are using ParentID.
4. Drag the larger window to the top corner of the screen. Note that it draws behind the second window now.

That's a demonstration of all of everything that the ParentID parameter is designed for. If you need to create a true child window, you must use SetParent.

Re: ParentWindowID in OpenWindow()

Posted: Mon Jan 12, 2015 11:14 pm
by luis
Or in other words: SetParent() set the parent for a child window, ParentWindowID set the owner of the window you are about to open.
So yes the name can be confusing.
msdn wrote: An owned window is always above its owner in the z-order.
The system automatically destroys an owned window when its owner is destroyed.
An owned window is hidden when its owner is minimized.

Re: ParentWindowID in OpenWindow()

Posted: Mon Jan 12, 2015 11:25 pm
by netmaestro
Maybe Fred would be open to changing the name to 'OwnerWindowID' because this 'parent' misconception happens regularly.

Re: ParentWindowID in OpenWindow()

Posted: Tue Jan 13, 2015 12:26 am
by RASHAD
ParentWindowID is exactly as
SetWindowLongPtr_( WindowID(2), #GWL_HWNDPARENT,WindowID(1))

Unfortunately no guaranty that both SetParent_() or ParentWindoID can do the job between external window created by external application and a window created by PB
Try with NotePad.exe for example

drahneir mentioned that later on

Re: ParentWindowID in OpenWindow()

Posted: Wed Jan 14, 2015 6:47 pm
by drahneir
OK gentlemen, thanks for your explanations.
@netmaestro
That was an impressive demonstration.