FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Window question
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Window question
Posted: Wed Jun 08, 2011 01: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

Marco Boschi
info@marcoboschi.it
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Window question
Posted: Wed Jun 08, 2011 02:04 PM

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

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Window question
Posted: Wed Jun 08, 2011 02: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

Marco Boschi
info@marcoboschi.it
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Window question
Posted: Wed Jun 08, 2011 02:26 PM
Marco,



Code (fw): Select all Collapse
#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 :-)
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.
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: Window question
Posted: Wed Jun 08, 2011 03:32 PM

IT WORKS
Many thanks

Marco Boschi
info@marcoboschi.it
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Window question
Posted: Wed Jun 08, 2011 03: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Window question
Posted: Wed Jun 08, 2011 07: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

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Window question
Posted: Wed Jun 08, 2011 07: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
Posts: 663
Joined: Mon Dec 05, 2005 11:22 PM
Re: Window question
Posted: Wed Jun 08, 2011 08: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 (fw): Select all Collapse
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<<<

Continue the discussion