我在类这么定义
ie_browser_dlg();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); //这是我要添加的函数
~ie_browser_dlg(void);
enum { IDD = IDD_DLG_BROWSER };
BEGIN_MSG_MAP(ie_browser_dlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
MESSAGE_HANDLER(WM_COMMAND, OnCommand)
// MESSAGE_HANDLER(WM_CTLCOLORDLG, OnCtlColor)
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorStatic)
CHAIN_MSG_MAP(CAxDialogImpl<ie_browser_dlg>)
ON_WM_CTLCOLOR()
END_MSG_MAP()
这是在相应的cpp文件中实现的代码
HBRUSH ie_browser_dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
if(nCtlColor==CTLCOLOR_DLG)
{
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(0,0,220));
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
return hbr;
}
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C2146: 语法错误 : 缺少“;”(在标识符“HBRUSH”的前面)
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C2061: 语法错误 : 标识符“CDC”
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(50) : error C2143: 语法错误 : 缺少“;”(在“break”的前面)
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(49) : error C3861: “ON_WM_CTLCOLOR”: 找不到标识符
1>main_ww_item_obj.cpp
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C2146: 语法错误 : 缺少“;”(在标识符“HBRUSH”的前面)
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C2061: 语法错误 : 标识符“CDC”
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(50) : error C2143: 语法错误 : 缺少“;”(在“break”的前面)
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(49) : error C3861: “ON_WM_CTLCOLOR”: 找不到标识符
1>ie_browser.cpp
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C2146: 语法错误 : 缺少“;”(在标识符“HBRUSH”的前面)
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(34) : error C2061: 语法错误 : 标识符“CDC”
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(50) : error C2143: 语法错误 : 缺少“;”(在“break”的前面)
1>c:\users\administrator\desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\ie_browser.h(49) : error C3861: “ON_WM_CTLCOLOR”: 找不到标识符
1>.\ie_browser.cpp(200) : error C2065: “CDC”: 未声明的标识符
1>.\ie_browser.cpp(200) : error C2065: “pDC”: 未声明的标识符
1>.\ie_browser.cpp(200) : error C2065: “CWnd”: 未声明的标识符
1>.\ie_browser.cpp(200) : error C2065: “pWnd”: 未声明的标识符
1>.\ie_browser.cpp(200) : error C2275: “UINT”: 将此类型用作表达式非法
1> C:\Program Files (x86)\Microsoft Visual Studio 8\VC\PlatformSDK\include\windef.h(172) : 参见“UINT”的声明
1>.\ie_browser.cpp(200) : error C2146: 语法错误 : 缺少“)”(在标识符“nCtlColor”的前面)
1>.\ie_browser.cpp(200) : error C2761: “HBRUSH ie_browser_dlg::OnCtlColor(void)”: 不允许成员函数重新声明
1>.\ie_browser.cpp(200) : error C2059: 语法错误 : “)”
1>.\ie_browser.cpp(201) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>.\ie_browser.cpp(201) : error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>正在生成代码...
1>生成日志保存在“file://c:\Users\Administrator\Desktop\trunk_2012_7_8\trunk\source\wy_oa_plugin\wy_ww_plugin\wy_ww_plugin\Release\BuildLog.htm”
1>wy_ww_plugin - 25 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
你的代码看着像是MFC的,ATL/WTL的写法是这样的:
BEGIN_MSG_MAP(CMainDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorStatic)
END_MSG_MAP()
LRESULT CMainDlg::OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
return 0;
}
应添加到窗体,结果添加到控件上了。