?
Solved

Dialog window size

Posted on 1998-07-15
8
Medium Priority
?
885 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

801 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