简体   繁体   English

最小化按钮不会出现在 MFC 对话框中

[英]Minimize button won't appear on MFC Dialog

I am having trouble adding the minimise button to my MFC Dialog application.我在将最小化按钮添加到我的 MFC 对话框应用程序时遇到了问题。 I have enabled minimise box (true).我已启用最小化框(true)。

The minimise button appears in the designer view but when I run the application the buttons are not visible.最小化按钮出现在设计器视图中,但是当我运行应用程序时按钮不可见。

Other settings are: Style: Overlapped其他设置有:样式:重叠
Application Window: True应用程序窗口:真
Border: Dialog Frame边框:对话框框
Tool Window: False工具窗口:假
System Menu: True系统菜单:真

I tried adding: ModifyStyle(0, WS_MINIMIZEBOX, TRUE);我尝试添加: ModifyStyle(0, WS_MINIMIZEBOX, TRUE);

to the OnInitDialog() but hasn't solved it.OnInitDialog()但还没有解决它。

There are 3 styles that I can choose which are popup, child and overlapped.我可以选择 3 种样式,分别是弹出样式、子样式和重叠样式。 If I use popup I don't see a title bar and cannot drag the window.如果我使用弹出窗口,我看不到标题栏并且无法拖动窗口。 Child throws an access violation if I use that style, so the only style I can choose is overlapped which shows the title bar and allows me to drag the window but the minimise button is not visible.如果我使用该样式,子项会引发访问冲突,因此我可以选择的唯一样式是重叠样式,它显示标题栏并允许我拖动窗口但最小化按钮不可见。

I am using Visual Studio 2019 and running Windows 10 1809.我正在使用 Visual Studio 2019 并运行 Windows 10 1809。

I have double checked and minimise box is set to TRUE however it still won't show up on the dialog box when running.我已经仔细检查并将最小化框设置为 TRUE 但是它在运行时仍然不会显示在对话框中。

The problem is when I use the Popup window style, I do not see the title bar at all!问题是当我使用弹出窗口样式时,我根本看不到标题栏! Also if I use the popup style I am unable to drag the window (title bar is missing).此外,如果我使用弹出样式,我将无法拖动窗口(缺少标题栏)。 Overlapped seems the only style that I can use.重叠似乎是我唯一可以使用的样式。

Try something like this:尝试这样的事情:

BOOL CMFCApplication1Dlg::OnInitDialog()
{
    ModifyStyle(0, WS_POPUP | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, TRUE);
    ...
}

Consider modifying your dialog template (in the .RC file) to include the necessary style bits instead of modifying the style at runtime.考虑修改您的对话框模板(在 .RC 文件中)以包含必要的样式位,而不是在运行时修改样式。

MFC is no different from programming a dialog without any frameworks. MFC 与在没有任何框架的情况下编写对话框没有什么不同。 You declare a DIALOGEX resource, and have the system load it up, and display a dialog based on that template.您声明一个DIALOGEX资源,并让系统加载它,并显示基于该模板的对话框。

To get a dialog with a minimize box it needs at least the styles WS_MINIMIZEBOX and WS_SYSMENU 1 .要获得带有最小化框的对话框,它至少需要样式WS_MINIMIZEBOXWS_SYSMENU 1 Open up the .rc script that defines the DIALOGEX dialog template, and make sure those 2 styles are present in the STYLE element.打开定义DIALOGEX对话框模板的 .rc 脚本,并确保这两种样式存在于STYLE元素中。

A default dialog template for a dialog-based application (with a minimize box) will typically be defined like this:基于对话框的应用程序(带有最小化框)的默认对话框模板通常如下定义:

IDD_MFCAPPLICATION1_DIALOG DIALOGEX  0, 0, 320, 200
STYLE DS_SHELLFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION
 | WS_THICKFRAME
 | WS_SYSMENU
 | WS_MINIMIZEBOX
EXSTYLE WS_EX_APPWINDOW
CAPTION ""
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,209,179,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,263,179,50,14
    CTEXT           "TODO: Place dialog controls here.",IDC_STATIC,10,96,300,8
END

You don't need to write any code that executes at runtime to get this behavior.您无需编写任何在运行时执行的代码即可获得此行为。


1 From Window Styles : " WS_MINIMIZEBOX : The window has a minimize button. [...] The WS_SYSMENU style must also be specified. " 1窗口样式WS_MINIMIZEBOX :窗口有一个最小化按钮。[...] WS_SYSMENU样式也必须指定。

BOOL CMFCApplication1Dlg::OnInitDialog(){

ModifyStyle(0, WS_MINIMIZEBOX, TRUE);
ModifyStyle(0, WS_POPUP, TRUE);
ModifyStyle(0, WS_BORDER, TRUE);
ModifyStyle(0, WS_SYSMENU, TRUE);
ModifyStyle(0, WS_CAPTION, TRUE);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM