Vulkan

如何为切分的窗口使用属性页(从fromview继承)

前言

这篇文章是讲怎么样在切分出来的窗口(一半opengl绘图,一半对话框)中使用属性页。。。记下来以便以后用到!

以下方法是参考了两篇10多年前的文章,主要是第二篇。。

http://www.vckbase.com/index.php/wv/211

http://www.codeguru.com/cpp/controls/propertysheet/article.php/c591/Creating-a-Property-Sheet-Inside-a-Form-View.htm


MFC中opengl环境配置:http://blog.csdn.net/shenlan282/article/details/8821861

使用CSplitterWnd切分窗口:http://blog.csdn.net/shenlan282/article/details/7183832

接下来就是讲怎么样在左半部分切分的窗口中使用属性页:

初始界面如图:


参照第二篇文章,详细步骤如下:

第一步: Create a "place holder" control in your form view's template

打开切分出来的左半部分的资源对话框,打开 工具箱,拖动一个picture control控件添加到对话框中,该控件ID为 IDC_PLACEHOLDER


第二步:Create a derived CPropertySheet class

切换到类视图模式,右击工程名,类向导((这里不要点击 添加-类)),右上角有个添加类,添加一个 CMyPropertySheet 类,继承自CPropertySheet

修改生成的类文件.h 的构造函数的参数,只保留一个

CMyPropSheet(CWnd* pParentWnd =NULL);

并且在CPP文件中把构造函数的实现改为:

  1. CMyPropSheet::CMyPropSheet(CWnd* pParentWnd):CPropertySheet(AFX_IDS_APP_TITLE,pParentWnd)
  2. {

  3. }

第三步:Add a pointer to the derived property sheet class in your form view class

在切分窗口类SplitterLeft中添加一个成员变量

 CMyPropertySheet * m_pMyPropSheet,

这里应该讲 CMyPropertySheet 类的头文件#include一下


第四步:Add code in CMyFormView::OnInitialUpdate() to create your property sheet

重载SplitterLeft的OnInitialUpdate() 方法(右击该类-属性-重载-找到该方法-添加),添加以下代码

	// create and asociated the property sheet with the "place holder" window
	CWnd* pwndPropSheetHolder = GetDlgItem(IDC_PLACEHOLDER);
	m_pMyPropSheet = new CMyPropertySheet(pwndPropSheetHolder);
	if (!m_pMyPropSheet->Create(pwndPropSheetHolder, 
		WS_CHILD | WS_VISIBLE, 0))
	{
		delete m_pMyPropSheet;
		m_pMyPropSheet = NULL;
		return;
	}
 
	// fit the property sheet into the place holder window, and show it
	CRect rectPropSheet;
	pwndPropSheetHolder->GetWindowRect(rectPropSheet);
	m_pMyPropSheet->SetWindowPos(NULL, 0, 0,
		rectPropSheet.Width(), rectPropSheet.Height(),
		SWP_NOZORDER | SWP_NOACTIVATE);

第五步:Create the pages by deriving from CPropertyPage

添加N个资源对话框,这些对话框用来作为propertyPage,每个对话框的Caption改为你想显示的名字,Style为child,Border为thin,只选中Titile Bar复选框,去掉其他复选框。为每个对话框添加不同的ID_

为每个对话框添加一个类(右键该资源对话框,添加类)继承自CPropertyPage,比如为Page1,Page2


第六步:Add the page's objects as member variables to the propery sheet class

为 CMyPropertySheet 类添加子对话框的类对象:右击CMyPropertySheet 类-添加变量

Page1 m_page1;

Page2 m_page2;

第七步:Add page insertion code in the derived property sheet's constructor


CMyPropertySheet 类的实现中把这Page类对象add进去

  1. CMyPropSheet::CMyPropSheet(CWnd* pParentWnd)
    	:CPropertySheet(AFX_IDS_APP_TITLE, pParentWnd)
    {
    	AddPage(&m_page1);
    	AddPage(&m_page2);
    	......
    }


第八步:Bingo~~~



注:转载请注明出处!


posted on 2013-04-20 13:21  Vulkan  阅读(330)  评论(0编辑  收藏  举报

导航