Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Recall the window size & position

Intel_C_Intel
Employee
442 Views
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
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
442 Views
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
0 Kudos
Intel_C_Intel
Employee
442 Views
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  
0 Kudos
Jugoslav_Dujic
Valued Contributor II
442 Views
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
0 Kudos
Intel_C_Intel
Employee
442 Views
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
0 Kudos
Jugoslav_Dujic
Valued Contributor II
442 Views
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
0 Kudos
Intel_C_Intel
Employee
442 Views
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
0 Kudos
Jugoslav_Dujic
Valued Contributor II
442 Views
I stand corrected -- I hadn't RTFM on WM_WINDOWPOSCHANGED :-(.

Jugoslav
0 Kudos
Reply