Shoutbox

GetWindowPlacement api - 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: GetWindowPlacement api (/showthread.php?tid=69735)

GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 04:32 PM

i have a problem when i try to retrive when a chatwindow is minimized
I use matty's function(GetWindowPlacement api):

var WindowPlacment = Interop.Allocate(48);
function _getPlacement(hWnd){
    if (hWnd > 0){
        Interop.Call('user32', 'GetWindowPlacement', hWnd, WindowPlacement);
       
        Debug.Trace('> .showCmd : '+WindowPlacement.ReadDWORD(8));
        if (WindowPlacement.ReadDWORD(8) == 3){
            Debug.Trace(' > .showCmd : Maximized');
        } else if (WindowPlacement.ReadDWORD(8) == 2){
            Debug.Trace(' > .showCmd : Minimized');
        } else if (WindowPlacement.ReadDWORD(8) == 1){
            Debug.Trace(' > .showCmd : Opened');
        }
    } else {
        Debug.Trace(' > .showCmd : Closed');
    }
}


but with it i can retrive when it opened ,maximized ,closed but i can't retrive when is minimized...Can someone help me???Thanks in advice


RE: GetWindowPlacement api by Matti on 12-20-2006 at 04:40 PM

According to the MSDN site and the Win32 API Constants, this should do it:

code:
var WindowPlacment = Interop.Allocate(48);
function _getPlacement(hWnd){
    if (hWnd > 0){
        Interop.Call('user32', 'GetWindowPlacement', hWnd, WindowPlacement);
       
        Debug.Trace('> .showCmd : '+WindowPlacement.ReadDWORD(8));
        if (WindowPlacement.ReadDWORD(8) == 3){
            Debug.Trace(' > .showCmd : Maximized');
        } else if (WindowPlacement.ReadDWORD(8) == 2){
            Debug.Trace(' > .showCmd : Minimized');
        } else if (WindowPlacement.ReadDWORD(8) == 1){
            Debug.Trace(' > .showCmd : Opened');
        } else if(WindowPlacement.ReadDWORD(8) == 6){
            Debug.Trace(' > .showCmd : Opened');
        }

    } else {
        Debug.Trace(' > .showCmd : Closed');
    }
}

RE: GetWindowPlacement api by Spunky on 12-20-2006 at 04:44 PM

Why not use:

if(<maximised>){
...
...
}else if(<opened>){
...
...
}else{
//Must be minimised
...
}


RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 04:49 PM

quote:
Originally posted by Mattike
According to the MSDN site and the Win32 API Constants, this should do it:
code:
var WindowPlacment = Interop.Allocate(48);
function _getPlacement(hWnd){
    if (hWnd > 0){
        Interop.Call('user32', 'GetWindowPlacement', hWnd, WindowPlacement);
       
        Debug.Trace('> .showCmd : '+WindowPlacement.ReadDWORD(8));
        if (WindowPlacement.ReadDWORD(8) == 3){
            Debug.Trace(' > .showCmd : Maximized');
        } else if (WindowPlacement.ReadDWORD(8) == 2){
            Debug.Trace(' > .showCmd : Minimized');
        } else if (WindowPlacement.ReadDWORD(8) == 1){
            Debug.Trace(' > .showCmd : Opened');
        } else if(WindowPlacement.ReadDWORD(8) == 6){
            Debug.Trace(' > .showCmd : Opened');
        }

    } else {
        Debug.Trace(' > .showCmd : Closed');
    }
}


Don't work so...However the problem is not this...I can't retrive when it's minimized not when it's opened..to retrive if it's opened i can use findwindow api function
RE: GetWindowPlacement api by Spunky on 12-20-2006 at 04:50 PM

* Spunky repeats himself :p


RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 04:53 PM

quote:
Originally posted by SpunkyLoveMuff
Why not use:

if(<maximised>){
...
...
}else if(<opened>){
...
...
}else{
//Must be minimised
...
}


your code can't work because the value is always 3 or 1 also when it's minimized so else operator can't work because there isn't another value....The problem is that matty's code always works except for chatwindow
RE: GetWindowPlacement api by Spunky on 12-20-2006 at 05:03 PM

