Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby ukoenig » Sat Aug 07, 2010 11:26 am

Hello,

I have a problem to calculate the same Button-positions on different Dialog-Sizes.
I want to show a Button allways on the same Place after changing the Dialog-Size.
Inside the Main-Window it works like :
< oWnd:nHeight - 80, oWnd:nWidth - 100 >
( for Exit-Button 70 x 50 showing on the Right / Bottom- Corner )

Inside a Dialog it doesn't work ( Button-position not related to Dialog-Size )
Is it possible, to calculate / show the Button allways on the same Position on different Dialogsizes ???

// Defined Dialog-Position / Size := 50, 50 TO 700, 600
DEFINE DIALOG oDlg5 FROM nDlgTop, nDlgLeft TO nDlgWidth, nDlgHeight TITLE "Background-Tests" ICON oIco PIXEL

// Button-Position not related to Dialogsize :
@ 220, 250 BTNBMP oBtn5 SIZE 70, 40 OF oDlg5 2007 PIXEL ;

Image

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: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby WilliamAdami » Mon Aug 09, 2010 1:30 am

Good night

I have a function that does what you want, DISPLAY.PRG. In the link below has the function and examples of how to use.

http://www.4shared.com/file/NIwJho3C/DISPLAY3.html


This function causes a screen designed in 800X600 resolution to appear equal in a resolution of 1024x768 for example. All controls (BUTTONS, GETS, SAYS, ETC ...) are displayed proportionately equal.

The function calculates the factor of height adjustment (nFactorHeight) and width (nFactorWitdh)
to calculate the position of the controls after resizing.

I hope it helps.

William Adami
WilliamAdami
 
Posts: 68
Joined: Tue Apr 14, 2009 9:26 pm
Location: Brasil

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby ukoenig » Mon Aug 09, 2010 5:50 pm

William,

thank You very much.
My problem is not the Screen-resolution. The user can change the Dialog-Size and Position.
Inside the new repainted Dialog, I want to show a Exit-Button allways on the same Position.
I tested with a calculation from Dialog-Bottom and Right, but that doesn't work ( only on the Main-Window ).

On Dialog-Size 700 x 600 i used for the Exit-Button :

@260, 150 SBUTTON oBtn2 FONT oFont1 ;
SIZE 50, 25 PIXELS ;
FILENAME c_path + "\SYSTEM\Exit.bmp" ;
OF oDlg5 PROMPT "&Exit" ACTION oDlg5:End()

I could define from Top / Left like : @50, 50 SBUTTON ...
and I will have the Button allways on the same Position, but that doesn't look very nice.

Image

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: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby WilliamAdami » Mon Aug 09, 2010 9:27 pm

Good night, the display function was only one example of how you could do this.

Below is an example of how.

William


****************************************************************************************
#include "fivewin.ch"

function main

DEFINE DIALOG oDlg5 FROM 10,10 to 300,500 TITLE "TEST" PIXEL

@ 110, 190 BTNBMP oBtn5 size 50, 30 of oDlg5 2007 pixel action test1(odlg5,obtn5)

activate dialog odlg5 centered

return nil




function test1(odlg5,obtn5)

* coord. from origin dialog:

nOriWidth := odlg5:nWidth
nOriHeight := odlg5:nHeight

msgalert("Now The new (big) dialog :")

odlg5:move(10,10,700,400)
odlg5:refresh()


* coord. of the new dialog

nWidth := odlg5:nWidth
nHeight := odlg5:nHeight

* calculate the factor :

nFactorWitdh := nWidth / nOriWidth
nFactorHeight := nHeight / nOriHeight

msgalert("FATOR HEIGHT: "+str(nFactorHeight,10,2)+CRLF+"FATOR WIDTH: "+str(nfactorwitdh,10,2))

* adjust the button in new dialog
obtn5:Move( obtn5:nTop * nFactorHeight , obtn5:nLeft * nFactorWitdh, , , .F. )

obtn5:refresh()
odlg5:refresh()

return nil


WilliamAdami
 
Posts: 68
Joined: Tue Apr 14, 2009 9:26 pm
Location: Brasil

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby James Bott » Mon Aug 09, 2010 9:28 pm

Ewe,

