Dialog Coordinates

Dialog Coordinates

Postby Bayron » Sun Sep 18, 2011 3: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...
Image
I only changed the calculations for the splitters!!!
=====>

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

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Dialog Coordinates

Postby nageswaragunupudi » Sun Sep 18, 2011 4: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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Dialog Coordinates

Postby Bayron » Sun Sep 18, 2011 4:57 am

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

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

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Dialog Coordinates

Postby Bayron » Sun Sep 18, 2011 6:13 am

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

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

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Dialog Coordinates

Postby nageswaragunupudi » Sun Sep 18, 2011 9:02 am

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

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

Re: Dialog Coordinates

Postby Bayron » 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
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Dialog Coordinates

Postby Bayron » Sun Sep 18, 2011 4: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
(215)2226600 Philadelphia,PA, USA
+(502)46727275 Guatemala
MayaBuilders@gMail.com

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Dialog Coordinates

Postby nageswaragunupudi » Sun Sep 18, 2011 6:05 pm

Clever :)
Regards

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

Re: Dialog Coordinates

Postby Antonio Linares » Sun Sep 18, 2011 6: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Dialog Coordinates

Postby Antonio Linares » Sun Sep 18, 2011 7:28 pm

An example:

testdlgu.prg // Testing dialog base units

Code: Select all  Expand view  RUN
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Dialog Coordinates

Postby Bayron » Sun Sep 18, 2011 7: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

Image
Last edited by Bayron on Sun Sep 18, 2011 7:51 pm, edited 1 time in total.
=====>

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

FWH12.04||Harbour 3.2.0 (18754)||BCC6.5||UEstudio 10.10||
Windows 7 Ultimate

FiveWin, One line of code and it's done...
User avatar
Bayron
 
Posts: 815
Joined: Thu Dec 24, 2009 12:46 am
Location: Philadelphia, PA

Re: Dialog Coordinates

Postby Antonio Linares » Sun Sep 18, 2011 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Dialog Coordinates

Postby James Bott » Mon Sep 19, 2011 11:17 pm

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

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

Re: Dialog Coordinates

Postby Antonio Linares » Tue Sep 20, 2011 5: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42203
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Dialog Coordinates

Postby James Bott » Tue Sep 20, 2011 5: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests

cron