
original window position/size



here's what i wanna do:
i want to restore a maximized window, but to the full screen size immediately. if it's first restored to original size, and then resized to the full screen size, this is not nice looking.
any thoughts?
thanks!


if a window can be restored to the original size, the original size must have been stored somewhere. is this info not accessible with AutoHotKey?
Nice question .. I do not know the answer though.
if it's first restored to original size, and then resized to the full screen size, this is not nice looking.
any thoughts?
When I WinRestore and WinMove I do not even get the slightest flicker which I think is due to the NVidia display, I guess.
I am not able to think of any other workaround other than to Hide the maximized window / Resore it / WinMove it / show it, like:
#SingleInstance Force DetectHiddenWindows, On #F10:: ID := WinExist("A") WinGet, Style, Style, ahk_id %ID% WinGet, Maximized, MinMax, ahk_id %ID% If ( Maximized ) { WinHide, ahk_id %ID% WinRestore, ahk_id %ID% } VarSetCapacity( WA, 16 ) DllCall( "SystemParametersInfo", UInt,0x30, UInt,0, UInt,&WA, UInt,0 ) wx := NumGet(WA), wy := NumGet(WA,4), ww := NumGet(WA,8), wh := NumGet(WA,12) WinMove, ahk_id %ID%,, WX, WY, WW, WH WinShow, ahk_id %ID% Return
However, the above code might produced undesirable effect on non resizeable windows such as Calculator.
You will have to check for the WS_SizeBox style of the active window before you can resize it.


hwnd := WinExist("Untitled - Notepad") WinGetPos, mX, mY WinGetNormalPos(hwnd, x, y, w, h) MsgBox Pos:`nx: %mX%`ny: %mY%`n`nNormalPos:`nx: %x%`ny: %y%`nw: %w%`nh: %h% WinGetNormalPos(hwnd, ByRef x, ByRef y, ByRef w="", ByRef h="") { VarSetCapacity(wp, 44), NumPut(44, wp) DllCall("GetWindowPlacement", "uint", hwnd, "uint", &wp) x := NumGet(wp, 28, "int") y := NumGet(wp, 32, "int") w := NumGet(wp, 36, "int") - x h := NumGet(wp, 40, "int") - y }

Can I make a request?...can you write a struct-handling library include?...yes I'm aware of ahkstructlib, but it's old & I'm sure you could write something better (seems like most of the people that can handle structs, can just use offsets & no one has written updated struct-handling code)...I can do wonders with AutoHotkey, but structs really annoy me...I might go searching again for new progress in the AutoHotkey struct-handling field...but can you link to any topics/info you know of?...or just write some?...again, I haven't done any looking into it yet, but how do you find the 28, 32, 36, 40...I mean I understand those are offsets, but I can't figure out how to "just know" them...I really need a (current) struct-handling library include...cuz I don't think I'll ever be able to deal directly with offsets...I don't want to get number 28...I want x...

from help on dllcalls
we know that 8 bits gives a byteA 32-bit integer (the most common integer type), whose range is -2147483648 (-0x80000000) to 2147483647 (0x7FFFFFFF). An Int is sometimes called a "Long".
An Int should also be used for each BOOL argument expected by a function (a BOOL value should be either 1 or 0).
An unsigned Int (UInt) is also used quite frequently, such as for DWORD and COLORREF. It is also used for almost all handles, such as HWND, HBRUSH, and HBITMAP.
an integer has 32 bit so
32 bit divided by 8 gives 4 bytes
/* Google is our friend ... ; from http://msdn2.microsoft.com/en-us/library/ms633518(VS.85).aspx BOOL GetWindowPlacement( HWND hWnd, WINDOWPLACEMENT *lpwndpl ); ; WINDOWPLACEMENT ; from http://msdn2.microsoft.com/en-us/library/ms632611(VS.85).aspx typedef struct _WINDOWPLACEMENT { UINT length; 4bytes UINT flags; 4 bytes UINT showCmd; 4 bytes POINT ptMinPosition; 8bytes POINT ptMaxPosition; 8bytes - 28 bytes used so far RECT rcNormalPosition; see below } WINDOWPLACEMENT; ; POINT ; from http://msdn2.microsoft.com/en-us/library/ms536119(VS.85).aspx typedef struct tagPOINT { LONG x; LONG y; } POINT, *PPOINT; ; RECT ; from http://msdn2.microsoft.com/en-us/library/ms536136(VS.85).aspx typedef struct _RECT { LONG left; 4 bytes; here we are :) OFFSET 28 LONG top; 4 bytes LONG right; 4 bytes LONG bottom; 4 bytes } RECT, *PRECT; */
i guess thats it, but i also might be proven wrong
greets
derRaphael
edit: after re reading my post i made a mistake i simply dont see. maybe lexikos will enlighten us?
edit II: found my mistake - i assumed the POINT was meant as pointer, but this is just a different structure type. now all fixed up. should be correct

