Solved

Dialog window size

Posted on 1998-07-15
8
880 Views
Last Modified: 2013-12-03
I create a dialog window by using CreateIndirect(). And I have a problem.
I want to create the window with a certain size, for example with a client
rectangle size of a parent window. I can get wanted size by using GetClientRect().
But the values I get are measured in pixels. At the same time I have to set
x, y, cx and cy parameters of DLGTEMPLATE in dialog box units, not in pixels.
I make the following:

...
CRect MainWndClientRect;
pParentWnd->GetClientRect(&MainWndClientRect);
...
LONG  DlgBaseUnit = GetDialogBaseUnits();
UINT  DlgBaseUnitX = (UINT)( ( DlgBaseUnit << 16 ) >> 16 );
UINT  DlgBaseUnitY = (UINT)( DlgBaseUnit >> 16 );

DLGTEMPLATE  dlgTempl;
...
dlgTempl.x  = (short)( ( MainWndClientRect.left     * 4 ) / DlgBaseUnitX );
dlgTempl.y  = (short)( ( MainWndClientRect.top      * 8 ) / DlgBaseUnitY );
dlgTempl.cx = (short)( ( MainWndClientRect.Width()  * 4 ) / DlgBaseUnitX );
dlgTempl.cy = (short)( ( MainWndClientRect.Height() * 8 ) / DlgBaseUnitY );
...
CreateIndirect( &dlgTempl, &pParentWnd );
...

As a result I have the dialog window with a wrong size. Why?
0
Comment
Question by:V245
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1410262
I'm not sure why that doesn't work.  But I can suggest an improvement.  (Yes that's right a change that will make it not work even faster.)

instead of

UINT  DlgBaseUnitX = (UINT)( ( DlgBaseUnit << 16 ) >> 16 );
UINT  DlgBaseUnitY = (UINT)( DlgBaseUnit >> 16 );

use

UINT  DlgBaseUnitX = (UINT)( DlgBaseUnit && 0x0000FFFF );
UINT  DlgBaseUnitY = (UINT)( DlgBaseUnit >> 16 );

How far are you off by?  like could this be a rounding thing?  
0
 
LVL 2

Accepted Solution

by:
duneram earned 70 total points
ID: 1410263
Why not catch the WM_INITDIALOG message in that dialog and then use the SetWindowPos() API?

Then you could just use pixel values directly.

In mfc its OnInitDialog
In Owl its SetupWindow
0
 
LVL 11

Expert Comment

by:alexo
ID: 1410264
The calculation you make is only valid if you're using the system font.
There is a workaround.  See KB articles Q145994 and Q74280 for details.

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Author Comment

by:V245
ID: 1410265
I'm using system font. So I accept the Duneram answer also at common I don't like such solutions. To my mind it isn't a problem solution but it is a trick for go around the problem. In any case it works.
Thanks for Nietod and Alexo for your advices.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1410266
I'm still curious, how far off was the positioning using your formulas?  was it close?
0
 
LVL 1

Author Comment

by:V245
ID: 1410267
Sorry for my delay, I was in leave. Well, at the time I know that   GetDialogBaseUnits() is cause of my problem. This function returns wrong value ( DlgBaseUnitX=10 and  DlgBaseUnitY=20 instead of 8 and 16 ). I tried 'Method Two' from article Q145994 - it works correct.
Thanks for all.
Vladimir
0
 
LVL 11

Expert Comment

by:alexo
ID: 1410268
Well, seems I was able to help after all :-)
0
 
LVL 1

Author Comment

by:V245
ID: 1410269
'Method Two' can be used for calculating dialog units instead GetDialogBaseUnits(). But in my case I can't use it because I need the dialog units values before the window is created. So I can't call MapDialogRect(). In my program I implemented Duneram's solution: I create the window with wrong size and then call SetWindowPos() in OnInitDialog(). I guess His Majesty Bill Gates didn't let me any choice ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question