I want to have a button on my form to launch the windows calculator.
Well that’s simple.
dim sh as new shell
sh.Execute("calc.exe")
But, I don’t want windows to launch a new instance when I press this button for the second time. Instead I want the running instance of the Windows Calculator coming on top.
Does anyone have the trick for me ?
First of all you need the process handle as Michel said.
After that you need to pass the handle to this Win32 API function: SetForegroundWindows
Not sure if WFS has that function, but even if it doesn’t, declaring it shouldn’t be too hard.
Edit: It is there actually. It needs WFS. The function is:
[code]
Sub BringToFrontWFS(extends w as Window) #if TargetWin32
Dim i, h, r As Integer
if not w.visible then
w.visible = true
end if
Declare Function SetWindowPos Lib "User32" (hWnd As Integer, hWndInsertAfter As Integer, _
X As Integer, Y As Integer, cx As Integer, cy As Integer, wFlags As Integer) As Integer
Declare Function ShowWindow Lib "User32" ( hWnd As Integer, nCmdShow As Integer ) As Integer
Declare Function BringWindowToTop Lib "User32" ( hWnd As Integer ) As Integer
Declare Function SetForegroundWindow Lib "User32" ( hWnd As Integer ) As Integer
' Get the Window Handle
h = w.WinHWND
r = &h1 + &h2 + &h40
' Activate the Window
i = SetWindowPos( h,-1, 0,0,0,0, r )
i = ShowWindow( h, 1 )
i = BringWindowToTop( h )
i = SetForegroundWindow( h )
w.FlashWindowExWFS( 3 )