Shoutbox

Focusing a window - 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: Focusing a window (/showthread.php?tid=82362)

Focusing a window by MeEtc on 03-14-2008 at 10:09 PM

I'm trying to set a opened window to be focused if the user tries to open a second window instead, so that only one window can be open at the same time. The problem I'm having, is that the variable I'm trying to work with doesn't appear to be a PlusWnd object, but I'm sure it is.

In one block of code, a window is created:

code:
openwnd = MsgPlus.CreateWnd("yass_gui.xml","WndConfig");
openwnd is a global variable.

Now, when this window is open and another is attempted to be opened...
code:
function OnEvent_MenuClicked(ControlId, Location, OriginWnd){
   switch(ControlId){
      case "settings":
         if(openwnd != undefined){
            Debug.Trace(typeof(openwnd));
            Debug.Trace(openwnd.Handle);
            Interop.Call('User32', 'SetForegroundWindow', openwnd.Handle);
            return;
         }
// more code ...
When this runs, I get:
code:
object
Error: unknown (code: -2147418113)
       File: yass_menu.js. Line: 24.
Function OnEvent_MenuClicked returned an error. Code: -2147352567
Line 24 is the second Debug statement.

So, whats going on with the openwnd variable? And how to I set focus to it?
RE: Focusing a window by vikke on 03-14-2008 at 10:24 PM

I would use the "BringWindowToTop" function in the Win32 API to get the window to front.

And in this case I would test this if-statement instead:

code:
if(openwnd)
{
//stuff here
}

RE: Focusing a window by MeEtc on 03-14-2008 at 10:30 PM

Still doesn't explain why openwnd.Handle is not defined


RE: Focusing a window by Spunky on 03-14-2008 at 10:58 PM

Yays, Fixed it :p


RE: Focusing a window by MeEtc on 03-14-2008 at 10:59 PM

I was setting openwnd to the wrong createwnd command :$


RE: RE: Focusing a window by vikke on 03-14-2008 at 11:13 PM

quote:
Originally posted by MeEtc
Still doesn't explain why openwnd.Handle is not defined
I have no idea of any other parts of your code, so it's impossible to know without guessing.
Anyway I'm glad it sorted out! :)