Date: 02-16-2022
Return to Index
'Compilable Example:
created by gbSnippets
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
End Enum
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
SetWindowPos(hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE) 'on Top
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
OPenFolderOnTop "c:\pbwin10"
End Select
End Select
End Function
Sub OpenFolderOnTop(folder$)
Local iCount As Long, hForeGroundWindow As Dword
hForegroundWindow = GetForegroundWindow()
ShellExecute(0, "Open", (folder$), $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
Wend
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 Sub
http://www.garybeene.com/sw/gbsnippets.htm