If it always returns 3 or 1, then thats got to be what Windows is reporting it as.

I got this in my debug window when testing:

code:
Script has been stopped
Script is starting
Script is now loaded and ready
> .showCmd : 1
> .showCmd : Opened
Script has been stopped
Script is starting
Script is now loaded and ready
> .showCmd : 3
> .showCmd : Maximized
Script has been stopped
Script is starting
Script is now loaded and ready
> .showCmd : 2
> .showCmd : Minimized

The function works fine (except the var in the above codes you have posted is called WindowPlacment not WindowPlacement)

EDIT: This also mean the if statement I suggested would work (except for if it encountered an error and returned 0)
RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 05:17 PM

quote:
Originally posted by SpunkyLoveMuff
If it always returns 3 or 1, then thats got to be what Windows is reporting it as.

I got this in my debug window when testing:
code:
Script has been stopped
Script is starting
Script is now loaded and ready
> .showCmd : 1
> .showCmd : Opened
Script has been stopped
Script is starting
Script is now loaded and ready
> .showCmd : 3
> .showCmd : Maximized
Script has been stopped
Script is starting
Script is now loaded and ready
> .showCmd : 2
> .showCmd : Minimized

The function works fine (except the var in the above codes you have posted is called WindowPlacment not WindowPlacement)

EDIT: This also mean the if statement I suggested would work (except for if it encountered an error and returned 0)

debug log:
Funzione chiamata: OnEvent_Timer
4654408
2557932
> .showCmd : 1
> .showCmd : Opened
False
Funzione chiamata: OnEvent_Timer
4654408
2557932
> .showCmd : 3
> .showCmd : Maximized
False
Funzione chiamata: OnEvent_Timer
4654408
2557932
> .showCmd : 1
> .showCmd : Opened     //THE WINDOW WAS MINIMIZED
False

however yes i know about the var...DO YOU TESTING THE CODE ON A CHATWND OR ON ANOTHER WINDOW??...BECAUSE I HAVE ALSO TESTED  ON ANOTHER WINDOW AND IT  WORKED...tHE CODE DON'T WORK ONLY ON CHATWND
RE: GetWindowPlacement api by Spunky on 12-20-2006 at 05:29 PM

It's a tabs issue :p It works fine when tabs are disabled, but not when they are in use. I think it's the way Plus! hides the windows rather than minimizing and so on


RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 05:36 PM

quote:
Originally posted by SpunkyLoveMuff
It's a tabs issue :p It works fine when tabs are disabled, but not when they are in use. I think it's the way Plus! hides the windows rather than minimizing and so on


yes i also tought it....but there is any way to detect if it's minimized??
because i need to have tabs
RE: GetWindowPlacement api by Spunky on 12-20-2006 at 05:43 PM

Maybe if it reports it as open, try to check for the dimensions of the window using the (GetWindowPos?) API?


RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 05:47 PM

quote:
Originally posted by SpunkyLoveMuff
Maybe if it reports it as open, try to check for the dimensions of the window using the (GetWindowPos?) API?


