Keep window at front (macOS)

  1. last year

    Christoph D

    6 Oct 2017 Pre-Release Testers, Xojo Pro
    Edited last year

    Is there a way to force a window as the front most window of the app without setting it to a (global) floating window?

    BTW macoS only

    I think that this will work for you.

    soft declare sub addChildWindow lib "Cocoa" selector "addChildWindow:ordered:" (parentWindow As Ptr, childWindow As Ptr, level As Integer)
    addChildWindow(Ptr(Self.Handle), Ptr(Window2.Handle), 1)

    It will make Window2 a child of the window that you call it from and will order it to be on top.
    That child window will always be on top of the parent window, but not on top of other applications.
    A side effect (not sure if it's desired or not) is that the child window follows the parent window if you move it.

  2. Jared F

    6 Oct 2017 Pre-Release Testers, Xojo Pro Answer Milwaukee, WI

    I think that this will work for you.

    soft declare sub addChildWindow lib "Cocoa" selector "addChildWindow:ordered:" (parentWindow As Ptr, childWindow As Ptr, level As Integer)
    addChildWindow(Ptr(Self.Handle), Ptr(Window2.Handle), 1)

    It will make Window2 a child of the window that you call it from and will order it to be on top.
    That child window will always be on top of the parent window, but not on top of other applications.
    A side effect (not sure if it's desired or not) is that the child window follows the parent window if you move it.

  3. Christoph D

    6 Oct 2017 Pre-Release Testers, Xojo Pro

    Exactly what I needed ! Thanks Jared !

  4. Christoph D

    6 Oct 2017 Pre-Release Testers, Xojo Pro
    Edited last year

    do I need to 'detach' the window when closing Window2?

    https://developer.apple.com/documentation/appkit/nswindow/1419063-removechildwindow?language=objc

  5. Christoph D

    6 Oct 2017 Pre-Release Testers, Xojo Pro

    It is also neat the Window2 drags along with Window1 ! Way cool.

  6. Jared F

    6 Oct 2017 Pre-Release Testers, Xojo Pro Milwaukee, WI

    I believe that you can just close Window2 without needing to do anything else, but if you do want to unlink them you can use:

    soft declare sub removeChildWindow lib "Cocoa" selector "removeChildWindow:" (parentWindow As Ptr, childWindow As Ptr)
    removeChildWindow(Ptr(Self.Handle), Ptr(Window2.Handle))
  7. Arthur G

    17 Dec 2017 Pre-Release Testers

    So I finally got back to this declare

    dim window2 as new LilDWindow
    soft declare sub removeChildWindow lib "Cocoa" selector "removeChildWindow:" (parentWindow As Ptr, childWindow As Ptr)
    removeChildWindow(Ptr(Self.Handle), Ptr(Window2.Handle))

    I did have to make it as an implicit instance, but it is window(0) finally.

    I unfortunately didn't have it saved and recovery didn't have it in there and it took me until now to realize it was missing.

    It works but for 2 problems.
    1. No matter what I do the titlebar doesn't show the window has focus. I have this problem with another window.

    2. The menuitem for close on the calling window is called. Yes I have stuff like menuhandlers and the same menubar.

    Suggestions

  8. Jared F

    19 Dec 2017 Pre-Release Testers, Xojo Pro Milwaukee, WI
    Edited last year

    I modified your original project and re-uploaded it for you to take a look at.

    CloseWindow.xojo_xml_project

    When I run this project, clicking the on the child window focuses that window (the titlebar shows the focus) and then using the menuitem to close will properly close the child window while it is focused.

  9. Arthur G

    19 Dec 2017 Pre-Release Testers
    Edited last year

    Thanks, Jared. Didn't think I would have to click on it to get it in focus. I can live with that.

    On my own application, the enableMenuItems doesn't run consistently. (I saw FileClose once and not since)
    I even tried putting FileClose.Enabled = True in the window's open and it still didn't show.

or Sign Up to reply!