深入浅出MFC第2版 92 页有个地方没有看懂。求指点

rainmarker 2010-08-26 05:05:56
BOOL CWnd::CreateEx()
{
cout<<“CWnd::CreateEx \n";
PreCreateWindow();

return TRUE;
}

这个PreCreateWindow(); 为什么 是调用CFrameWnd::PreCreateWindow 而不是调用CWnd::PreCreateWindow();
...全文
168 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainmarker 2010-08-28
  • 打赏
  • 举报
回复
谢谢。可能是虚函数我没有理解彻底。
rainmarker 2010-08-27
  • 打赏
  • 举报
回复
这么说来是多态,可是我并没有看到基类(CWnd)指针或引用来调用PreCreateWindow()
pro_To_Life 2010-08-27
  • 打赏
  • 举报
回复
既然给了虚函数,目的就一定是要实现多态,不需要明确指明,规定的就是自动调用,
你要能看到基类(CWnd)指针调用PreCreateWindow(),那才奇怪呢,因为虚函数不能直接使用。只能继承使用,好好看看多态方面的吧,对你十分有帮助
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
没有虚函数,多态怎么实现呢
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
多态性,是一种能给程序带来灵活性的东西。看过《设计模式》的程序员应该都知道,相当多的模式(几乎所有)都是依靠多态来实现的,以此给程序提供可扩展、可重用性。在《再谈多态——向上映射及VMT/DMT》一文中,提到了多态性是依赖于虚函数/虚方法(即动态绑定)来实现的,也介绍了虚函数/虚方法(virtual)的实现方法
rainmarker 2010-08-26
  • 打赏
  • 举报
回复
好像是虚函数的问题, 不是多态的问题。不过还是谢谢。
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
多态的原理
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
虚函数,只能在继承后覆盖使用吧
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
CWnd::PreCreateWindow
Example See Also Send Feedback


Called by the framework before the creation of the Windows window attached to this CWnd object.


virtual BOOL PreCreateWindow(
CREATESTRUCT& cs
);
是虚拟的,不能直接CWnd::PreCreateWindow()使用
rainmarker 2010-08-26
  • 打赏
  • 举报
回复
现在的问题是调用CFrameWnd::PreCreateWindow 而不是调用CWnd::PreCreateWindow(); 有点整不明白。
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
class CFrameWnd没有自己定义PreCreateWindow这个方法,直接继承 CWnd的,所以只能调用CWnd::PreCreateWindow()
rainmarker 2010-08-26
  • 打赏
  • 举报
回复
覆盖?
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
CFrameWnd Members
See Also Send Feedback


Base Class Members

CObject Members

CCmdTarget Members

CWnd Members

m_bAutoMenuEnable
Controls automatic enable and disable functionality for menu items.

rectDefault
Pass this static CRect as a parameter when creating a CFrameWnd object to allow Windows to choose the window's initial size and position.

CFrameWnd
Constructs a CFrameWnd object.

Create
Call to create and initialize the Windows frame window associated with the CFrameWnd object.

GetDockState
Retrieves the dock state of a frame window.

LoadAccelTable
Call to load an accelerator table.

LoadBarState
Call to restore control bar settings.

LoadFrame
Call to dynamically create a frame window from resource information.

SaveBarState
Call to save control bar settings.

SetDockState
Call to dock the frame window in the main window.

ShowControlBar
Call to show the control bar.

ActivateFrame
Makes the frame visible and available to the user.

BeginModalState
Sets the frame window to modal.

CreateView
Creates a view within a frame that is not derived from CView.

DockControlBar
Docks a control bar.

EnableDocking
Allows a control bar to be docked.

EndModalState
Ends the frame window's modal state. Enables all of the windows disabled by BeginModalState.

FloatControlBar
Floats a control bar.

GetActiveDocument
Returns the active CDocument object.

GetActiveFrame
Returns the active CFrameWnd object.

GetActiveView
Returns the active CView object.

GetControlBar
Retrieves the control bar.

GetMenuBarState
Retrieves the display state of the menu in the current MFC application.

GetMenuBarVisibility
Indicates whether the default behavior of the menu in the current MFC application is either hidden or visible.

GetMessageString
Retrieves message corresponding to a command ID.

GetTitle
Retrieves the title of the related control bar.

InitialUpdateFrame
Causes the OnInitialUpdate member function belonging to all views in the frame window to be called.

InModalState
Returns a value indicating whether or not a frame window is in a modal state.

IsTracking
Determines if splitter bar is currently being moved.

RecalcLayout
Repositions the control bars of the CFrameWnd object.

SetActiveView
Sets the active CView object.

SetMenuBarState
Sets the display state of the menu in the current MFC application to hidden or displayed.

SetMenuBarVisibility
Sets the default behavior of the menu in the current MFC application to be either hidden or visible.

SetMessageText
Sets the text of a standard status bar.

SetTitle
Sets the title of the related control bar.

ShowOwnedWindows
Shows all windows that are descendants of the CFrameWnd object.

GetMessageBar
Returns a pointer to the status bar belonging to the frame window.

NegotiateBorderSpace
Negotiates border space in the frame window.

OnCreateClient
Creates a client window for the frame.

OnSetPreviewMode
Sets the application's main frame window into and out of print-preview mode.

OnBarCheck
Called whenever an action is performed on the specified control bar.

OnContextHelp
Handles SHIFT+F1 Help for in-place items.

OnUpdateControlBarMenu
Called by the framework when the associated menu is updated.

OnHideMenuBar
Called before the menu in the current MFC application is hidden.

OnShowMenuBar
Called before the menu in the current MFC application is displayed.

可以看出,class CFrameWnd没有PreCreateWindow这个方法,是继承 CWnd,直接使用的。
所以只能调用CWnd::PreCreateWindow();
pro_To_Life 2010-08-26
  • 打赏
  • 举报
回复
应该是覆盖吧,class CFrameWnd : public CWnd
继承关系
CFrameWnd::PreCreateWindow覆盖CWnd::PreCreateWindow()
csucdl 2010-08-26
  • 打赏
  • 举报
回复
建议去看看CFrameWnd::PreCreateWindow 源代码, 一切真相大白

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