Solved

Dialog Units

Posted on 2001-06-29
5
702 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
Comment Utility
Hi!
how you layout controls?
in the resource editor?
0
 

Author Comment

by:eholmberg
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maxBlock challenge 30 99
method notes when mouse over in eclipse 5 65
wordcount challenge 11 71
Problem to open Excel file 15 35
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

8 Experts available now in Live!

Get 1:1 Help Now