设计一个适用于所有分辨率的 MFC 应用程序?
我目前正在设计我的第一个 Windows GUI。 我正在使用 MFC 和 Visual Studio 2008。我用来设计程序的显示器的原始分辨率为 1680x1050。 如果我编译程序并将其发送给我的一位同事在他们的计算机上运行(通常是一台以 1024x768 运行的笔记本电脑),我的程序将无法适合他们的屏幕。
我一直在尝试阅读如何设计 MFC 应用程序,以便它可以在所有分辨率上运行,但我不断发现误导性信息。 在我看来,DLU 似乎应该为您调整应用程序的大小,并且您应该遇到问题的唯一时间是当您拥有需要担心其分辨率的实际位图时。 但如果是这样的话,为什么当我将显示器设置为较低的分辨率时,我的程序将不再适合我的屏幕? 我的程序并没有“缩小”以占用与 1680x1050 分辨率相同的屏幕空间,而是变得巨大且有颗粒感。
这里“明显”的解决方案是将分辨率设置为 1024x768 并重新设计我的程序以适合屏幕。 只是我已经尽可能地压缩了对话框中的所有内容,以尝试让我的程序适合以 1024x768 运行的屏幕。 我的对话框字体设置为 Microsoft Sans Serif 8,但在 1024x768 下运行时仍然显得很大(远大于 8 磅)。
我知道必须有一种方法可以让我的程序保持相同的缩放比例......对吧? 或者这是解决问题的错误方法? 设计 MFC 程序以使其可以在多种分辨率(例如 800x600 及以上)上运行的正确/标准方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您的应用程序 GUI 是基于对话框的(主窗口是一个对话框)?
在这种情况下,您就会遇到问题,因为正如您所发现的,MFC 不支持正确调整对话框的大小。 您的选择是:
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:
MFC 只是 Windows API 的一个薄包装。 他们都做出了一个几乎不可能成立的假设:如果您有更高分辨率的屏幕,您将调整 Windows 中的 DPI 或字体大小以获得更大的字符。 大多数时候,更大的屏幕尺寸意味着更大的物理显示器,或者您希望将尽可能多的信息压缩到小屏幕中的笔记本电脑; 人们更看重更多的信息而不是更详细的信息。 因此假设失败。
如果您无法将整个 UI 压缩到您需要支持的最小尺寸屏幕中,则必须找到另一种方法来使其更小。 在不了解用户界面的情况下,我可能建议使用选项卡将控件分组到页面中。
我很幸运地调整了窗口的大小,以便拥有更大屏幕的人可以立即看到更多信息。 您需要以困难的方式做到这一点,响应窗口的 WM_SIZE 消息并决定哪些控件应该变大,哪些控件应该移动。
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.
当分辨率改变时,没有自动调整对话框内容大小的方法。 所以,你需要设定一些界限。
选项 1。
如果您正在为客户开发应用程序,请选择一种最低分辨率(例如 1024x7678),重新设计对话框以使一切都适合。 也许将一些分成几个,或者使用选项卡条控件。
选项 2。
为您想要支持的每个分辨率创建单独的对话框表单,但使用相同的类来处理它。 在运行时检测分辨率并使用适当的形式。
选项 3。
编写您自己的调整大小功能,以便用户可以根据自己的喜好调整对话框的大小。
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.