Are you aware the dialogs use a different unit than Windows? This was developed by Microsoft and I never really understood why.

I did write about this in my "Introduction to Fivewin" article on this page:

http://www.gointellitech/program.htm

Maybe that will help.

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

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby ukoenig » Tue Aug 10, 2010 12:50 am

William, James

I tested with the Factor-calculation. The Position is non-linear to the Dialog-Size.
It seems, to move the Button to the Left / upper-corner, will be the only Solution.

Image

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: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby WilliamAdami » Tue Aug 10, 2010 1:01 am

UWE, in my Function DISPLAY() she works with scaling factor and works very well if you increase or decrease the dialog, the controls adjust accordingly.

Good luck

William
WilliamAdami
 
Posts: 68
Joined: Tue Apr 14, 2009 9:26 pm
Location: Brasil

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby ukoenig » Mon Aug 16, 2010 10:12 pm

I searched in the Internet how to convert / calculate the Control-Positions ( from PIXEL and REVERSE ).
The Infos I found. Maybe we can use it ???

MapDialogRect Function

Converts the specified dialog box units to screen units (pixels).
The function replaces the coordinates in the specified RECT structure with the converted coordinates,
which allows the structure to be used to create a dialog box or position a control within a dialog box.

Syntax
CopyBOOL WINAPI MapDialogRect(
__in HWND hDlg,
__inout LPRECT lpRect
);

// ----- FWH - Function -----------------

DLL32 FUNCTION MapDialRec;
( hDlg AS LONG, @lpRect AS LPSTR ) ; // RECT
AS LONG PASCAL;
FROM "MapDialogRect" LIB "USER32"


// -----------------------

Parameters
hDlg [in]
HWND
A handle to a dialog box.
This function accepts only handles returned by one of the dialog box creation functions.
Handles for other windows are not valid.

lpRect [in, out]
LPRECT
A pointer to a RECT structure that contains the dialog box coordinates to be converted.

Return Value
BOOL

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information,
call GetLastError.

Remarks
The MapDialogRect function assumes that the initial coordinates
in the RECT structure represent dialog box units.
To convert these coordinates from dialog box units to pixels,
the function retrieves the current horizontal and vertical base units for the dialog box,
then applies the following formulas:

Copy
left = MulDiv(left, baseunitX, 4.0)
right = MulDiv(right, baseunitX, 4.0)
top = MulDiv(top, baseunitY, 8.0)
bottom = MulDiv(bottom, baseunitY, 8.0)
If the dialog box template has the DS_SETFONT or DS_SHELLFONT style,
the base units are the average width and height, in pixels,
of the characters in the font specified by the template.

Given Pixel-Values to Base-Units
-----------------------------------
Each horizontal base unit is equal to 4 horizontal dialog template units
each vertical base unit is equal to 8 vertical dialog template units
If MapDialogRect(1000) => 1200, then you could simply
take your pixel values, multiply by 1000, divide by 1200, and you would have what you
need. That's just algebra.
For example, suppose your value is 1200 pixels. Then 1000*1200 = 1200000; divide that by
1200 and you get 1000, which is the DBU value you would have started with. So if you got
a 2400 pixel element, it would represent 2000 DBU, which is the value you would store.

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: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby James Bott » Mon Aug 16, 2010 11:03 pm

Uwe,

This seems very odd to base the size of the dialog calculations on the size of the font used in the dialog. What if the font is not one of the two specified.

In the graphic you posted using my conversion numbers, you didn't include the size of the dialogs. Can I get those and maybe the formula you used to calculate the position of the button?

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

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby ukoenig » Mon Aug 16, 2010 11:24 pm

James,

it seems, Fonts can be different :

MFC Library Reference
CDialog::MapDialogRect

Call to convert the dialog-box units of a rectangle to screen units.

Copy
void MapDialogRect(
LPRECT lpRect
) const;

Parameters
lpRect
Points to a RECT structure or CRect object that contains the dialog-box coordinates to be converted.

Remarks
--------------------------------------------------------------------------------

Dialog-box units are stated in terms of the current dialog-box base unit derived from the average width and height of characters in the font used for dialog-box text. One horizontal unit is one-fourth of the dialog-box base-width unit, and one vertical unit is one-eighth of the dialog-box base height unit.

