Window question

Window question

Postby MarcoBoschi » Wed Jun 08, 2011 1:27 pm

Please try this little program

test #1:
I run the program and close the window:
the result is 100 100 401 501

test #2:
I run the program, I move the window in another place on my desktop, then I close the window:
the result is 100 100 401 500 (the same result of first test

test #3:
I run the program, I move the windows changing dimension on my desktop , then I close the window( after this movements the window is roughly at the same position of test #2:
the result is 331 669 597 1083

The question is: If I only move a window without changing dimensions the four parameters
? oMain:nTop, oMain:nLeft, oMain:nBottom, oMain:nRight do not change!
Is it normal?

Many thanks

Marco




#include "fivewin.ch"
FUNCTION MAIN()
LOCAL oMain
LOCAL nTw := 100 , nLw := 100 , nBw := 400 , nRw := 500


DEFINE WINDOW oMain FROM nTw , nLw TO nBw , nRw PIXEL


ACTIVATE WINDOW oMain

? STR( oMain:nTop ,4 ) + STR( oMain:nLeft ,4 ) + STR( oMain:nBottom ,4 ) + STR( oMain:nRight ,4 )

RETURN NIL


#include "fivewin.ch"
FUNCTION MAIN()
LOCAL oMain
LOCAL nTw := 100 , nLw := 100 , nBw := 400 , nRw := 500


DEFINE WINDOW oMain FROM nTw , nLw TO nBw , nRw PIXEL


ACTIVATE WINDOW oMain

? STR( oMain:nTop ,4 ) + STR( oMain:nLeft ,4 ) + STR( oMain:nBottom ,4 ) + STR( oMain:nRight ,4 )

RETURN NIL
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Window question

Postby James Bott » Wed Jun 08, 2011 2:04 pm

Try calling oWnd:coorsUpdate() before reading the coordinates.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Window question

Postby MarcoBoschi » Wed Jun 08, 2011 2:18 pm

James,
0 0 0 0


King Regards

Marco
#include "fivewin.ch"
FUNCTION MAIN()
LOCAL oMain
LOCAL nTw := 100 , nLw := 100 , nBw := 400 , nRw := 500


DEFINE WINDOW oMain FROM nTw , nLw TO nBw , nRw PIXEL


ACTIVATE WINDOW oMain
oMain:coorsUpdate()
? STR( oMain:nTop ,4 ) + STR( oMain:nLeft ,4 ) + STR( oMain:nBottom ,4 ) + STR( oMain:nRight ,4 )

RETURN NIL
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Window question

Postby ukoenig » Wed Jun 08, 2011 2:26 pm

Marco,

Image

Code: Select all  Expand view

#include "fivewin.ch"

function main()
local oWnd1, oWnd2

DEFINE WINDOW oWnd1 ;
FROM 50, 50 TO 250, 500 PIXEL TITLE " "

oWnd1:bMoved := {|| oWnd1:CoorsUpdate(), oWnd1:SetText ( ;
"Top : " + ALLTRIM( STR( oWnd1:nTop ) ) + ;
" / Left : " + ALLTRIM( STR( oWnd1:nLeft ) ) + ;  
" / Bottom : " + ALLTRIM( STR( oWnd1:nBottom ) ) + ;
" / Right : " + ALLTRIM( STR( oWnd1:nRight ) ) ) }

DEFINE WINDOW oWnd2 TITLE "oWnd2" ;
FROM 100, 100 TO 400, 600 PIXEL

oWnd2:Show()

ACTIVATE WINDOW oWnd1

return nil
 


Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Window question

Postby MarcoBoschi » Wed Jun 08, 2011 3:32 pm

IT WORKS
Many thanks
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Window question

Postby James Bott » Wed Jun 08, 2011 3:43 pm

Marco,

Glad to hear you got it working.

This points out a better class design would have nTop, nBottom, nLeft, and nRight as methods instead of data. This way the coordinates could be updated within the method before returning a value.

Method nTop()
local aRect := GetCoors( ::hWnd )
return aRect[1]

Or even more simply:

Method nTop()
return GetCoors(::hWnd)[1]

The downside to this design is that the GetCoors() function would have to be called four times to get all the coordinates. The upside is that you wouldn't have to remember to call the CoorsUpdate() method before using the coordinates.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Window question

Postby Gale FORd » Wed Jun 08, 2011 7:00 pm

I added a data element ::lWndNeedCoord and ::lSaveWindow.

Then part of the window resize and move blocks I can tell if I need to save window information and when the coordinates need to be updated.
::oWnd:bMoved := { | nRow, nCol | ::lSaveWindow := .t. }
::oWnd:bResized := { | nSizeType, nWidth, nHeight | ::lSaveWindow := .t., ::lWndNeedCoord := .t., eval( ::bResize, nSizeType, nWidth, nHeight ) }

Then in my environment class that can save and restore window, splitter, and browse information I know when to update coordinates.
You have to check if the window is zoomed also. Probably iconized is another issue.

if .not. iszoomed( ::oWnd:hWnd )
if ::oWnd:lWndNeedCoord
::oWnd:CoorsUpdate()
endif
if ::oWnd:nTop != nil
::nWndTop := ::oWnd:nTop
::nWndLeft := ::oWnd:nLeft
::nWndBottom := ::oWnd:nBottom
::nWndRight := ::oWnd:nRight
::lWndNeedCoord := .f.
endif
endif


oWnd:bResized
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston

Re: Window question

Postby nageswaragunupudi » Wed Jun 08, 2011 7:17 pm

GetWndRect( oWnd:hWnd ) --> gives the correct coordinates at any time.
We may use this one function instead of using combination of many methods/functions.

Alternatively, we can use oWnd:GetRect() -> oRect ( TRect object )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10631
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Window question

Postby Gale FORd » Wed Jun 08, 2011 8:59 pm

oWnd:GetRect() does not get the correct coordinates at all times. I added a button to a MDI child window that runs a small function that adds the window coordinates to a trace log file.
Here is the function that the new button calls
Code: Select all  Expand view

function checkmyinfo( oWndBrw )
   local oRect := oWndBrw:GetRect()
   tracelog( oRect:nTop, oRect:nLeft, oRect:nBottom, oRect:nRight, oRect:nWidth(), oRect:nHeight() )
return nil
 


When the window is not maximized or minimized I pressed the button. Then I maximize the window and then press the button.
The trace log results below.

[dimvbrtest.prg->CHECKMYINFO] (4655) Called from:
dimvbrtest.prg->(b)MOVBROWTEST:NEW(670)
.\source\classes\BTNBMP.PRG->TBTNBMP:CL
.\source\classes\BTNBMP.PRG->TBTNBMP:LB
.\source\classes\CONTROL.PRG->TCONTROL:
.\source\classes\BTNBMP.PRG->TBTNBMP:HA
.\source\classes\WINDOW.PRG->_FWH(3394)
->WINRUN(0)
.\source\classes\WINDOW.PRG->TMDIFRAME:
c:\projects\diwin11\DIWIN.PRG->DIMAIN:S
c:\projects\diwin11\DIWIN.PRG->MAIN(89)
Type: N >>> 81<<<
Type: N >>> -1<<<
Type: N >>> 575<<<
Type: N >>> 1416<<<
Type: N >>> 1418<<<
Type: N >>> 495<<<

[dimvbrtest.prg->CHECKMYINFO] (4655) Called from:
dimvbrtest.prg->(b)MOVBROWTEST:NEW(670)
.\source\classes\BTNBMP.PRG->TBTNBMP:CL
.\source\classes\BTNBMP.PRG->TBTNBMP:LB
.\source\classes\CONTROL.PRG->TCONTROL:
.\source\classes\BTNBMP.PRG->TBTNBMP:HA
.\source\classes\WINDOW.PRG->_FWH(3394)
->WINRUN(0)
.\source\classes\WINDOW.PRG->TMDIFRAME:
c:\projects\diwin11\DIWIN.PRG->DIMAIN:S
c:\projects\diwin11\DIWIN.PRG->MAIN(89)
Type: N >>> 51<<<
Type: N >>> -9<<<
Type: N >>> 994<<<
Type: N >>> 1689<<<
Type: N >>> 1699<<<
Type: N >>> 944<<<
Gale FORd
 
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 109 guests