这个问题大家来讨论讨论!!!

abigpot 2001-05-23 06:06:00
在一个程序中有多和CTreeView对象和一个CHtmlView对象,我想在一个CTreeView对象中获得CHtmlView对象的指针:
CMainFrame* h=(CFrameWnd*)AfxGetApp()->m_pMainWnd;
CView* Hview=h->GetActiveView();
这时获得的是CTreeView的指针;我该如何办???

我想是否可以在程序初始化的时候,使CHtmlView对象激活,这时GetActiveView()后,能否获得CHtmlView的指针。此想法可行吗?该怎样在初试化的时候激活CHtmlView呢?

我会继续加分!
...全文
205 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
abigpot 2001-05-25
  • 打赏
  • 举报
回复
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CenterWindow();
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.CreateEx(this) ||
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}


// TODO: Remove this if you don't want tool tips

m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY);
m_wndToolBar.GetToolBarCtrl().AddBitmap(2,IDR_TOOLBAR1);

//Create the image list to be used with the control bars.
m_ImageList.Create(IDB_IMAGELIST,13,1,RGB(0,255,0));

//CG:The following block was insert by the 'Dialog Bar' component
{
m_wndWorkspace.SetBtnImageList(&m_ImageList);
// m_wndWorkspace.SetMenuID(IDR_POPUP);

//Initialize dialog bar m_wndWorkspace
if(!m_wndWorkspace.Create(this,CG_ID_VIEW_WORKSPACE,
_T("索引"),CSize(220,150)))
{
TRACE0("Failed to create dialog bar m_wndWorkspace\n");
return -1;//fail to create
}
//Add the views to the tab control.
m_wndWorkspace.AddView(_T("小儿体格生长的特点"),RUNTIME_CLASS(CTreeViewTD));
m_wndWorkspace.AddView(_T("小儿体格生长的规律"),RUNTIME_CLASS(CTreeViewGL));
m_wndWorkspace.AddView(_T("小儿体格生长的评价"),RUNTIME_CLASS(CTreeViewPJ));
m_wndWorkspace.AddView(_T("影响体格生长的因素"),RUNTIME_CLASS(CTreeViewYS));

//Define the image list to use with the tab contol
// m_TabImages.Create(IDB_IL_TAB,16,1,RGB(0,255,0));
// m_wndWorkspace.SetTabImageList(&m_TabImages);

//allow bar to be resized when floating
m_wndWorkspace.SetBarStyle(m_wndWorkspace.GetBarStyle()|
CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);

m_wndWorkspace.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndWorkspace,AFX_IDW_DOCKBAR_LEFT);
}

return 0;
}
abigpot 2001-05-25
  • 打赏
  • 举报
回复
BOOL CMyApp::InitInstance()
{
AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif

// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

LoadStdProfileSettings(); // Load standard INI file options (including MRU)

// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.

CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);

// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;

// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}
hongv 2001-05-25
  • 打赏
  • 举报
回复
m_wndWorkspace既然有AddView(),也许会有GetView()一类的东西可以调用
hongv 2001-05-25
  • 打赏
  • 举报
回复
m_wndWorkspace是什么类的对象,使用了什么界面库么?
jy 2001-05-25
  • 打赏
  • 举报
回复
再看了一遍你的问题,发觉我的代码弄错了.
你是要View指针是吧?sessi的代码不能成功?
直接用CMainFrame::GetActiveView()?
那就是说,不知道你的代码在干什么了?

那我也没辙了!

最后一招:
全局变量m_pView;
在CMyView(即你的HtmlView)的初始化成功处加入:m_pView = this;
行了,我可不相信这都不行。
jy 2001-05-25
  • 打赏
  • 举报
回复
你的TreeView并没有像CMyView一样执行 AddDocTemplate(pDocTemplate);
来登记到CDocument派生类中,所以不能取得正确的pDoc指针。

如果想大盗你的目的,只能使用CMultiDocTemplate的AddDocTemplate()将TreeView和MyView都注册。
但是你这个程序时典型的SDI模式,所以,我有替代方案给你:

在CMainFrame中添加一个变量CMyDoc* m_pDoc;
在CmainFrame::OnCreate中设法初始化m_pDoc;
以后,在你的TreeView中通过((CMainFrame*)AfxGetMainWnd())->m_pDoc的方式访问你的pDoc。

------------
要想完成上述的初始化pDoc的工作,你必须使用这样的代码:
CMyView* pView;
pView = DYNAMIC_DOWNCAST(CMyView, GetActiveView());
ASSERT(pView);

m_pDoc = pView->GetDocment();
ASSERT_VALID(m_pDoc);


qzc77 2001-05-25
  • 打赏
  • 举报
回复
你可以在你的CDocument你添加两个变量(两个视图的的指针),
因为每个视图都有GetDocument得到CDocument,你在各个视图建立时CDocument的指针指向自己,那你不就可以随时在某个视图中得到另一个视图指针吗???
abigpot 2001-05-25
  • 打赏
  • 举报
回复
woding
hongv 2001-05-24
  • 打赏
  • 举报
回复
把下面两句
CMainFrame* h=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CMyDoc* HDoc=(CMyDoc*)h->GetActiveDocument();
换成
CMyDoc * HDoc=(CMyDoc *)GetDocument();
试试!

abigpot 2001-05-24
  • 打赏
  • 举报
回复
没人帮我!!!
abigpot 2001-05-24
  • 打赏
  • 举报
回复
~
)~
abigpot 2001-05-24
  • 打赏
  • 举报
回复
怎么没人理我!
abigpot 2001-05-24
  • 打赏
  • 举报
回复
CTreeView对象就象IE中的收藏或是历史对象,我是想要实现如它们一样的功能,点中某一项后CHtmlView对象定位到新的网址。我现在得不到CHtmlView对象的指针!!!
abigpot 2001-05-24
  • 打赏
  • 举报
回复
大哥大姐们,救命!
abigpot 2001-05-24
  • 打赏
  • 举报
回复
wo ding
abigpot 2001-05-24
  • 打赏
  • 举报
回复
void CTreeViewTD::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
HTREEITEM hSelected=m_TreeCtrl->GetSelectedItem();
CMainFrame* h=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CMyDoc* HDoc=(CMyDoc*)h->GetActiveDocument();

POSITION pos=HDoc->GetFirstViewPosition();
CView* pView =HDoc->GetNextView(pos);


*pResult = 0;
}
HDoc为什么返回0x00000000?
seesi 2001-05-24
  • 打赏
  • 举报
回复
1。在TreeView中写:
CWnd *wndForm;
while(!(wndForm=GetNextWindow())->IsKindOf(RUNTIME_CLASS(CXXHtmlView)))
{
;
}
2。在MainFrame中写一个Public的函数GetHtmlView
如果用分割窗口的方法,可以这样写
CWnd* pWnd=m_wndSplitter.GetPane(0,1);//参数请看分割时候的值
ASSERT(pWnd->IsKindOf(RUNTIME_CLASS(CDHtmlView)));
return (CDHtmlView*)pWnd;
然后这句话CView* Hview=h->GetActiveView();可以是h->GetHtmlView就得到了CHtmlView了
abigpot 2001-05-24
  • 打赏
  • 举报
回复
GetNextView()是文档对象的函数!
John11 2001-05-24
  • 打赏
  • 举报
回复
试试GetNextView()
abigpot 2001-05-24
  • 打赏
  • 举报
回复
期待
加载更多回复(7)

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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