View类里面这三个得到的有区别?(SDI) CMainFrame* ss=(CMainFrame*)AfxGetMainWnd();
CMainFrame* ss=(CMainFrame*)GetParent();
CMainFrame* ss=(CMainFrame*)AfxGetApp()->m_pMainWnd;
解决方案 »
- 关于CreateRemoteThread在VC6.0运行的问题....
- ocx技术是针对ActiveX而言的吗? 还是它包含了更多的东西?
- 向各位高手请教:Socket实现Http协议Post请求,通过构造Soap包方式访问WebService?
- 获得1个字符串的长度
- 在VC6.0,如果改变Combo Box控件宽度!那位朋友熟悉的,进来告诉指点一下!
- (怪异问题,非高手勿进)使用自定义框架创建子窗口时的怪异问题!
- 想让程序在某处暂停一段时间该怎么办
- 新手求教,刷新Edit Box控件的显示导致CPU占用达到100%
- CButton 实际上就是Activex控件吧?
- ★★收到研究生录取通知书,散分.(顺便问个问题)★★
- 能否使用win32实现一部分显示动态刷新,另一部分正常的接收用户命令,显示处理结果?
- fatal error LNK1104: cannot open file "libeay32.dll",Error executing link.exe.
第二个View是Mainframe子窗口时成立
请指教!
CMainFrame* ss=(CMainFrame*)AfxGetApp()->m_pMainWnd;
这两条语句运行结果是相同的。至于CMainFrame* ss=(CMainFrame*)GetParent(); 嘛,只有作为CMainFrame的子窗口做调用,才能得到正确的结果。在对象Create(WM_CREATE消息映射)的时候,有一个参数(CWnd* pParent)就是用来指定当前对象的父窗口的。
CMainFrame* ss=(CMainFrame*)AfxGetApp()->m_pMainWnd;相同
CMainFrame* ss=(CMainFrame*)GetParent(); 只有在特定的环境才正确,如果当前父窗口不是CMainFrame类型,很危险,通常还是建议用上面两种方法
不过对于单文档来说,view窗口是Frame的子窗口,为什么得到的还是不一样呢?view窗口是不是Frame的子窗口呢?
不一样,我是这么测试的:
class CTestView : public CView
{
public:
CButton dd;
}int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{ CMainFrame* ss=(CMainFrame*)GetParent();
// CMainFrame* ss=(CMainFrame *)AfxGetApp()->m_pMainWnd;
dd.Create("sd",WS_VISIBLE,CRect(0,0,100,100),ss,104);
dd.ShowWindow(SW_SHOW);}
没问题int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{// CMainFrame* ss=(CMainFrame*)GetParent();
CMainFrame* ss=(CMainFrame *)AfxGetApp()->m_pMainWnd;
dd.Create("sd",WS_VISIBLE,CRect(0,0,100,100),ss,104);
dd.ShowWindow(SW_SHOW);}
有问题
第二个仅仅返回Parent,不能保证是CMainFrame
第三个在任何线程使用都将返回主线程的CMainFrame,最好。
这里GetParent()和GetTopLevelFrame( ) 一样,总的来说还是用GetTopLevelFrame( ),那两个AFX函数不能用。
怎么可能是自身呢?!
自身this不就完了。
CWnd::GetParent
CWnd* GetParent( ) const;Return ValueIdentifies the parent window if the member function is successful. Otherwise, the value is NULL, which indicates an error or no parent window. The returned pointer may be temporary and should not be stored for later use.