IonicWind Software

IWBasic => General Questions => Topic started by: Andy on July 14, 2012, 06:37:17 AM

Title: Get caption of the active window
Post by: Andy on July 14, 2012, 06:37:17 AM
Hi,

I've seen this somewhere but can't find it now.

How do I get the caption / title of the active window?

I think you need to use the GetWindowTextA function - does anyone have an example of how to do this?

Example: program A and program B are running, if you click on program A how do you get the title / caption of program A?

Thanks,
Andy.
Title: Re: Get caption of the active window
Post by: LarryMc on July 14, 2012, 12:05:23 PM
DECLARE extern GetForegroundWindow(),INT
DECLARE extern GetWindowTextA(hwnd:INT, lpSTRING:STRING, cch:INT),INT

window w1

OPENWINDOW w1,0,0,350,80,@MINBOX|@MAXBOX|@SIZE,0,"Simple Window",&main
CONTROL w1,@static,"",5,5,340,20,0, 1
starttimer w1,500
WAITUNTIL  iswindowclosed(w1)
END

SUB main(),int
    select @MESSAGE
case @IDCLOSEWINDOW
stoptimer w1
        CLOSEWINDOW w1
case @IDTIMER
int hwnd=GetForegroundWindow()
string caption
GetWindowTextA(hwnd,caption,255)
setcontroltext w1,1,caption
    ENDSELECT
RETURN
ENDSUB
Title: Re: Get caption of the active window
Post by: Andy on July 15, 2012, 04:03:24 AM
Thanks Larry,

That's perfect!

Andy.
:)