窗口分割后,如何在一个视图中获得另外一个视图的句柄??
答案:2 悬赏:20 手机版
解决时间 2021-03-14 11:54
- 提问者网友:温旧梦泪无声
- 2021-03-13 17:32
多文档窗口静态分割为两个视图,想在一个视图中获得另外一个视图的句柄。多文档的分割是在childfrm中进行。。
最佳答案
- 五星知识达人网友:洒脱疯子
- 2021-03-13 18:15
先得到文档Doc *pDoc=GetDocument();
在用文档遍历视图GetFirstViewPosition()和GetNextView()
POSITION p2 = pDocument->GetFirstViewPosition(); //得到文档对应的第1个视图
while (p2 != NULL) //遍历文档对应的视图
{
CView *pView = pDocument->GetNextView(p2);
},然后通过视图类型获取
在用文档遍历视图GetFirstViewPosition()和GetNextView()
POSITION p2 = pDocument->GetFirstViewPosition(); //得到文档对应的第1个视图
while (p2 != NULL) //遍历文档对应的视图
{
CView *pView = pDocument->GetNextView(p2);
},然后通过视图类型获取
全部回答
- 1楼网友:猎心人
- 2021-03-13 18:41
1 在多文档多视图的mfc架构中,要想获得当前选中的cview可重写cview::onactivateview函数,如下:
void
onactivateview(bool bactivate,
cview * pactivateview,
cview * pdeactiveview)
{
if(bactivate)
{
setenable(true);
}
else
{
setenable(false);
}
cview::onactivateview(bactivate,
pactivateview,
pdeactiveview);
}
2 获得窗口或者视图句柄
2.1 获得窗口句柄
要找到某个cwnd对象的hwnd,用getsafehwnd()。
在窗口类中,有句柄的成员变量,可以直接访问: m_hwnd
在窗口类外,可以用afxgetmainwnd()->m_hwnd获得。
在mainframe里直接用this;
其它地方用 cmainframe* pmainframe = (cmainframe*)theapp.m_pmainwnd;
想得到一个控件的的句柄
getdlgitem(id…)->m_hwnd
2.2 获得视图的句柄
afxgetmainwnd()->getactiveview();
sdi: ((cframewnd*)(afxgetapp()->m_pmainwnd))->getactiveview();
mdi: ((cframewnd*)(afxgetapp()->m_pmainwnd))->getactiveframe()->getactiveview();
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