自绘制按钮初探一
2008-09-18 18:41
176 查看
1、很多的做的比较cool的界面都回截取WM_MOUSELEAVE和WM_MOUSEHOVER消息,而此消息不是标准的windows消息,我们可以通过mfc类向导添加WM_MOUSEMOVE响应函数,在其中添加以下代码以得到以上两种消息:
void CXPButton::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bTracking)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = m_hWnd;
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 1;
m_bTracking = _TrackMouseEvent(&tme);
}
CButton::OnMouseMove(nFlags, point);
}
MDSDN对以上函数解释如下:
TrackMouseEvent
The TrackMouseEvent function posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time.
为以上两种消息添加消息响应函数 如下:
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnMouseHover(WPARAM wParam, LPARAM lParam);
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
2、自绘制按钮一般重DrawItem()函数,在调用此函数前应该设置控件的属性为自绘制,通过调用PreSubclassWindow() 函数实现。代码如下:
void CXPButton::PreSubclassWindow()
{ CButton::PreSubclassWindow();
ModifyStyle(0, BS_OWNERDRAW);
}
DrawItem函数在MSDN解释如下:
virtual void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
Called by the framework when a visual aspect of an owner-drawn button has changed. An owner-drawn button has the BS_OWNERDRAW style set. Override this member function to implement drawing for an owner-drawn CButton object. The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before the member function terminates.
相关文章推荐
- 初探Android的View绘制过程
- android实现按钮拖动效果及路径的绘制等2D绘图功能---待完善
- 对按钮重新绘制
- 图文剖析自定义View的绘制(以自定义滑动按钮为例)
- C# 制作出任意不规则按钮! (原理根据背景图绘制button)
- 使用GDI+绘制的360风格按钮控件
- 绘制圆形按钮
- 手游产品经理初探(四)从Buy按钮谈玩家付费
- Android使用XML Shape绘制带阴影效果的圆形按钮
- ActionScript绘制复杂样式按钮
- 在按钮上绘制图片
- 在Microsoft Expression Blend 2 中绘制圆角矩形按钮
- QT 绘制按钮 paintEvent enterEvent leaseEvent mouseEvent
- TabControl tab绘制关闭按钮
- 绘制圆形按钮
- javafX初探(开关按钮)
- 使用GTK - 绘制按钮和消息框
- PS新手教程!教你绘制一枚通透质感的游戏按钮
- [js] webgl 初探 - 绘制三角形
- 如何在datagridview 的head上绘制一个全选按钮