Calculating correct size for window

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
aholzinger
In need of some credit
In need of some credit
Posts: 8
Joined: Wed Jan 04, 2006 10:08 pm

Calculating correct size for window

Post by aholzinger » Sat Feb 11, 2006 9:06 am

Hello wxWidgeters,

I wrote a small dialog style application, that doesn't allow sizing. It worked perfectly on my PC, but I was a little upset, when I saw it on a user's machine for the first time: the window was too small to show all controls and as it's not sizeable, the program was not usable.

I started the project by designing the dialog in DialogBlocks and there entered fixed sizes for width and height, but this seems to be the problem.

Is there a possibility to calculate the sizes (for width and height) that are needed on the user's PC (at runtime) to size the window to the correct size?

I admit, I come from MS DevStudio, where you get that feature for free, if you write a dialog based MFC application and build the dialog with the resource editor.

Any hints higly appreciated.

Best regards
Axel

leio
Can't get richer than this
Can't get richer than this
Posts: 802
Joined: Mon Dec 27, 2004 10:46 am
Location: Estonia, Tallinn
Contact:

Post by leio » Sat Feb 11, 2006 9:13 am

Use wxDefaultSize for your frame, use sizers properly inside the frame (panel as the only child of frame, a sizer managing panels children, all other controls inside the frame children or grandchildren of the panel), and you should get the frame with a proper size automatically, me thinks
Compilers: gcc-3.3.6, gcc-3.4.5, gcc-4.0.2, gcc-4.1.0 and MSVC6
OS's: Gentoo Linux, WinXP; WX: CVS HEAD

Project Manager of wxMUD - http://wxmud.sf.net/
Developer of wxGTK;
gtk+ port maintainer of OMGUI - http://www.omgui.org/

alexcoppo
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 06, 2004 8:56 am
Location: Italy
Contact:

Post by alexcoppo » Sat Feb 11, 2006 10:07 am

Always use sizers; they handle all the problems auto-magically. If you need an unresizable window, just select a non-resizing border for the top containing window: at creation time, all controls and containers and sizers do they business and the user cannot change anything.

By the way, another reason for always using sizers is that you handle localization automatically: there are languages (like German) which are enormously more text intensive than English so you need more screen real estate. With fixed dialogs a-la Window you have to create different resources, with wxWidgets you have the same code which loads appropriate strings (see poedit) and sizing takes place automatically.

Beautifull, isn't it?

Bye!!!

aholzinger
In need of some credit
In need of some credit
Posts: 8
Joined: Wed Jan 04, 2006 10:08 pm

Post by aholzinger » Mon Feb 13, 2006 5:43 pm

Hello leio and alexcoppo,

sorry, I was not able to read your messages earlier. Thanks for your replies.

But using wxDefaultSize (or width = -1, height = -1 in DialogBlocks) didn't solve the problem.

My (test) app (for this problem) looks like this:
App: "DefaultApp" uses frame "DefaultFrame"
Frame: "DefaultFrame" has the following children:
"wxMenuBar: ID_MENUBAR" with one menu "Menu" with one item "Item"
"wxPanel: ID_PANEL" with one child "wxBoxSizer V"
"wxBoxSizer V" has the following children:
"wxBoxSizer H" and wxStaticBoxSizer V"
"wxBoxSizer H" has two "wxStaticBoxSizer H" as children, each with some controls.
"wxStaticBoxSizer V" has 3 "wxStaticBoxSizer H" as children, each with a single line text control and a button.

I have chosen -1 and -1 for width and height for the frame in DialogBlocks, but the appearing window, when starting the application doesn't show all controls.

I can upload (is this possible) or email the small demo project (it's only 13KB).

Regards
Axel

Post Reply