调整属性表大小时出错
Errors with resizing property sheet
我正在尝试使用示例 http://support.microsoft.com/kb/300606 制作可重新调整大小的属性表。但是,我的代码中出现了几个我不知道如何克服的错误。我使用对话框上的类向导创建了属性表。我只需要文章中提到的重新调整大小功能。任何帮助将不胜感激。
.cpp类
#include "stdafx.h"
#include "Geometry.h"
#include "GeoSheet.h"
// CGeoSheet
IMPLEMENT_DYNAMIC(CGeoSheet, CPropertySheet)
CGeoSheet::CGeoSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
{
}
CGeoSheet::CGeoSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaption, pParentWnd, iSelectPage)
{
}
CGeoSheet::~CGeoSheet()
{
}
BEGIN_MESSAGE_MAP(CGeoSheet, CPropertySheet)
ON_COMMAND(IDOK, OnOK)
END_MESSAGE_MAP()
// CGeoSheet message handlers
void CGeoSheet::OnOK()
{
CPropertySheet::OnClose();
}
// Overriding DoModal() allows us to hook our callback into
// the prop sheet creation
int CGeoSheet::DoModal()
{
// Hook into property sheet creation code
AFX_OLDPROPSHEETHEADER* psh = GetPropSheetHeader();
psh->dwFlags |= PSH_USECALLBACK;
psh->pfnCallback = XmnPropSheetCallback;
return CPropertySheet::DoModal();
}
// This function must be a STATIC member function.
//Callback to allow us set the default window styles
// for the property sheet
int CGeoSheet ::XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam)
{
extern int CALLBACK AfxPropSheetCallback(HWND, UINT message, LPARAM lParam);
// XMN: Call MFC's callback
int nRes = AfxPropSheetCallback(hWnd, message, lParam);
switch (message)
{
case PSCB_PRECREATE:
// Set our own window styles
((LPDLGTEMPLATE)lParam)->style |= (DS_3DLOOK | DS_SETFONT
| WS_THICKFRAME | WS_SYSMENU | WS_POPUP | WS_VISIBLE | WS_CAPTION);
break;
}
return nRes;
}
.h 文件
#pragma once
// CGeoSheet
class CGeoSheet : public CPropertySheet
{
DECLARE_DYNAMIC(CGeoSheet)
public:
CGeoSheet(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
CGeoSheet(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
virtual ~CGeoSheet();
protected:
DECLARE_MESSAGE_MAP()
//{{AFX_MSG(CMyPropertySheet)
// NOTE - the ClassWizard will add and remove member functions here.
afx_msg void OnOK();
int CGeoSheet::DoModal();
int CGeoSheet ::XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam);
//}}AFX_MSG
};
我不断收到这些错误。
geosheet.cpp(49) : error C2065: 'AFX_OLDPROPSHEETHEADER' : undeclared identifier
geosheet.cpp(49) : error C2065: 'psh' : undeclared identifier
geosheet.cpp(49) : error C3861: 'GetPropSheetHeader': identifier not found
geosheet.cpp(50) : error C2065: 'psh' : undeclared identifier
geosheet.cpp(50) : error C2227: left of '->dwFlags' must point to class/struct/union/generic type
type is ''unknown-type''
geosheet.cpp(51) : error C2065: 'psh' : undeclared identifier
geosheet.cpp(51) : error C2227: left of '->pfnCallback' must point to class/struct/union/generic type
type is ''unknown-type''
编辑我根据 http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc/2005-09/msg00585.html 修改了DoModal 函数;现在我得到这个错误。
法典:
int CGeoSheet::DoModal()
{
// Hook into property sheet creation code
m_psh.dwFlags |= PSH_USECALLBACK;
m_psh.pfnCallback = XmnPropSheetCallback;// <--Error
return CPropertySheet::DoModal();
}
错误:
geosheet.cpp(50) : error C2440: '=' : cannot convert from 'int (__cdecl *)(HWND,UINT,LPARAM)' to 'PFNPROPSHEETCALLBACK'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
您使用了 CWndResizer 类,可以调整属性表的大小。
在头文件中包括 cwndresizer 类和此类的 make 对象。CWndResizer reizer;
在 cpp 文件中,可以调整属性表中所有控件的大小。
BOOL ClassName::OnInitDialog(){
CPropertySheet::OnInitDialog();
BOOL ok = FALSE;
ok = resizer.Hook(this);
ASSERT(ok);
IDC_POLYGONS_LIST要调整大小的控件 ID
ok = resizer.SetAnchor(IDC_POLYGONS_LIST,ANCHOR_LEFT|ANCHOR_TOP|ANCHOR_BOTTOM);
ASSERT(ok);
bOk = resizer.SetParent("CS",IDC_STATIC_GROUPBOX2);
ASSERT(bOk);
}
有关更多详细信息,请点击此链接。http://www.codeproject.com/Articles/125068/MFC-C-Helper-Class-for-Window-Resizing
错误是因为在 .h 中您忘记将回调设置为静态
int CGeoSheet ::XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam);
应该是
static int CGeoSheet::XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam);
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 为什么在读取文件大小时文件IO速度会发生变化
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 调整模板对象矢量大小时出错
- 调整属性表大小时出错
- 读取线程应用程序(linux,pthreads)中的文件大小时出错
- 尝试获取C++上的当前进程内存大小时出错,MinGW
- 2D 矢量中的 push_back() 在使用动态大小时出错