FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Dialog Coordinates
Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Dialog Coordinates
Posted: Sun Sep 18, 2011 03:54 AM
Hi all,
Is there any difference between Window Coordinates and Dialog Coordinates????

I built a separate .prg file using a window, I obtained the size of it by using WndHeight( GetDesktopWindow() ), WndWidth( GetDesktopWindow() ) I calculated the coordinates using oWnd:nHeight and oWnd:nWidth, all the controls were placed and sized logically using percentages of this coordinates…
Now I am adding this .prg to my main program and for that reason, I am changing the Window to a Dialog, but now all controls appear to be double the size of what they were supposed to be….

This is a pretty big .prg file, with thousands of logical calculations for size and position, and I just want to know if there is something special about Dialogs that I need to know to make my calculations???

EDITED1:
I tested msginfo( oDialog:nwidth )
and It returned the right coordinates in pixels...
It seems that the size of the dialog is right, but the size and position of the controls are not... How is this possible, I just change from DEFINE WINDOW to DEFINE DIALOG??

EDITED2:
Dividing oDlg:nHeight and oDlg:nWidth by 2, it shows the controls in the right place... (This can't be Right) I think I am going to wait for FiveTech on this one, I don't want to change 1,000 lines and find out I only needed:

One line of code to get it done...

I only changed the calculations for the splitters!!!

=====>

Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 04:48 AM
Dividing oDlg:nHeight and oDlg:nWidth by 2, it shows the controls in the right place.

That is right.
This is the difference between windows and dialogs.
Fivewin has nothing to do with it. It is Microsoft Windows behavior.

We need to do all our calculations to position the controls keeping this in mind.
Regards



G. N. Rao.

Hyderabad, India
Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 04:57 AM

Thanks Mr. Rao, I did not knew that...

=====>

Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 06:13 AM

I Wonder why GradientFill, did not needed the divided by 2 calculation???

=====>

Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 09:02 AM

In the ON INIT clause, we do not have to do 1/2

Regards



G. N. Rao.

Hyderabad, India
Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 12:50 PM

Now I fully undestand it's behavior because of your good explanation...

Thanks a lot Mr. Rao...

=====>

Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 04:31 PM
nageswaragunupudi wrote:In the ON INIT clause, we do not have to do 1/2


Next time I am going to read my own Forum Signature and believe in it:

FiveWin, One line of code and it's done...

I am almost done... after not sleeping last night..., and I just realized that I only needed to change a few lines of code:

Create a function to be called from the ON INIT clause to build the controls, Copy and Paste and Done...

Some times we do dumb things because: who does not know is like who does not see...

=====>

Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 06:05 PM

Clever :)

Regards



G. N. Rao.

Hyderabad, India
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 06:45 PM
http://msdn.microsoft.com/en-us/library/ms645475(VS.85).aspx

baseunitX = nLoWord( GetDlgBaseUnits() )
baseunitY = nHiWord( GetDlgBaseUnits() )


Therefore, to convert dialog template units to pixels, use the following formulas:

pixelX = MulDiv(templateunitX, baseunitX, 4);
pixelY = MulDiv(templateunitY, baseunitY, 8 );

Similarly, to convert from pixels to dialog template units, use the following formulas:

templateunitX = MulDiv(pixelX, 4, baseunitX);
templateunitY = MulDiv(pixelY, 8, baseunitY);
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 07:28 PM
An example:

testdlgu.prg // Testing dialog base units

Code (fw): Select all Collapse
#include "FiveWin.ch"

function Main()

   local oWnd, cTest := Space( 20 )

   DEFINE WINDOW oWnd TITLE "A window"
   
   @ 20, 20 SAY "Hello" SIZE 80, 20 PIXEL
   
   @ 20, 60 GET cTest SIZE 80, 20 PIXEL

   @ 80, 60 BUTTON "Ok" SIZE 80, 20 PIXEL

   @ 80, 180 BUTTON "Cancel" SIZE 80, 20 PIXEL

   Dialog( oWnd )

   ACTIVATE WINDOW oWnd ;
      ON CLICK MsgInfo( oWnd:nWidth )

return nil

#define SM_CXDLGFRAME 7

function Dialog( oWnd )

   local oDlg, cTest := Space( 20 )
   local factorX := 4 / nLoWord( GetDlgBaseUnits() )
   local factorY := 8 / nHiWord( GetDlgBaseUnits() )

   DEFINE DIALOG oDlg TITLE "A dialog" ;
      SIZE oWnd:GetCliRect():nWidth - 2, oWnd:GetCliRect():nHeight - 2

   @ 20 * factorX, 20 * factorY SAY "Hello" SIZE 80 * factorY, 20 * factorX PIXEL

   @ 20 * factorX, 60 * factorY GET cTest SIZE 80 * factorY, 20 * factorX PIXEL
   
   @ 80 * factorX, 60 * factorY BUTTON "Ok" SIZE 80 * factorY, 20 * factorX PIXEL

   @ 80 * factorX, 180 * factorY BUTTON "Cancel" SIZE 80 * factorY, 20 * factorX PIXEL

   ACTIVATE DIALOG oDlg CENTERED NOWAIT ;
      ON CLICK MsgInfo( oDlg:GetCliRect():nWidth - oWnd:GetCliRect():nWidth )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 883
Joined: Thu Dec 24, 2009 12:46 AM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 07:36 PM
Thanks for the excelent example Mr. Linares...
That should be the right way to doit, but I worked out fine for me dividing everything by 2 as well...

All the controls are calculated automatically and sized to the screen resolution... even the fonts

=====>

Bayron Landaverry
xBasePHP.com
(215)2226600 Philadelphia,PA, USA
MayaBuilders@gMail.com
Guatemala

FWH25.06--Harbour 3.0.0--BCC7.7--UEstudio 10.10
Windows 10

FiveWin, One line of code and it's done...

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Dialog Coordinates
Posted: Sun Sep 18, 2011 07:49 PM

Bayron,

You are welcome :-)

Still there is a little difference between the width and height of the window and the dialog, not sure exactly why...

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Dialog Coordinates
Posted: Mon Sep 19, 2011 11:17 PM

I found that using 2.05 for the divisor worked better for me.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Dialog Coordinates
Posted: Tue Sep 20, 2011 05:08 AM

James,

It depends on the used font, thats why its better to call GetDlgBaseUnits() provided by Windows API as I used in my example above :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Dialog Coordinates
Posted: Tue Sep 20, 2011 05:37 PM

Antonio,

>It depends on the used font, thats why its better to call GetDlgBaseUnits() provided by Windows API as I used in my example above

I totally agree. My 2.05 value I came up with many, many years ago--probably with Win98. It worked OK then, but your system is better.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion