ParentWindowID in OpenWindow()

Just starting out? Need help? Post your questions and find answers here.
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

ParentWindowID in OpenWindow()

Post 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().
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: ParentWindowID in OpenWindow()

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: ParentWindowID in OpenWindow()

Post by RASHAD »

I prefer to use Parentwindowid over SetParent_() for many reasons
Control the movement with Windows CallBack or BindEvent()

Believe me :)
Egypt my love
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Re: ParentWindowID in OpenWindow()

Post by drahneir »

@Kukulkan

the parent window is not a PB window. I had to use the API function FindWindow() to get the handle.
Last edited by drahneir on Fri Jan 09, 2015 8:52 am, edited 2 times in total.
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Re: ParentWindowID in OpenWindow()

Post by drahneir »

@RASHAD

The use of Window callback makes my simple program too complicated.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ParentWindowID in OpenWindow()

Post 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.
BERESHEIT
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: ParentWindowID in OpenWindow()

Post 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.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: ParentWindowID in OpenWindow()

Post by netmaestro »

Maybe Fred would be open to changing the name to 'OwnerWindowID' because this 'parent' misconception happens regularly.
BERESHEIT
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: ParentWindowID in OpenWindow()

Post 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
Egypt my love
drahneir
Enthusiast
Enthusiast
Posts: 105
Joined: Tue Jul 18, 2006 4:18 pm
Location: JO42RM

Re: ParentWindowID in OpenWindow()

Post by drahneir »

OK gentlemen, thanks for your explanations.
@netmaestro
That was an impressive demonstration.
Post Reply