Recall the window size & position

Recall the window size & position

I want to store the current Window position so I can use it the next time I run my application.

I see there is SetWindowPos - but no GetWindowPos.

How can I do this?

Also is it easy to write & recall the vaules to/from the registry.

Thanks,

David

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

No, there's no GetWindowPos. The best you can get is GetWindowRect, but then you'll have to convert it to parent-client coordinates (ScreenToClient(GetParent(hWnd))).

Alternatively, you can handle WM_WINDOWPOSCHANGED, which contains a pointer to WINDOWPOS structure. However, docs are unclear whether its coordinates are screen-relative or parent-client relative.

Jugoslav

I got it working (sort of).
I was using CreateWindowEx to create the window - the parameters are X & Y position, width & height.
Then I get the X & Y position form WM_MOVE and the width & height from WM_SIZE - with a bit of fudging it works.

I was able to use the Registry for the 4 values using Norman Lawrence's book.
It strange that the RegQueryValueEx does not work for the first call, you have to call it twice to get it to work.

Regards, David

From the 'Tip of the Day' example:

   iret = RegQueryValueEx(hKey,"Show Tips at Startup"C,&
          0,loc(dataType),loc(TipString),loc(cbdata))					
   ! if not successful, try once more
   if( iret /= 0) then
       iret = RegQueryValueEx(hKey,"Show Tips at Startup"C, &
	          0,loc(dataType),loc(TipString),loc(cbdata))	
   end if  

You don't appear to be initializing cbdata. lpcbData is an INOUT argument -- you should initialize it to sizeof(dataType). In your actual code, first call to RegQueryValueEx fails, but fills in lpcbData; thus, the second call succeeds.

Gosh this code is really in Norman Lawrence's samples? OK, it is bulletproof but I wouldn't call it elegant.

Jugoslav

1. Thanks for the explanation of Normal Lawrences example, I have changed it so the variables are initialised and it's OK.

2. You suggested using WM_WINDOWPOSCHANGED, it looks as if that's what I want.

I now have
type (T_WINDOWPOS) WindowPos

and
case (WM_WINDOWPOSCHANGED)
WindowPos=loc(lparam)

But this last line is wrong - I'm never sure of the syntax with LOC - what should it be?
It would be nice if the 'Help' came with small examples.

Thanks,
David

The help does not contains samples because it is written for C programmers, who are supposed to know how to dereference a pointer to an object.

Unfortunately, there's no a standard way to dereference a C-style pointer in F95 (there will be in F2000). However, I don't think that portability matters to you since you're tied to CVF anyway. In CVF, you can use a "Cray pointer":

!Btw, this kind of declaration is the sole place
!where I use ; statement-separator, because declaration
!of Cray pointers is kinda "F77-ish":
TYPE(T_WINDOWPOS):: WP; POINTER(pWP, WP)
...
CASE(WM_WINDOWPOSCHANGED)
   pWP = lParam
   !Now you can access WP%x, WP%y etc.

HTH
Jugoslav

Thanks, the symtax was a bit complex.

I put a breakpoint on case(WM_WINDOWPOSCHANGED) and when I move or resize the window it doesn't go through this.
So maybe I will just use WM_MOVE & WM_SIZE

Regards,
David

I stand corrected -- I hadn't RTFM on WM_WINDOWPOSCHANGED :-(.

Jugoslav

Leave a Comment

Please sign in to add a comment. Not a member? Join today