很多问题。。。

maxh718 2000-11-23 09:47:00
1单文档,多视的拆分窗口,如何在窗口大小改变时,其中的一个视大小不变?
2如何用最简单的方法在SDI窗口中实现两个视的切换,像属性页一样,但不是对话框。
...全文
88 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
RedFire 2000-11-23
  • 打赏
  • 举报
回复
1、视类也是从窗口类继承而来的,你自己处理视类的WM_SIZE不就行了吗?
2、下面的例子是从《VC++技术内幕5.0》中直接拷贝出来的,都是E文,不过很容易看懂的。

The EX20C Example—Switching View Classes Without a Splitter
Sometimes you just want to switch view classes under program control and you don't want to be bothered with a splitter window. The EX20C example is an SDI application that switches between CStringView and CHexView in response to selections on the View menu. Starting with what AppWizard generates, all you need to do is add two new menu commands and then add some code to the CMainFrame class. You also need to change the CStringView and CHexView constructors from protected to public.

Resource Requirements
The following two items have been added to the View menu in the IDR_MAINFRAME menu resource. Caption Command ID CMainFrame Function
St&ring View ID_VIEW_STRINGVIEW OnViewStringView
&Hex View ID_VIEW_HEXVIEW OnViewHexView


ClassWizard was used to add the command-handling functions (and corresponding update command UI handlers) to the CMainFrame class.

CMainFrame
The CMainFrame class gets a new private helper function, SwitchToView, which is called from the two menu command handlers. The enum parameter tells the function which view to switch to. Here are the two added items in the MainFrm.h header file:


private:
enum eView { STRING = 1, HEX = 2 };
void SwitchToView(eView nView);
The SwitchToView function (in MainFrm.cpp) makes some low-level MFC calls to locate the requested view and to activate it. Don't worry about how it works. Just adapt it to your own applications when you want the view- switching feature. Add the following code:


void CMainFrame::SwitchToView(eView nView)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = (CView*) GetDlgItem(nView);
if (pNewActiveView == NULL) {
switch (nView) {
case STRING:
pNewActiveView = (CView*) new CStringView;
break;
case HEX:
pNewActiveView = (CView*) new CHexView;
break;
}
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
pNewActiveView->Create(NULL, NULL, WS_BORDER,
CFrameWnd::rectDefault, this, nView, &context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView);
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(
pOldActiveView->GetRuntimeClass() ==
RUNTIME_CLASS(CStringView) ? STRING : HEX);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
}
Finally, here are the menu command handlers and update command UI handlers that ClassWizard initially generated (along with message map entries and prototypes). The update command UI handlers test the current view's class.


void CMainFrame::OnViewStringView()
{
SwitchToView(STRING);
}

void CMainFrame::OnUpdateViewStringView(CCmdUI* pCmdUI)
{
pCmdUI->Enable(
!GetActiveView()->IsKindOf(RUNTIME_CLASS(CStringView)));
}

void CMainFrame::OnViewHexView()
{
SwitchToView(HEX);
}

void CMainFrame::OnUpdateViewHexView(CCmdUI* pCmdUI)
{
pCmdUI->Enable(
!GetActiveView()->IsKindOf(RUNTIME_CLASS(CHexView)));
}

16,471

社区成员

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

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

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