Shoutbox

Check whether control is focused - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Check whether control is focused (/showthread.php?tid=94355)

Check whether control is focused by ryxdp on 04-11-2010 at 09:12 AM

I have an EditControl that, when the text changes, checks whether it's focused (there is a secondary EditControl that does exactly the same). I searched the forums and found the GetFocus function via SetFocus, but the function doesn't seem to have any parameters. What I need to do is something like:

code:
if(Interop.Call('user32','GetFocus',EdtBox.Handle)){
//do stuff
}

Is there some way to do this?
RE: Check whether control is focused by Matti on 04-11-2010 at 12:42 PM

GetFocus() returns the handle of the currently focused control, so you need to compare that return value to the handle of the control you want to react upon.

Javascript code:
// Get the handle of the focused control
var hFocused = Interop.Call('user32', 'GetFocus');
// Check if it's our edit control
if( hFocused === PlusWnd.GetControlHandle('MyEditControl') ) {
    // Do stuff
}

Or the short version:
Javascript code:
// Check whether our edit control has focus
if( Interop.Call('user32', 'GetFocus') === PlusWnd.GetControlHandle('MyEditControl') ) {
    // Do stuff
}


RE: Check whether control is focused by ryxdp on 04-11-2010 at 11:59 PM

Thanks a lot, it seems to be working perfectly now :P

I just wasn't sure if it'd return what I wanted, from what the MSDN article said it seemed like it included entire windows as well.