All scripts, unless otherwise noted, are hereby released under CC-BY
RECT rcNormalPosition; 4bytes -> also pointer (but to another structure)...(like I said, I haven't even looked into it yet {I do know how to search & investigate things})...but I die when I see structs...a struct in a struct is just absolutely ridiculous...well ok it might be easy in C or C++, but at the current state of AutoHotkey, structs are a nightmare...so even if I had looked it up, I wouldn't've gotten past the struct-in-struct...& I don't see how lexikos did it either...he just accesses offsets from the 1st struct, shouldn't he need to get a pointer to the rcNormalPosition struct, then use NumGet off that struct?...somehow he's accessing the rcNormalPosition struct's members directly off of the lpwndpl struct...lexikos please teach me structs!...
...what?...how do you make a mistake, edit the post about it & not know what mistake?edit: after re reading my post i made a mistake i simply dont see. maybe lexikos will enlighten us?
...what?...now I don't know what changed...but I know POINT is another struct type...edit II: found my mistake - i assumed the POINT was meant as pointer, but this is just a different structure type. now all fixed up. should be correct

...what?...now I don't know what changed...but I know POINT is another struct type...
instead of POINT i simply read in my 1st attempt pointer. i just copy, pasted and submitted. after re reading my post i realised that when summing up all those 4 byte values (my 1st mistaken pointers) i ended at offset 20 but should have been at offset 28 but still i didnt realise that POINT is different to POINTER (i know it spells different, too) thats what confused me
back at msdn i found that POINT is no pointer but a STRUCTURE containing two long values ... i realised where my mistake was and corrected it
sorry for those confusing edit comments
greets
derRaphael

All scripts, unless otherwise noted, are hereby released under CC-BY
I don't see how lexikos did it either...he just accesses offsets from the 1st struct, shouldn't he need to get a pointer to the rcNormalPosition struct, then use NumGet off that struct?...somehow he's accessing the rcNormalPosition struct's members directly off of the lpwndpl struct...
as far as i understood all this, the complete size of WINDOWPLACEMENT is given within its 1st four bytes ... this also includes the RECT struct
so every byte is in straight order. knowing how big the structs are they can be simply accessed via numget. my previous statement (which is corrected btw) about the pointer to RECT is simply WRONG. there is NO pointer to this RECT struct. it's simply a part from WINDOWPLACEMENT and directly integrated.
greets
derRaphael

All scripts, unless otherwise noted, are hereby released under CC-BY
/* ; WINDOWPLACEMENT typedef struct _WINDOWPLACEMENT { offset - desc.* 0 UINT length; 4 UINT flags; 8 UINT showCmd; POINT ptMinPosition { 12 LONG x; 16 LONG y; } POINT ptMaxPosition { 20 LONG x; 24 LONG y; } RECT rcNormalPosition { 28 LONG left; 32 LONG top; 36 LONG right; 40 LONG bottom; } } WINDOWPLACEMENT; */
there are no pointers inside the struct. each value can be directly accessed. sorry for the confusing post above
greets
derRaphael

All scripts, unless otherwise noted, are hereby released under CC-BY
:lol:lexikos... your understanding of struct's is amazing...
At one point I was planning on writing a script to parse a struct definition and generate accessor functions for getting/setting struct members. I gave up on that idea, since I didn't want the overhead of a function call / and/or I was too lazy to write it. :lol:Can I make a request?...can you write a struct-handling library include?
How did I understand WINDOWPLACEMENT, you ask? Well, it isn't that complex. I already knew POINT is 8 bytes and RECT is 16 bytes. If you want an example of a complex structure, take a look at DEVMODE.
I could have calculated the offsets in my head, but I didn't. DEVMODE was such a pain that I wrote a script specifically to parse it. I've used the same script to parse many other structures since then.
For WINDOWPLACEMENT, I first looked up the definition:
typedef struct _WINDOWPLACEMENT { UINT length; UINT flags; UINT showCmd; POINT ptMinPosition; POINT ptMaxPosition; RECT rcNormalPosition; } WINDOWPLACEMENT;I then ran my script, copied that in, and clicked "Parse". Out came the magic code:
; typedef struct _WINDOWPLACEMENT { length := NumGet(struct, 0, "UInt") flags := NumGet(struct, 4, "UInt") showCmd := NumGet(struct, 8, "UInt") ptMinPosition_X := NumGet(struct, 12, "Int") ptMinPosition_Y := NumGet(struct, 16, "Int") ptMaxPosition_X := NumGet(struct, 20, "Int") ptMaxPosition_Y := NumGet(struct, 24, "Int") rcNormalPosition_left := NumGet(struct, 28, "Int") rcNormalPosition_top := NumGet(struct, 32, "Int") rcNormalPosition_right := NumGet(struct, 36, "Int") rcNormalPosition_bottom := NumGet(struct, 40, "Int") ; } SIZE := 44 StdOut( "length=" length ", flags=" flags ", showCmd=" showCmd ", ptMinPosition_X=" ptMinPosition_X ", ptMinPosition_Y=" ptMinPosition_Y ", ptMaxPosition_X=" ptMaxPosition_X ", ptMaxPosition_Y=" ptMaxPosition_Y ", rcNormalPosition_left=" rcNormalPosition_left ", rcNormalPosition_top=" rcNormalPosition_top ", rcNormalPosition_right=" rcNormalPosition_right ", rcNormalPosition_bottom=" rcNormalPosition_bottom ):lol::lol::lol:
I haven't posted the script yet because it handles only a specific set of types/nested structures. I plan to eventually write a script to parse C++ headers, collecting #defines (aka constants) and structure definitions. Collecting the #defines will automatically allow it to interpret any given structure based on the limited set of C++ primitives. It will also allow looking up a specific #define in a given header file. I use A handy tool to lookup Win32 Constants, but I occasionally find that it is missing constants.
(I will post the script anyway in Scripts & Functions soon; stay tuned.)
Edit: StructParser
Btw, "struct-in-struct" is nothing for me... it's array-in-struct and unions that give me headaches.

