BOOL CMainFrame::SubClassButton( HWND hwnd )
{
CSkinButton * btn = new CSkinButton();
CWnd* pWnd = CWnd::FromHandlePermanent(hwnd);
if ( pWnd == NULL)
{
btn->SubclassWindow(hwnd); //Line 251
btn->SetResource(&m_btnres); return TRUE;
}
return FALSE;
}
\MainFrm.cpp(251) : warning C4003: not enough actual parameters for macro 'SubclassWindow'
\MainFrm.cpp(251) : error C2059: syntax error : '('
\MainFrm.cpp(252) : error C2039: 'btn' : is not a member of 'CSkinButton'
e:\project\themesong\skincomm\skinbutton.h(37) : see declaration of 'CSkinButton'
Error executing cl.exe.
说明:
1。CSkinButton继承自CButton,没有重载SubclassWindow函数
2。完全相同的代码放在基于dialog的程序中,写在CTestDlg中就没有任何问题
但是转移到single Document(use FormView)上这段代码不管放在CMainFram还是
CTestFormView中都是报这两个错。本来可能会运行出错,但是编译出错就说不过去了,这里难道与是不是dialog有关?
3。btn->SubclassWindow(hwnd); //Line 251
这句话改为btn->SubclassWindow(this,hwnd); 就不会报警告,奇怪,为什么要多加一个参数?而且这个警告说“for macro 'SubclassWindow'“ 什么意思?
{
CSkinButton * btn = new CSkinButton();
CWnd* pWnd = CWnd::FromHandlePermanent(hwnd);
if ( pWnd == NULL)
{
btn->SubclassWindow(hwnd); //Line 251
btn->SetResource(&m_btnres); return TRUE;
}
return FALSE;
}
\MainFrm.cpp(251) : warning C4003: not enough actual parameters for macro 'SubclassWindow'
\MainFrm.cpp(251) : error C2059: syntax error : '('
\MainFrm.cpp(252) : error C2039: 'btn' : is not a member of 'CSkinButton'
e:\project\themesong\skincomm\skinbutton.h(37) : see declaration of 'CSkinButton'
Error executing cl.exe.
说明:
1。CSkinButton继承自CButton,没有重载SubclassWindow函数
2。完全相同的代码放在基于dialog的程序中,写在CTestDlg中就没有任何问题
但是转移到single Document(use FormView)上这段代码不管放在CMainFram还是
CTestFormView中都是报这两个错。本来可能会运行出错,但是编译出错就说不过去了,这里难道与是不是dialog有关?
3。btn->SubclassWindow(hwnd); //Line 251
这句话改为btn->SubclassWindow(this,hwnd); 就不会报警告,奇怪,为什么要多加一个参数?而且这个警告说“for macro 'SubclassWindow'“ 什么意思?
解决方案 »
- mfc中ole嵌入word, 删除word对象时界面的刷新问题
- VC中有没有类似C#中DataSet这种的离线数据集?
- 关于CFileDialog的问题
- 子窗口的内容怎么样保存?
- 控件背景透明化问题
- 问一个保留上次记录的问题?谢谢!
- 求助:c#用Chart控件编写Realtime Curve时,遇到的问题。。。(求大神帮忙看哪儿出问题了))
- CSDN首页这次改得太TMD难看,鸟字体在我的98+15"显示器上看起来累死人!
- hotmail邮箱帐户在foxmail中怎样设smtp和pop
- VC编译错误error LNK2001: unresolved external symbol "void __cdecl NR::broydn(class N
- 超类化和子类化是什么意思呀?
- 如何尽可能减小release版本的exe文件的大小?
class CSkinButton : public CButton
{
DECLARE_DYNAMIC(CSkinButton)
。。
}他怎么说
'btn' : is not a member of 'CSkinButton' ???
但是放在基于dialog的CMyDialog中又没有任何问题!
Call this member function to "dynamically subclass" a window and attach it to this CWnd object. When a window is dynamically subclassed, windows messages will route through the CWnd’s message map and call message handlers in the CWnd’s class first. Messages that are passed to the base class will be passed to the default message handler in the window.This member function attaches the Windows control to a CWnd object and replaces the window’s WndProc and AfxWndProc functions. The function stores a pointer to the old WndProc in the CWnd object.
BOOL SubclassWindow( HWND hWnd );Return ValueNonzero if the function is successful; otherwise 0.ParametershWndA handle to the window.
class CSkinTestDlg : public CDialog
{}用
BOOL CSkinTestDlg::SubClassButton( HWND hwnd )
就没有任何问题,
而一旦改为
BOOL CMainFrame::SubClassButton( HWND hwnd )
怎么就编译通不过???还有,SubclassWindow到底是做什么的呢?
子类化,将你的控件和一个类关联起来
哪个控件和哪个类呢?
那么btn->SubclassWindow(hwnd);
是btn这个控件了,hwnd有什么用,我传的是mainFrame的hwnd.
如果是dialog的话,我传的是dialog的hwnd
“如果是dialog的话,我传的是dialog的hwnd“
我是一个回调函数调用SubClassButton( HWND hwnd )
这个hwnd应该是dialog上的控件的句柄,比如一个button的hwnd
The Windowsx.h file is a header that includes message cracker macros to help programmers write more portable Windows-based applications. The header file contains a preprocessor macro named SubclassWindow. The macro bears the same name as the CWnd::SubclassWindow() member function. The macro has two parameters; the member function has only one parameter. The preprocessor tries to expand the symbol SubclassWindow when it is found. RESOLUTION
You can un-define the macro as follows:
#undef SubclassWindow
还有,试试用CWnd::SubclassDlgItem
BOOL SubclassDlgItem( UINT nID, CWnd* pParent );将251、252行改为
SubclassDlgItem(m_btnres,btn);
BOOL CSkinTestDlg::SubClassButton( HWND hwnd )
BOOL CMainFrame::SubClassButton( HWND hwnd )
中相同的语句
btn->SubclassWindow(hwnd);
其实调用的是不同的地方的SubclassWindow(); ?
不然怎么会一个地方编译成功,另外一个地方有警告,
不过就算这个地方解决,后面还有两个error还是没有解决,为什么从
dialog--->single document(formView)就会产生这个问题?
Call this member function to “dynamically subclass” a control created from a dialog template and attach it to this CWnd object. When a control is dynamically subclassed, windows messages will route through the CWnd’s message map and call message handlers in the CWnd’s class first. Messages that are passed to the base class will be passed to the default message handler in the control.这个好像不懂
为什么从dialog--->single document(formView)就会产生这个问题?我也不是很清楚。不过我感觉可能是hwnd的问题。subclasswindow是把hwnd所代表的窗体子类化,你传递CMainFrame的hwnd应该是不行的,而应该是你说想子类化的窗体的hwnd,比如说一个button的hwnd。
有一个问题,你的m_btnres是一个button的ID吗?你的这些控件是动态创建的呢还是用对话框模板创建的。如果你是用对话框模板创建的,其实只要用class wizard把m_btnres这个控件和一个cskinbutton的对象连接起来就可以了,这样所有的消息就会先发到cskinbutton,这样你就不用subclsswindow和subclassdlgitem了。
2。是用对话框模板创建的。
你的意思我好像明白了,谢谢了,我试试看。我的目的是用一个回调函数遍历对话框上的所有button,
确实如你所猜测,是想给所有button"运行时动态换肤"
现在想移植到基于single document(FormView)。
然后就出现这些问题。
为此我还有另外一个贴子问相关的问题,见(怎么取到FormView类的对话框资源?)
http://expert.csdn.net/Expert/topic/1862/1862710.xml?temp=.7848627还有,原来基于dialog的代码可以到一下地址看看:
http://www.vckbase.com/document/viewdoc.asp?id=529
有讲解,并且有下载源吗连结。很感谢你耐心回答我的问题,其实我觉得我这样问真是叫别人头晕。呵呵。
btn->SubclassDlgItem(IDC_BUTTON1,btn);
就可以吧,
但是好像还是没有任何效果,就是没有任何编译错误而已。
我想你把所有这些代码都放在CTestFormView里,hwnd就取CTestFormView的m_hWnd应该可以。你说的编译错误可以试试在SubClassButton函数第一句添加
#undef SubclassWindow
关键是:
在SubClassButton函数第一句添加
#undef SubclassWindow特别谢谢escout!
“
在SubClassButton函数第一句添加
#undef SubclassWindow“起到一个什么作用?难道移植到single document时候
编译器去找到宏,然后用这句,叫他不要去找了,这样就和
原来dialog时候用的是一个SubclassWindow????不管又没有回答,最晚明天结贴!