怎样在CFormView中加一个属性表?该属性表不是弹出的,而是一直在CFormView的界面上的.请问这样的属性表怎样做?且怎样添加各个页?
解决方案 »
- MessageBox接收串口数据的问题
- 注册表问题.
- CListctrl控件按REPORT方式显示时, 如何使用GetItemData取得所有栏的内容?
- 帮忙看看GetQueuedCompletionStatus的问题,谢谢
- 看看这是什么引起的错误
- 在线等!谢谢!
- 越想越奇怪!MFC的源代码怎么能跟踪进去,自己编写的dll的源代码怎么不能跟踪进去呢?
- 关于在扩展DLL中显示对话框的问题
- 急!急!急!请问高手怎样判断父窗口发生变化(指大小)??
- 怎么使对话框上的按纽点击以后变灰和恢复?
- 高分求救算法:求一条直线与一个矩形相交点的坐标?
- 如何用CPropertySheet和CPropertyPage产生属性表,高手请指教?
http://www.codeguru.com/propertysheet/inside_formview.shtml
需要的话可以给你源代码
[email protected]//#if !defined EMBEDED_PAGE_H
#define EMBEDED_PAGE_H#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000// EmbededPage.h : header file
//BOOL CreateEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,DWORD dwStyle=WS_CHILD|WS_VISIBLE,DWORD dwStyleEx=0);
void PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,CRect rectPosition);
BOOL PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,UINT nIDIndicatorArea);#endif
////
#include "stdafx.h"
#include "UsePropertySheet.h"//include the resource
#include "EmbededPage.h"BOOL CreateEmbededSheet(
CWnd *pWndParent,
CPropertySheet *pSheet,
DWORD dwStyle,
DWORD dwStyleEx)
{
ASSERT_VALID(pWndParent);
ASSERT_VALID(pSheet); //Create the Sheet at the specified Parent window
if(!pSheet->Create(pWndParent,dwStyle,dwStyleEx))
{
TRACE0("Failed to create the embeded sheet\n");
return FALSE;
} //The sheet should have the style to access the TAB
pSheet->ModifyStyle(0,WS_TABSTOP);
// Allows the user to navigate among the child windows of
//the window by using the TAB key.
pSheet->ModifyStyleEx(0,WS_EX_CONTROLPARENT); //Assert the parent window have the style:WS_EX_CONTROLPARENT
pWndParent->ModifyStyleEx(0,WS_EX_CONTROLPARENT); return TRUE;
}void PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,CRect rectPosition)
{
ASSERT_VALID(pWndParent);
ASSERT_VALID(pSheet); //Get the tab control associated with the sheet
CTabCtrl *pTabCtrl=pSheet->GetTabControl();
ASSERT_VALID(pTabCtrl); CRect rectTab;
pTabCtrl->GetWindowRect(rectTab);
pWndParent->ScreenToClient(rectTab); CRect rectSheet;
pSheet->GetWindowRect(rectSheet);
pWndParent->ScreenToClient(rectSheet); //calculate the margin's size to right side
int cx=rectSheet.Width()-rectTab.Width();
int cy=rectSheet.Height()-rectTab.Height(); //Shift the sheet to appropriate pos
pSheet->MoveWindow(rectPosition.left,rectPosition.top,rectPosition.Width(),rectPosition.Height()); //shift the tab
pTabCtrl->SetWindowPos(NULL,0,0,rectPosition.Width()-cx,rectPosition.Height()-cy,SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
//activate all the pages ,avoid redrawing,just update it
int nCurrentPage=pSheet->GetActiveIndex();
for(int i=0;i<pSheet->GetPageCount();i++)
{
pSheet->SetActivePage(i);
}
pSheet->SetActivePage(nCurrentPage);}BOOL PositionEmbededSheet(CWnd *pWndParent,CPropertySheet *pSheet,UINT nIDIndicatorArea)
{
ASSERT_VALID(pWndParent);
ASSERT_VALID(pSheet);
//get the indicator's rect
CRect rectPos;
CWnd *pIndicatorCtrl=pWndParent->GetDlgItem(nIDIndicatorArea);
if(pIndicatorCtrl!=NULL)
{
pIndicatorCtrl->GetWindowRect(rectPos);
pWndParent->ScreenToClient(rectPos);
::PositionEmbededSheet(pWndParent,pSheet,rectPos);
return TRUE;
} return FALSE;
}
用法举例:
//BOOL CSheetDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
::CreateEmbededSheet(this,&m_sheet);
::PositionEmbededSheet(this,&m_sheet,IDC_STATIC_SHEET_AREA);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}//----------------------------------------------------
void CUsePropertySheetView::OnInitialUpdate()
{
CFormView::OnInitialUpdate(); ::CreateEmbededSheet(this,&m_sheet);
::PositionEmbededSheet(this,&m_sheet,IDC_SHEET_AREA);
//change the size of the formview to contain the sheet
GetParentFrame()->RecalcLayout();
this->ResizeParentToFit(FALSE);
this->ResizeParentToFit(TRUE);
// set the focus to first control with the tabstop
CWnd *pChild=this->GetWindow(GW_CHILD);
while(pChild!=NULL&&(pChild->GetStyle()&WS_TABSTOP)==0)
{
pChild=pChild->GetNextWindow();
} if(pChild!=NULL)
{
pChild->SetFocus();
}}
void CUsePropertySheetView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
// update data in here
//interview with CDocument
//UpdateData(FALSE);
//if(m_sheet.GetSafeHwnd()!=NULL)
//m_sheet.GetActivePage()->UpdateData(FALSE);
}
void CUsePropertySheetView::OnApply( )
{
// TODO: Add your specialized code here and/or call the base class
this->UpdateData(true);
//m_sheet.GetActivePage()->UpdateData(true);
//interview with CDocument
//UpdateData(TRUE);
//pDoc->SetModifiedFlag(TRUE);
//pDoc->UpdateAllViews(this);
}