vs2019 MFC 如何在框架类中实现添加一个按钮button
首先, 在框架类CMainFrame中添加一个CButton m_btn的成员
然后,在框架类CMainFrame中OnCreate 函数最后添加创建button的函数并显示button,
(注意:在创建button函数create中如果使用了WS_VISIBLE,那么ShowWindow可以不用)
最后运行,可以看到显示添加的button在框架显示栏范围内(根据需要调整button大小位置让其显示在合理位置即可)
重点:关于CButton类提供的成员函数Create 和CButton的父类CWnd提供的ShowWindow说明如下:
Create |
Creates the Windows button control and attaches it to the CButton object.
|
CButton::Create |
Example See Also Send Feedback |
Creates the Windows button control and attaches it to the CButton object.
|
Parameters
lpszCaption
Specifies the button control's text.
dwStyle
Specifies the button control's style. Apply any combination of button styles to the button.
rect
Specifies the button control's size and position. It can be either a CRect object or a RECT structure.
pParentWnd
Specifies the button control's parent window, usually a CDialog. It must not be NULL.
nID
Specifies the button control's ID.
Return Value
Nonzero if successful; otherwise 0.
Remarks
You construct a CButton object in two steps. First, call the constructor and then call Create, which creates the Windows button control and attaches it to the CButton object.
If the WS_VISIBLE style is given, Windows sends the button control all the messages required to activate and show the button.
Apply the following window styles to a button control:
-
WS_CHILD Always
-
WS_VISIBLE Usually
-
WS_DISABLED Rarely
-
WS_GROUP To group controls
-
WS_TABSTOP To include the button in the tabbing order
Example
Visual C++ | Copy Code |
---|---|
|
MFC Library Reference |
CWnd::ShowWindow |
Example See Also Send Feedback |
Sets the visibility state of the window.
|
Parameters
nCmdShow
Specifies how the CWnd is to be shown. It must be one of the following values:
-
SW_HIDE Hides this window and passes activation to another window.
-
SW_MINIMIZE Minimizes the window and activates the top-level window in the system's list.
-
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position.
-
SW_SHOW Activates the window and displays it in its current size and position.
-
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
-
SW_SHOWMINIMIZED Activates the window and displays it as an icon.
-
SW_SHOWMINNOACTIVE Displays the window as an icon. The window that is currently active remains active.
-
SW_SHOWNA Displays the window in its current state. The window that is currently active remains active.
-
SW_SHOWNOACTIVATE Displays the window in its most recent size and position. The window that is currently active remains active.
-
SW_SHOWNORMAL Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position.
Return Value
Nonzero if the window was previously visible; 0 if the CWnd was previously hidden.
Remarks
ShowWindow must be called only once per application for the main window with CWinApp::m_nCmdShow. Subsequent calls to ShowWindow must use one of the values listed above instead of the one specified by CWinApp::m_nCmdShow.
Example
Visual C++ | Copy Code |
---|---|
|
上一篇: 关于人工智能的二十件事