When my program exits i want to save its screenposition (Left, Top, Width, Height) to a textfile.
When the program startsup again i want to read those settings to winpos.x, winpos.y,wpos.wt,wpos.ht

Here is what i have so far: (works nice) using Masm32/Radasm

WINPOS struct
x dd ?
y dd ?
wt dd ?
ht dd ?

wpos WINPOS <10,10,450,320> ;/* <0,3,Left,Top,Width,Height,100>

invoke MoveWindow,hWin,wpos.x,wpos.y,wpos.wt,wpos.ht,TRUE

The Task: On WM_CLOSE i want to return the wpos values into a buffer so i can write them to the
textfile. How can i do such? (I tried already alot but somehow the buffer was empty or not a string.)


This message was written entirely in my Messageboard Editor v4.0
Posted on 2003-11-06 04:09:15 by Ranma_at
stupid me forgot to put edx in brackets :grin:

lea edx, wpos.x
invoke dwtoa, [edx],addr Buffer
invoke MessageBox,hWnd,addr Buffer,0,MB_OK

now it works...
Posted on 2003-11-06 06:22:35 by Ranma_at
use GetWindowRect(), so you have x and y position, then just do rect.top - rect.bottom and you have height, and rect.right - rect.left and you have width, or use GetClientRect() to get window's widht and height.
Posted on 2003-11-06 06:37:38 by bart
Hi Ranma_at and bart.

After trying several methods to do it, I find it better to use GetWindowPlacement and SetWindowPlacement. The only catch is that you have to make sure that your window will be visible and within the visible part of the screen. You can do the first by either checking the members of the WINDOWPLACEMENT structure, or calling ShowWindow. You can do the second by sending DM_REPOSITION to your dialog box after the call to SetWindowPlacement (the latter does not work with windows created with CreateWindowEx).

Hope it helps. :)
Posted on 2003-11-06 16:39:42 by QvasiModo
The SetWindowPlacement function sets the show state and the restored, minimized, and maximized positions of the specified window.

Thanks QvasiModo for pointing this out, i recently added a settings.ini demo at the (algo and source code section)
where i posted my 2nd version (using GetWindowRect instead of using a Struct...)

I think i missed checking if the user exits the application windowstate minimized.

But the SetWindowPlacement doesnt let me move the window or get its coordins.
or can you post this method here for me, cause i dont see any other way the get the window position
x,y,wt,ht then using GetWindowRect.


Posted on 2003-11-07 04:07:45 by Ranma_at
You can use GetWindowRect, but also you can try to deduce the window rectangle from the data at the WINDOWPLACEMENT structure. If the window is restored, the position is at rcNormalPosition. If it's maximized, it's size is ptMaxPosition (and it's position seems to be -1,-1 but I wouldn't know if that's so for every OS version). If it's minimized, well... ;)

It still seems easier to make a call to GetWindowRect. Less trouble. :)

Anyway getting and setting the placement ensures that the window's position will be kept intact, so (at least for that matter) you don't need to know the window rectangle since you don't call MoveWindow at all.

There is one catch, you should check if the window is in an unwanted position... for example if some dumb user has been playing with your INI file. :tongue:
Posted on 2003-11-07 13:46:33 by QvasiModo