?
Solved

Dialog Units

Posted on 2001-06-29
5
Medium Priority
?
763 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 200 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

764 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