Solved

Dialog Units

Posted on 2001-06-29
5
729 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
[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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

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 …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.

726 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