如何在 MFC 中创建可调整大小的 CDialog?

2021-12-17 00:00:00 winapi mfc

我必须创建一个基于对话框的应用程序,而不是旧的 CFormView 类型的设计.但是 CDialog 生成固定大小的对话框.如何使用可调整大小的对话框创建基于对话框的应用程序?

I have to create a dialog based application, instead of old CFormView type of design. But CDialog produces fixed-size dialogs. How can I create dialog based applications with resizable dialogs?

推荐答案

在 RC 资源文件中,如果对话框有类似这样的样式,它将是固定大小的:

In the RC resource file if the dialog has this style similar to this it will be fixed size:

IDD_DIALOG_DIALOG DIALOGEX 0, 0, 320, 201
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU

如果对话框有这种风格,它会很大:

If the dialog has this style it will be sizeable:

IDD_DIALOG_DIALOG DIALOGEX 0, 0, 320, 201
STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME

使用这些可调整大小的框架选项,对话框将可以重新调整大小,但您仍需要做大量工作来处理 WM_SIZE 消息,以管理对话框中控件的大小和位置.

With these sizable frame options the dialog will be re-sizeable but you will still need to do a lot of work handling the WM_SIZE message to manage the sizing an positioning of the controls within the dialog.

相关文章