我在VC工程中添加一个类,想在Class View 为这个派生类右键添加一个虚函数和消息处理函数。发现Add Virtual Function 与 Add Windows Message Handler这两项没有。请问是为什么?你可以随意建一对话框应用程序,把这个类添加进去看看。这个类的名字叫CReportCtrl,在我网盘(www.wgd123pl.ys168.com)中的第一个。进去就以下了。先谢谢各位大侠。
调试欢乐多
//
// CReportCtrl, a CListCtrl derived class that is specialized on "Report View"
// style.
//
// Features:
//
// 1, Item sorting by clicking on column header.
// 2, Sub-item text edit.
// 3, Item repositioning.
// 4, Customizing checkbox styles, including "single" and "disabled".
// 5, Sending a message to parent window when user clicks on a checkbox.
// 6, Convenient item insertion, deletion, moving, and sub-item text changing.
// 7, Sub-item images and color
// 8, And much more...
//
// This code may be used in compiled form in any way you desire. This file may be
// redistributed unmodified by any means PROVIDING it is not sold for profit without
// the authors written consent, and providing that this notice and the authors name
// is included. If the source code in this file is used in any commercial application
// then acknowledgement must be made to the author of this file .
//
// This file is provided "as is" with no expressed or implied warranty.
//
// Written by Bin Liu ([email protected])
//
// History
//
// Nov. 26, 2003 - Initial release.
// Dec. 03, 2003 - Fixed a bug in "EndEdit" where item text were not preperly committed.
// Completed the implementation of the "Sort-Separator" feature.
// Jan. 01, 2004 - Fixed a bug in "SetItemData".
// - Added message "WM_EDIT_COMMITTED" which is sent to the parent window
// when an item text editing is committed.
// - Fixed a bug in "SetItemText"(double type).
// - Fixed a bug where item sorting does not work properly when there
// are multiple CReportCtrl objects on same window.
//
///////////////////////////////////////////////////////////////////////////////#ifndef __REPORTCTRL_H__
#define __REPORTCTRL_H__// Sent to parent window when user clicked on the checkbox of an item:
// wParam: The item index in the list ctrl
// lParam: The mouse event type(WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc) which generated this event.
// Note: This message is not sent when the checkbox states were altered programmatically
// by calling "SetItem", it is only sent when the user "physically" clicked the
// checkbox using mouse or joystick etc.
#define WM_ON_CHKBOX (WM_APP + 10000)// Sent to parent window when a column of items were sorted
// wParam: The column index
// lParam: The sort method, either 0(descending) or 1(ascending)
#define WM_ITEM_SORTED (WM_APP + 10001)// Sent to parent window when an item text editing was committed
// wParam: The item index
// lParam: The column index
#define WM_EDIT_COMMITTED (WM_APP + 10002)// Checkbox styles.
#define RC_CHKBOX_NONE 0 // No checkbox displayed
#define RC_CHKBOX_NORMAL 1 // Normal, multiple check allowed
#define RC_CHKBOX_SINGLE 2 // Single check only
#define RC_CHKBOX_DISABLED 3 // Disabled, cannot be checked/unchecked by user input,
// but can be by your code.// Item state flags for selection, deletion, etc.
// Multiple flags can be combined together using the bit-or operator.
// Note: If RC_ITEM_ALL is set, all other flags are ignored
#define RC_ITEM_NONE 0x0000 // Void, indicates invalid items only
#define RC_ITEM_ALL 0x0001 // All items regardless of states
#define RC_ITEM_SELECTED 0x0002 // Selected items
#define RC_ITEM_UNSELECTED 0x0004 // Unselected items
#define RC_ITEM_CHECKED 0x0008 // Checked items
#define RC_ITEM_UNCHECKED 0x0010 // Unchecked items
#define RC_ITEM_FOCUSED 0x0020 // Focused item
#define RC_ITEM_UNFOCUSED 0x0040 // Unfocused items// Item inverting types
#define RC_INVERT_SELECTION 0 // Invert item selection
#define RC_INVERT_CHECKMARK 1 // Invert item check // Removes any custom color from item text and item backgroun
#define COLOR_INVALID 0xffffffff//////////////////////////////////////////////////////////////////////////
// The CReportCtrl Class Definition
//////////////////////////////////////////////////////////////////////////class CReportCtrl : public CListCtrl
{
public:
//////////////////////////////////////////////////////////////////////
// Constructor & Destructor
//////////////////////////////////////
如:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(xxxDlg)
不然没有‘向导’的注释,恐怕不行。
class CReportCtrl : public CListCtrl
{
public:
CReportCtrl();
~CReportCtrl();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CReportCtrl)
//}}AFX_VIRTUAL// Implementation
public: // Generated message map functions
protected:
//{{AFX_MSG(CReportCtrl)
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};.cpp文件里得有这一段
BEGIN_MESSAGE_MAP(CReportCtrl, CListCtrl)
//{{AFX_MSG_MAP(CReportCtrl) //}}AFX_MSG_MAP
END_MESSAGE_MAP()手工添加这三段后保存.然后按我说的:关闭工程,删除 工程.clw文件,重启工程
查看->建立类向导,会出提示,点ADD ALL确定后即可.
我经常这样做,来解决不能添加虚函数和增加WINDOWS消息处理的问题.