The GetDialogBaseUnits Windows function returns size information for the system font,
but you can specify a different font for each dialog box if you use the DS_SETFONT style in the resource-definition file. The MapDialogRect Windows function uses the appropriate font for this dialog box.
The MapDialogRect member function replaces the dialog-box units in lpRect with screen units (pixels) so that the rectangle can be used to create a dialog box or position a control within a box.

Best Regards
Uwe :roll:
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: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby nageswaragunupudi » Tue Aug 17, 2010 12:13 am

Mr Uwe

Please see \fwh\source\function\xbrowser.prg

Here the size of dialog size was not known initially and the dialog is finally resized on the basis of the size of the browsed data. The buttons and controls are finally moved to the appropriate relative positions. The logic in this function may be helpful to you.
Regards

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

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby James Bott » Tue Aug 17, 2010 12:28 am

Uwe,

OK, this is a lot simpler than it first seems. Below is my code.

I think with some more work you could eliminate the resize() function and do the whole thing with a oDlg:bResized codeblock (just one line, not calling a function).

Originally, I was not understanding that you wanted the button the same distance from the bottom and right side of the dialog rather than in the same relative position. It does make sense to me now.

Regards,
James

Code: Select all  Expand view

/*
Purpose: To keep a button at the bottom at the same distance from the bottom
and from the right side of the dialog after resizing the dialog. - James Bott
Date: August 16, 2010
*/



#include "fivewin.ch"

function main

   local oDlg, oBtn

   DEFINE DIALOG oDlg FROM 10,10 to 300,500 TITLE "TEST" PIXEL

   @ 110, 190 BTNBMP oBtn size 50, 30 of oDlg 2007 ;
     action resize(oDlg,oBtn,10,10,700,500) update

   activate dialog oDlg centered

return nil




function resize(oDlg, oBtn, nTop, nLeft, nBottom, nRight)

   local nBtnTop, nBtnLeft

   // How high from bottom of dialog is top of button (oBtn:nTop)
   nBtnTop:= oDlg:nHeight - oBtn:nTop

   // How far from right side of dialog is button's left side (oBtn:nLeft)
   nBtnLeft:= oDlg:nWidth - oBtn:nLeft

   // Resize the dialog
   oDlg:move(nTop,nLeft,nBottom,nRight)

   // adjust the button in new dialog
   oBtn:Move( oDlg:nHeight - nBtnTop , oDlg:nWidth - nBtnLeft, , , .F. )

   oDlg:refresh()

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

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby James Bott » Tue Aug 17, 2010 1:01 am

Well, I tried doing it with oDlg:bResized and oDlg:bMoved but neither will allow passing of any but the built-in parameters and neither passes self either, so I don't think it can be done.

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

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby James Bott » Tue Aug 17, 2010 1:06 am

Uwe,

it seems, Fonts can be different :


This seems like a which came first, the chicken or the egg thing. I expect the font size is determined by the dialog size (when the dialog is resized). Then you are supposed to get the dialog size using the font size.

Luckily for the problem at hand, it seems we don't need to use any of this information.

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

Re: Possible to calc. Right/Bottom Btn-Pos on diff. Dlg-Sizes ?

Postby ukoenig » Tue Aug 17, 2010 6:35 pm

Hello James,

the Basics for my new Folder-painter are working now.
More Settings will follow ( ADJUSTMENTS TO DANIEL's new FOLDERCLASS )

1. From Background-Page I select the Background and define in Design-Mode
with the Preview Size and Position for the Dialog.
The Button-text shows TOP, LEFT, WIDTH and HEIGHT of the Dialog / Window

Image

2. I move to the Folder-Page and select < Design-Mode >
Inside the Preview ( Dialog Background is defined before )
I create my Folder ( Size and Position in Relation to the Dialog )
The Button-text shows TOP, LEFT, WIDTH and HEIGHT of the Folder.
The Dialog-Title shows the Dialog-Size.

Image

3. I select a Background for the Folder and change to < Design-Result >.
As final Result, the Preview shows the created Dialog and Folder with Size and Background.

Image

Best Regards
Uwe :lol:
Last edited by ukoenig on Tue Aug 17, 2010 6:47 pm, edited 1 time in total.
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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests