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
Solved

Dialog Units

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 108
fix34  challenge 9 143
Making an alias 7 101
Message not shown 5 67
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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