Restored from previous forum. Originally posted by PB.
This procedure lets you activate (give the focus to) a foreign window by either
its handle or window title. By default it activates by the handle, unless you
specify a window title (upon which the handle parameter is ignored).
Fred, could this become a native command please?
Code: Select all
Procedure AppActivate(handle,title$)
If title$ <> "" : handle=FindWindow_(0,title$) : EndIf
thread1=GetWindowThreadProcessId_(GetForegroundWindow_(),0)
thread2=GetWindowThreadProcessId_(handle,0)
If thread1thread2 : AttachThreadInput_(thread1,thread2,#True) : EndIf
SetForegroundWindow_(handle)
If thread1thread2 : AttachThreadInput_(thread1,thread2,#False) : EndIf
ProcedureReturn IsWindow_(handle)
EndProcedure
;
MessageRequester("Title test","Click OK to activate Calculator by its title...",0)
;
If AppActivate(0,"Calculator")=0
Debug "Calculator not found..."
Else
Debug "Calculator has the focus!"
EndIf
;
MessageRequester("Handle test","Click OK to activate Calculator by its handle...",0)
;
; Assume calc is the handle of the calculator from an earlier search...
If AppActivate(calc,"")=0
Debug "Calculator not found..."
Else
Debug "Calculator has the focus!"
EndIf
PB - Registered PureBasic Coder
Edited by - PB on 20 June 2002 23:02:26