October 30, 2025, 04:51:16 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Get caption of the active window

Started by Andy, July 14, 2012, 06:37:17 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.