views:

529

answers:

3

I'm currently designing my first ever GUI for Windows. I'm using MFC and Visual Studio 2008. The monitor I have been designing my program on has 1680x1050 native resolution. If I compile and send my program to one of my coworkers to run on their computer (generally a laptop running at 1024x768), my program will not fit on their screen.

I have been trying to read up on how to design an MFC application so that it will run on all resolutions, but I keep finding misleading information. Everywhere I look it seems that DLUs are supposed to resize your application for you, and that the only time you should run into problems is when you have an actual bitmap whose resolution you need to worry about. But if this is the case, why will my program no longer fit on my screen when I set my monitor to a lower resolution? Instead of my program "shrinking" to take up the same amount of screen real estate that it uses at 1680x1050, it gets huge and grainy.

The "obvious" solution here is to set my resolution to 1024x768 and redesign my program to fit on the screen. Except that I've already squished everything on my dialogs as much as possible to try and get my program to fit on screen running at 1024x768. My dialog fonts are set to Microsoft Sans Serif 8 but still appear huge (much larger than 8 points) when running at 1024x768.

I know there HAS to be a way to make my program keep the same scaling... right? Or is this the wrong way to approach the problem? What is the correct/standard way to go about designing an MFC program so that it can run on many resolutions, say 800x600 and up?

+2  A: 

I assume your application GUI is dialog based (the main window is a dialog)?

In that case you have a problem, because, as you discovered, MFC has no support for resizing a dialog correctly. Your options are:

  • Redesign your GUI to use a SDI or MDI GUI.
  • Use a dialog resize extension. There are many available, for some very good suggestions see this question. Another options are this one and this one.
  • Don't use MFC. wxWidgets has much better support for dialog resizing.
Dani van der Meer
Just to throw in another link, Joseph M. Newcomer (MS MVP) has a nice essay about resizing MFC dialogs. Take a look: http://www.flounder.com/getminmaxinfo.htm
eran
+1  A: 

There is no automatic way to resize the content of your dialogs when resolution changes. So, you need to set some boundaries.

Option 1. If you are developing your app for customers, pick one minimum resolution (like 1024x7678), redesign you dialogs so that everything fits. Maybe break up some into several, or use tab strip control.

Option 2. Create separate dialog forms for each resolution you'd like to support, but use the same class to handle it. At runtime detect resolution and use the appropriate form.

Option 3. Write your own resizing functionality, so that user could adjust the size of your dialogs to his liking.

z-boss
+1  A: 

MFC is only a thin wrapper over the Windows API. They both make an assumption which is hardly ever true: if you have a higher resolution screen, you'll adjust the DPI or font size in Windows to get larger characters. Most of the time, a larger screen size means a larger physical monitor, or a laptop where you want to squeeze as much information into a small screen as possible; people value more information over greater detail. Thus the assumption fails.

If you can't squeeze your entire UI into the smallest size screen you need to support, you'll have to find another way to make it smaller. Without knowing anything about your UI, I might suggest using tabs to group the controls into pages.

I've had good luck making my windows resizable, so that people with larger screens can see more information at once. You need to do this the hard way, responding to the WM_SIZE message to the window and deciding which controls should be made larger and which ones should just move.

Mark Ransom
Unfortunately I'm already using a tab control. I may need to reduce my font size because on 1024x768 the font is huge... though on 1680x1050 it's just the right size. :/
Lauren
The default dialog font is pretty small already. Did you select a font other than the default?
Mark Ransom