No announcement yet.

Open Explorer Windows On Top

  • Filter
  • Time
  • Show
Clear All
new posts

  • Open Explorer Windows On Top

    I want to open a folder in a topmost window - on top of the calling app, which itself is topmost. I want to leave the calling app window as topmost so that when the folder window is closed, the calling app remains on top of everything else as it was before opening the folder window.

    ShellExec lets me open the folder just fine, but the arguments don't support opening it as topmost window.

  • #2
    Stealing from some code Pierre provided, this seems to work ...

    'Compilable Example:
    #Compile Exe
    #Dim All
    %Unicode = 1
    #Include ""
    Function PBMain() As Long
       Local iCount As Long, hForeGroundWindow As Dword
       hForegroundWindow = GetForegroundWindow()
       ShellExecute(0, "Open", "c:\pbwin10", $Nul, $Nul, %SW_Restore)
       'The new foreground window will be the window opened by ShellExecute()
       iCount = 0
       While GetForegroundWindow() = hForegroundWindow
         Sleep 10 'Give the OS time to breath
         Incr iCount : If iCount > 300 Then Exit Loop
       If iCount > 300 Then ? "Foreground Window not found!"
       'Here is our window handle
       hForegroundWindow = GetForegroundWindow()
       SetWindowPos(hForegroundWindow, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE)  'on Top
    End Function