Thank Spunky i'll try to do it and i will report if it work or not...
:(:(:( Don't work...i have also tried "IsVisibleWindow" api function but seems that even if the chatwnd is invisible when i minized it,it results visible...mmmhh i don't know why...


tomorrow i'll reverse msn to discover it
RE: RE: GetWindowPlacement api by CookieRevised on 12-20-2006 at 07:36 PM

quote:
Originally posted by Mattike
According to the MSDN site and the Win32 API Constants, this should do it:
code:
var WindowPlacment = Interop.Allocate(48);
function _getPlacement(hWnd){
    if (hWnd > 0){
        Interop.Call('user32', 'GetWindowPlacement', hWnd, WindowPlacement);
       
        Debug.Trace('> .showCmd : '+WindowPlacement.ReadDWORD(8));
        if (WindowPlacement.ReadDWORD(8) == 3){
            Debug.Trace(' > .showCmd : Maximized');
        } else if (WindowPlacement.ReadDWORD(8) == 2){
            Debug.Trace(' > .showCmd : Minimized');
        } else if (WindowPlacement.ReadDWORD(8) == 1){
            Debug.Trace(' > .showCmd : Opened');
        } else if(WindowPlacement.ReadDWORD(8) == 6){
            Debug.Trace(' > .showCmd : Opened');
        }

    } else {
        Debug.Trace(' > .showCmd : Closed');
    }
}

No...

SW_MINIMIZE (0x6) is not the same as SW_SHOWMINIMIZED (0x2).

If you read the MSDN documentation on the GetWindowPlacement API it states:
quote:
If the window identified by the hWnd parameter is maximized, the showCmd member is SW_SHOWMAXIMIZED. If the window is minimized, showCmd is SW_SHOWMINIMIZED. Otherwise, it is SW_SHOWNORMAL.
So the only values you need to check for are:
SW_SHOWNORMAL (0x1)
SW_SHOWMINIMIZED (0x2)
SW_SHOWMAXIMIZED (0x3)

There will be no other value returned by the function in the WINDOWPLACEMENT structure.

Speaking of which, the MSDN docs also states:
quote:
The length member of WINDOWPLACEMENT must be set to sizeof(WINDOWPLACEMENT). If this member is not set correctly, the function returns FALSE.
but nevertheless the API will function though. (dodgy MS keeping stuff like this for compatibily reasons, instead of urging programmers to do the right thing in the first place).

---------------------------------

As for detecting if a chat window is minimized or not. That is far from straightforward when grouped chats are used. This because then Messenger Plus! controls what window is minimized, maximized or normal because the chat windows will become owned by a hidden Plus! window.

To see if grouped chats are in use, you must check if an owner window exist.
If so, you can not check with the GetWindowPlacement API like you normally would for the state of a chatwindow since Plus! will always disable automatically the chats which aren't visible and not minimize them (hence why you'll see 'normal' with the GetWindowPlacement API on those chats).

So if you see that a chat is 'normal' and you see that grouped chats is in use, you must use the IsWindowEnabled API in those cases to see if the chat window is disabled (aka minimized) or not.

But even then it isn't that straightforward. Only when _all_ chat windows are disabled, you could assume that the grouped chat as a whole has been truely minimized. In other cases it is quite possible that the chat window you're checking on will give you 'disabled', eventhough other windows are enabled and thus nothing is minimized at all.


TheGuruSupremacy, a solution for this extremely depends on what you want to do _exactly_. "I want to check if a chat is minimized" is way to vague to give you a proper solution. It totally depends on _why_ you want to know that and what you're going to do with it. Since there is a difference, in case of grouped chatting, between the real state and the thing you see on your screen.
RE: RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-20-2006 at 09:21 PM

quote:
Originally posted by CookieRevised
quote:
Originally posted by Mattike
According to the MSDN site and the Win32 API Constants, this should do it:
code:
var WindowPlacment = Interop.Allocate(48);
function _getPlacement(hWnd){
    if (hWnd > 0){
        Interop.Call('user32', 'GetWindowPlacement', hWnd, WindowPlacement);
       
        Debug.Trace('> .showCmd : '+WindowPlacement.ReadDWORD(8));
        if (WindowPlacement.ReadDWORD(8) == 3){
            Debug.Trace(' > .showCmd : Maximized');
        } else if (WindowPlacement.ReadDWORD(8) == 2){
            Debug.Trace(' > .showCmd : Minimized');
        } else if (WindowPlacement.ReadDWORD(8) == 1){
            Debug.Trace(' > .showCmd : Opened');
        } else if(WindowPlacement.ReadDWORD(8) == 6){
            Debug.Trace(' > .showCmd : Opened');
        }

    } else {
        Debug.Trace(' > .showCmd : Closed');
    }
}

No...

SW_MINIMIZE (0x6) is not the same as SW_SHOWMINIMIZED (0x2).

If you read the MSDN documentation on the GetWindowPlacement API it states:
quote:
If the window identified by the hWnd parameter is maximized, the showCmd member is SW_SHOWMAXIMIZED. If the window is minimized, showCmd is SW_SHOWMINIMIZED. Otherwise, it is SW_SHOWNORMAL.
So the only values you need to check for are:
SW_SHOWNORMAL (0x1)
SW_SHOWMINIMIZED (0x2)
SW_SHOWMAXIMIZED (0x3)

There will be no other value returned by the function in the WINDOWPLACEMENT structure.

Speaking of which, the MSDN docs also states:
quote:
The length member of WINDOWPLACEMENT must be set to sizeof(WINDOWPLACEMENT). If this member is not set correctly, the function returns FALSE.
but nevertheless the API will function though. (dodgy MS keeping stuff like this for compatibily reasons, instead of urging programmers to do the right thing in the first place).

---------------------------------

As for detecting if a chat window is minimized or not. That is far from strait forward when grouped chats are used. This because then Messenger Plus! controls what window is minimized, maximized or normal because the chat windows will become owned by a hidden Plus! window.

To see if grouped chats are in use, you must check if an owner window exist.
If so, you can not check with the GetWindowPlacement API like you normally would for the state of a chatwindow since Plus! will always disable automatically the chats which aren't visible and not minimize them (hence why you'll see 'normal' with the GetWindowPlacement API on those chats).

So if you see that a chat is 'normal' and you see that grouped chats is in use, you must use the IsWindowEnabled API in those cases to see if the chat window is disabled (aka minimized) or not.

But even then it isn't that strait forward. Only when _all_ chat windows are disabled, you could assume that the grouped chat as a whole has been truely minimized. In other cases it is quite possible that the chat window you're checking on will give you 'disabled', eventhough other windows are enabled and thus nothing is minimized at all.


TheGuruSupremacy, a solution for this extremely depends on what you want to do _exactly_. "I want to check if a chat is minimized" is way to vague to give you a proper solution. It totally depends on _why_ you want to know that and what you're going to do with it. Since there is a difference, in case of grouped chatting, between the real state and the thing you see on your screen.

Right Cookie,but can you help me???.....Nothing about my question??
RE: GetWindowPlacement api by CookieRevised on 12-20-2006 at 09:49 PM

Not without answering:

quote:
Originally posted by CookieRevised
TheGuruSupremacy, a solution for this extremely depends on what you want to do _exactly_. "I want to check if a chat is minimized" is way to vague to give you a proper solution. It totally depends on _why_ you want to know that and what you're going to do with it. Since there is a difference, in case of grouped chatting, between the real state and the thing you see on your screen.

If you want to check on the (simulated in group chatting!) state you'll see on the screen, thus where minimized doesn't necessarily means the actual window is minimized, you could use the attached function.

But again, use that with extreme caution as the usefullness and correctness of it depends on what you exactly want to achieve with getting the window states.
RE: RE: GetWindowPlacement api by TheGuruSupremacy on 12-21-2006 at 10:27 AM

quote:
Originally posted by CookieRevised
Not without answering:
quote:
Originally posted by CookieRevised
TheGuruSupremacy, a solution for this extremely depends on what you want to do _exactly_. "I want to check if a chat is minimized" is way to vague to give you a proper solution. It totally depends on _why_ you want to know that and what you're going to do with it. Since there is a difference, in case of grouped chatting, between the real state and the thing you see on your screen.

If you want to check on the (simulated in group chatting!) state you'll see on the screen, thus where minimized doesn't necessarily means the actual window is minimized, you could use the attached function.

But again, use that with extreme caution as the usefullness and correctness of it depends on what you exactly want to achieve with getting the window states.


OK....sorry i didn't see the answering in your previuos post................ ....HOWEVER THANK A LOT COOKIE....YOU ARE ALWAYS HELPFUL:):)......I haven't tried the code yet,but i have seen it and i think that it  should work!......THANK AGAIN COOKIE:)


edit:I have tried it and it works PERFECTLY...when i have at least 100 posts
i'll vote for you:)