在SDI中的FormView建立起属性页,总是不行,大家帮忙看看!

clack234 2003-08-19 05:36:30
我先是在FormView0.h中声明了:
CViewPropertySheet m_PropSheet;

CMYPropertyPage m_Page1;
CMYPropertyPage2 m_Page2;

然后:在FormView0.h中加入:
BOOL CFormView0::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{

m_PropSheet.AddPage(&m_Page1);
m_PropSheet.AddPage(&m_Page2);


// create a modeless property sheet
if (!m_PropSheet.Create(this)) {
DestroyWindow();
return FALSE;
}

return TRUE;
}


编译时也通过了。显示属性页框,没有显示主窗体,就发生了断言错误:
Debug Assertion Failed:
Winfrm.cpp Line(1177)
WinCore.cpp Line(2198)

我所写的代码,参考了:
http://www.codeguru.com/propertysheet/inside_formview.shtml
不过这是个MDI。

我该怎么办?请高手指点!
...全文
82 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
clack234 2003-08-20
  • 打赏
  • 举报
回复
我在VCBASE和CodeGuru都看过这文章.我照着做了,总是出错!
昨天晚上到CodeProject去问了,两个小时后就有人给解决了.
yurling 2003-08-20
  • 打赏
  • 举报
回复
我就是照着它做的,一点问题也没有啊
xiaoliuzi 2003-08-20
  • 打赏
  • 举报
回复
mark
yurling 2003-08-20
  • 打赏
  • 举报
回复
是不是想在formview里面创建一个属性页?
看看下边这篇文章合不合适你用吧:

Creating a Property Sheet Inside a Form View - Asaf Levy
--------------------------------------------------------------------------------

This topic was contributed by Asaf Levy.
Form views (CFormView) can do almost anything you want: you can easily shape and modify it, process its control's messages, and communicate with the document. It's like creating a very important dialog box.

Property sheet (CPropertySheet) is also a very convinient and simple way to gather and display information. You create property pages using the dialog template editor, and simply add them to the propery sheet's object. Most importantly, the property sheet takes care of all the page's notification messages for you. All you have to be worried about is what your code will do, not where it is routed to, and who is actually getting it (each page intercepts its own IDC_blahblah's messages).

But, have you ever tried putting a propery sheet inside a form view, together with other controls like buttons, check boxes, list boxes, ect...? Sure, you can use the tab control (CTabControl), given in the dialog template editor. But who will take care of all the notification messages? YOU?? no way!! And how will you create the page's interfaces? BY HAND?? no way!!

To my opinion, these two reasons if far from enough to convince a sane programmer to look for a way out: property sheets inside a form view! It handels your notification messages and lets you add editable dialog templates to the sheet - what more can you possibly ask??

Now, lets look at how you do this. This task has a few simple steps:

Step 1: Create a "place holder" control in your form view's template
You have to create a control that will function as a place holder for the property sheet control. The most suitable control is the picture control: it will be the sheet's parent window. Make sure the control is Visible, and that it's on type Frame. Make it big enough to include the pages in it. Lets suppose that its ID of the picture control is IDC_PLACEHOLDER.
Step 2: Create a derived CPropertySheet class
Create a class derived from CPropertySheet using ClassWizard (lets call it CMyPropertySheet), and leave only one constructor with the parent window as its parameter:
CMyPropSheet(CWnd* pParentWnd = NULL);

Step 3: Add a pointer to the derived property sheet class in your form view class
In your derived form view class, add a pointer to the newly created derived property sheet class, so you can refer to it and use it later:
CMyPropSheet* m_pMyPropSheet;

Step 4: Add code in CMyFormView::OnInitialUpdate() to create your property sheet
Create a handler to WM_INITIALUPDATE in CMyFromView, and after the call to CFormView::OnInitialUpdate(), add code to create a Modeless Property Sheet and associate it with the place holder control.
// create and asociated the property sheet with the "place holder" window
CWnd* pwndPropSheetHolder = GetDlgItem(IDC_PLACEHOLDER);
m_pMyPropSheet = new CMyPropSheet(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);

Step 5: Create the pages by deriving from CPropertyPage
Create as many classes as you wish which are derived from CPropertyPage using ClassWizard, and leave them as they are (you will later handle the page control's specific messages there). Associate a different IDD_blahblah to every class.
Step 6: Add the page's objects as member variables to the propery sheet class
Declare objects of your page's derived types (as was created in step 5), and put them in the class declaration of your derived property sheet:
CMyPage1 m_pageMy1;
CMyPage2 m_pageMy2;
......

Step 7: Add page insertion code in the derived property sheet's constructor
Now you will associate the page's objects to your property sheet, by adding them to the sheet, using the CPropertySheet::AddPage(...) function.
Note: Here i put the code in the sheet's constructor, so it will be done automatically, but you can put this code anywhere you want in the derived property sheet class.

CMyPropSheet::CMyPropSheet(CWnd* pParentWnd)
:CPropertySheet(AFX_IDS_APP_TITLE, pParentWnd)
{
AddPage(&m_pageMy1);
AddPage(&m_pageMy2);
......
}

That's it. If you compile and run your application, you will now get a fully functional property sheets with pages you can edit easily!
All you have to do now is add message handlers in each page to the page's own control. Have Fun!!

clack234 2003-08-19
  • 打赏
  • 举报
回复
我试过了,没有用! :(
flashboy 2003-08-19
  • 打赏
  • 举报
回复
你应该在Create的时候带上这个标志:WS_CHILD |WS_VISIBLE
clack234 2003-08-19
  • 打赏
  • 举报
回复
up
clack234 2003-08-19
  • 打赏
  • 举报
回复
没人知道啊!55555~ 帮帮我!!

16,472

社区成员

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

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

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