Solved

Dialog Units

Posted on 2001-06-29
5
709 Views
Last Modified: 2013-11-20
I am developing an application for Windows CE where I have very specific sizing specifications (in pixels) for the various controls and dialogs.  The problem is that Microsoft uses "Dialog Units" (DLU's) to layout the dialog boxes and controls.  I need to layout the controls using pixels.

Does anyone know of a way to force 1 DLU = 1 pixel???  I'm not sure where MS does the conversion or if I can override a function call somewhere.  I tried overriding MapDialogRect in my CDialog-derived class, but the function is not called.

For a little background, 1 Horizontal DLU = 1/4 the average width of the dialog font.  1 Vertical DLU = 1/8 the average height of the dialog font.  I have tried using various fonts without any luck in getting both the DLU's = 1 pixel.

Any help would be appreciated!

-Eric
0
Comment
Question by:eholmberg
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6239522
Hi!
how you layout controls?
in the resource editor?
0
 

Author Comment

by:eholmberg
ID: 6239531
Yes, with the resource editor.  I am currently resizing everything in the OnInitDialog() function.  The code for resizing the dialog is shown below:

     MoveWindow( 0,0,800,600);// resize to 800x600

This results in the proper pixel-size for the dialog, but it means that I must resize and reposition all of the controls on the dialog.  It would be extremely helpful to just layout the dialog and controls in the resource editor and be done with it.  Remember, this is going on a Windows CE device with a fixed display and fonts, etc.
0
 

Author Comment

by:eholmberg
ID: 6239535
Yes, with the resource editor.  I am currently resizing everything in the OnInitDialog() function.  The code for resizing the dialog is shown below:

     MoveWindow( 0,0,800,600);// resize to 800x600

This results in the proper pixel-size for the dialog, but it means that I must resize and reposition all of the controls on the dialog.  It would be extremely helpful to just layout the dialog and controls in the resource editor and be done with it.  Remember, this is going on a Windows CE device with a fixed display and fonts, etc.
0
 
LVL 12

Accepted Solution

by:
migel earned 50 total points
ID: 6239606
Hi!
simplest way:
int the resource editor set control to size 10x10 and look at runtime its size and then calculate coewfficients to translate DLU to pixels.
Another way is to walk around all controls in the dialog and manually resize it to proper size:
for eaxample:
CMyDialog::OnInitDialog()
{
CRect rc;
CRect rcChild;
GetWindowRect(&rc);
   MoveWindow( 0,0,800,600);// resize to 800x600
//
HWND hwndChild = ::GetWindow(m_hwnd, GW_CHILD);
// we use HWND for speed
while (hwndChild)
   {
   ::GetWindowRect(hwndChild, &rc);
   rc.left *= rc.Width()/800;
   rc.top *= rc.Height()/600;
   rc.right *= rc.Width()/800;
   rc.bottom *= rc.Height()/600;
   ScreenToClient(&rc);
   // and move it:
   ::MoveWindow(hwndChild,    rc.left,
   rc.top,
   rc.right-rc.left,  rc.bottom -rc.top, FALSE);
   hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT);
   }
}

0
 

Author Comment

by:eholmberg
ID: 6239679
Migel,

You're the man!  Thanks.  I changed your code slightly, here is what I used.  It works great, although ScreenToClient doesn't offset the y-coordinates for the task bar.  For my CE application, I don't have one, so it doesn't matter.  Good work!

Poka,
Eric


CRect     rc;
double     dHDLU,dVDLU;

GetWindowRect(&rc);

// Calculate the Pixel/DLU ratio
dHDLU = 800.0 / (rc.right - rc.left);
dVDLU = 600.0 / (rc.bottom - rc.top);

// Resize to 800 x 600
rc.left   *= dHDLU;
rc.right  *= dHDLU;
rc.top    *= dVDLU;
rc.bottom *= dVDLU;
MoveWindow( 0,0,rc.right - rc.left,rc.bottom - rc.top);

// Verify that we don't have any rounding errors
ASSERT(rc.right - rc.left == 800);
ASSERT(rc.bottom - rc.top == 600);

// Resize all of the controls to pixel sizes
HWND hwndChild = ::GetWindow(m_hWnd, GW_CHILD);
while (hwndChild)
{
     ::GetWindowRect(hwndChild, &rc);
     rc.left *= dHDLU;
     rc.right *= dHDLU;
     rc.top *= dVDLU;
     rc.bottom *= dVDLU;
     ScreenToClient(&rc);

     // and move it:
     ::MoveWindow(hwndChild, rc.left, rc.top, rc.right - rc.left,  rc.bottom - rc.top, FALSE);
     hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT);
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 121
iSeries DB2 Query 2 90
conditional code and condition difference 9 77
NotAlone Challenge 20 79
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now