一般创建控件有两种方法,一种是动态创建,调用CWND::Create()方法,还有就是采用SubclassDlgItem()方法绑定一个资源ID.
这两者有什么区别?比如,我继承CTreeCtrl,重载PreCreateWindow(),发现后面一种方法并没有调用该函数,结果导致我的树形控件不能显示ToolTips,但是我在属性里面选了显示提示信息风格阿?最后没办法,在外部直接调用m_tree.EnableToolTips(1);这时候又可以显示提示信息了!我在扩展中还遇到第二个问题,无法拖放,跟踪调试发现TVN_BEGINRDRAG的处理函数根本就没有调用,这是什么原因?是不是消息反射机制有特殊要求?
这两者有什么区别?比如,我继承CTreeCtrl,重载PreCreateWindow(),发现后面一种方法并没有调用该函数,结果导致我的树形控件不能显示ToolTips,但是我在属性里面选了显示提示信息风格阿?最后没办法,在外部直接调用m_tree.EnableToolTips(1);这时候又可以显示提示信息了!我在扩展中还遇到第二个问题,无法拖放,跟踪调试发现TVN_BEGINRDRAG的处理函数根本就没有调用,这是什么原因?是不是消息反射机制有特殊要求?
你重载PreCreateWindow试试:
BOOL CDragDropTreeCtrl::PreCreateWindow(CREATESTRUCT& cs)
{
// Make sure the control's TVS_DISABLEDRAGDROP flag is not set.
// If you subclass an existing tree view control rather than create
// a CDragDropTreeCtrl outright, it's YOUR responsibility to see that
// this flag isn't set.
cs.style &= ~TVS_DISABLEDRAGDROP;
return CTreeCtrl::PreCreateWindow(cs);
}
If you have supplied a handler for a specific message, or for a range of messages, in your parent window's class, it will override reflected message handlers for the same message provided you don't call the base class handler function in your own handler. For example, if you handle WM_CTLCOLOR in your dialog box class, your handling will override any reflected message handlers.If, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT(). If you use ON_NOTIFY_REFLECT_EX() in your message map, your message handler may or may not allow the parent window to handle the message. If the handler returns TRUE, the message will be handled by the parent as well, while a call that returns FALSE does not allow the parent to handle it. Note that the reflected message is handled before the notification message.When a WM_NOTIFY message is sent, the control is offered the first chance to handle it. If any other reflected message is sent, the parent window has the first chance to handle it and the control will receive the reflected message. To do so, it will need a handler function and an appropriate entry in the control's class message map.The message-map macro for reflected messages is slightly different than for regular notifications: it has _REFLECT appended to its usual name. For instance, to handle a WM_NOTIFY message in the parent, you use the macro ON_NOTIFY in the parent’s message map. To handle the reflected message in the child control, use the ON_NOTIFY_REFLECT macro in the child control’s message map. In some cases, the parameters are different, as well. Note that ClassWizard can usually add the message-map entries for you and provide skeleton function implementations with correct parameters.
楼上大大们,顺便问一句,能将vs.net2003里面的外挂字体变大吗?
两种情况下都会调用PreSubclassWindow,如果你要为两种情况使用同一个类,这是不错的初始化位置。