How to resize Dlgboxes runtime?

Posted on 1998-10-19
Medium Priority
Last Modified: 2013-11-20
I make an application for an embedded device with Windows CE. This device can have several displays, big and little. However, the ratio between the dialog and the screen must be fixed always. So, the dialog must be bigger when the display is bigger.
On the fly (at starting up the application) I determine with GetSystemMetrics() what the size of the screen is. Then I want to change the size of the dialog. (When I change the size of the dialog font in the resource editor, a good result is given; however this is a fixed size for all screens.)
I thought, maybe I can change the size of the dialogfont when the object is constructed, or in OnInitDialog.
I want to resize all components of the dialog box, the fontsize (for all controls) and the metrics of the controls.

My question is: can I do this in combination with the dialog made in the resource editor (and how!), or do I have to make it in a template in memory, to change DS_SETFONT?
I can use FindResource and LoadResource to load the resource, but I need a HMODULE in FindResource, and in Windows CE it can't be NULL.
When I change the size of the font in the resource editor, the controls are resized automaticcaly. Is this really not possible when changing the fontsize in run-time?
Can you me give a piece of code where I load a resource of IDD_DIALOG in a Template and then change the size of the Font fo that template, create the dialog and display it? Or any other manner to reach the same result.

Question by:rakok
  • 4

Author Comment

ID: 1323512
Adjusted points to 50

Author Comment

ID: 1323513
Adjusted points to 75

Expert Comment

ID: 1323514
1. If you want to change the font, including the dialog base units (the dlg is measured in terms of the font) you need to construct you own resource template

2. If you want to simply resize the dialog, and/or controls you can cheat
i. Use MoveWindow (or any other sizing API) on the dialog itself
ii. Use MoveWindow (or any other sizing API) on the dialog controls
iii. Modify the font of each control by sending WM_SETFONT message to each control
When using (i) and (ii) - with GetWindowRect etc.  watch out for screen/client rect coordinates, and use ScreenToClient (etc.) to convert em.  All this sizing stuff can be done when the dialog is active, e.g. OnInitDialog

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 1323515
I have tried your comment. Most of it works, but the comboboxes and checkboxes remain the same size (the spinbutton and the box of the checkbox). I think because of the DBU fo the default font.


Accepted Solution

SileNcer earned 210 total points
ID: 1323516
Hmmm, It sounds to me like you could use a combination of functions.  If you want to actually change the size of the dialog you could use SetWindowPos(0,0,Xmax,Ymax) and then center it again with CenterWindow(NULL);

To change your actual font sizes, use the CreateFont() function and set your checkboxs to this font.  Remember that the computer that runs it needs the font too.

//Put this in the header
CFont m_fontCheck1;

//put this in the .cpp
m_fontCheck1.CreateFont( 35, 14, 0, 0, 700, 0, 0, 0, 1, 0, 0, 0, 0, _T("MS Sans Serif") );

CEdit *pCheck1 = (CEdit *) GetDlgItem(IDC_YourCheckBox);
pCheck1->SetFont( &m_fontCheck1 );


Author Comment

ID: 1323517
It's a good answer. But when I resize Comboboxes, the spinbutton remains the same width. Also checkboxes are not goot scaled, so I think it's not good usable for all controls. I don't understand why it can't be good! So I can't use it for my dialog-boxes.


Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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 …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

597 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