Solved

Dialog window size

Posted on 1998-07-15
8
881 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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