Attach a Window child to Window Parent?

Does anyone happen to have windows Declares to attach a window to a parent window so when you move the parent window the child window moves with it? Its what Christian has for OS X NSWindowMBS.AddChildWindow().

Thank you much in advance.

NSWindowMBS class is for macOS.

I guess Mike is aware of this, that’s why he’s looking for a Windows replacement :wink:

If I understand what you’re trying to do, here’s a link to something I threw together a long time ago that will keep a window in front of another window and move it when the parent moves, let me know if this isn’t what you’re after and I’ll have a tinker:

If you don’t want it to open a movie for the demo, comment out all the code after dim f as folderitem in Window1.Open

Thank you Julian and yes that’s what I am looking to accomplish for Windows. I will try this today and thank you again.

Thanks Christian, but please read the last sentence of my post :slight_smile:

1 Like

@JulianS ,

I copy and pasted your code and replaced your windows# reference with Self. I put your Windows2 (Child) into my child window.open and the Windows1 (Parent) code under my parent window.

It looks like its doing something as It freezes both windows after the child is instantiated (Implicit Off child window). Controls dont respond along with i cant move the windows.

ChildWindow.Open:

Var ok as integer
Var style as integer

'style = Self.GetWindowLong(GWL_STYLE)
style = WS_POPUP ’ reset all styles and go with a popup
ok = SetWindowLong(Self.Handle, GWL_STYLE, style)

style = Self.GetWindowLong(GWL_EXSTYLE)

BitSet(style, WS_EX_LAYERED Or WS_EX_TRANSPARENT Or WS_EX_NOACTIVATE)

ok = SetWindowLong(Self.Handle, GWL_EXSTYLE, style)
ok = SetWindowPos(Self.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE)
ok = SetLayeredWindowAttributes(Self.Handle, &hFEFFFE, 0, 1)

'ok = SetLayeredWindowAttributes(Window2.Handle, 0, 0.5 * 255, LWA_ALPHA) ’ use this instead if you just want semi-transparent

ParentWindow.Open:

Var style As Integer
Var ok As Integer
Var i as Integer
ok = SetWindowPos(Self.handle, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
style = Self.GetWindowLong(GWL_STYLE)
ok = SetWindowLong(Self.handle, GWL_STYLE, BitSet(style, WS_CLIPSIBLINGS))

Im trying to tinker also based on your constants you implemented from: https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles

If you have time could you see if this is expected? Thank you again for your help!!!
Mike

All the code in Window1.Open can be ignored, that’s to do with bringing a control in front of the movie player which was the demos original purpose.

There’s a tiny bit of code in App.Open that you might have missed, this will stop the child window from momentarily stealing focus from the parent window as the child is opened, and you’ll need all the events from Window1 to make sure things are moved and features are disabled/enabled if you’re doing anything other than a full screen movie player.

If you post up your little demo project, I’ll fix it.

2 Likes

Awesome thanks! Yes I did miss the app.open and Window1.Activate. Trying again. :slight_smile:

I’d be interested in the solution too :wink:

1 Like

Success!!

Ok this took a few declares to attach a child window to a parent window (Move the parent and the child follows seamlessly). Here is the sample project I built. @JulianS a huge thank you for your project example to help me begin to understand some of these win32 functions.

https://www.dropbox.com/s/ue5ayl9o5r7cfh6/ChildParentMoveTest.xojo_binary_project?dl=1

The View code is in ChildWindow.Open and the controller code is in the WindowsAPI module.

// SET PARENT OF THIS WINDOW TO MAIN WINDOW
Var setParentResultInt as Integer = WindowsAPI.setParent(Self.Handle, ParentWindow.Handle)

// SET CHILD BIT ON WINDOW STYLE
Var childStyle as Integer = WS_CHILDWINDOW
Var setWinStyleResultInt as Integer = WindowsAPI.SetWindowLong(Self.Handle, GWL_STYLE, childStyle)

// SET BORDER AROUND CHILD WINDOW
Var borderStyle as Integer = WS_BORDER
Var borderResultInt as Integer = WindowsAPI.SetWindowLong(Self.Handle, GWL_STYLE, borderStyle)

// SET CHILD X/Y POS  VARIABLES
Var newXpos as Integer = (ParentWindow.Width/2 - self.Width/2)
Var newYpos as Integer = (ParentWindow.Height/2 - self.Height/2)
Var newW as Integer = Self.Width
Var newH as Integer = Self.Height
Var moveWinResultInt as Integer = WindowsAPI.MoveWindow(Self.Handle, newXpos, newYpos, newW, newH, True)

// UPDATE PARENT
Var updateWinResultInt as Integer = WindowsAPI.UpdateWindow(ParentWindow.Handle)