vc++ 中如何派生 picture控件的 类?

2025-01-20 14:56:08
推荐回答(2个)
回答1:

1,picture控件空间响应mousemove 消息不需要重新派生类,先为对话框或者view添加mousemove 消息响应函数,然后重载消息控制函数PreTranslateMessage(MSG* pMsg);
2,在这个函数中添加以下代码:
if(WM_MOUSEMOVE == pMsg-> message)
if(pMsg-> hwnd == GetDlgItem(IDC_STATIC)-> GetSafeHwnd())
{
//这里添加移动鼠标是需要响应的代码

}

回答2:

在你的CPic类中响应WM_NCHITTEST消息
CPic.h

//{{AFX_MSG(CPic)
afx_msg UINT OnNcHitTest(CPoint point);
//}}AFX_MSG

CPic.cpp
BEGIN_MESSAGE_MAP(CPic, CStatic)
//{{AFX_MSG_MAP(CPic)
ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

UINT CPic::OnNcHitTest(CPoint point)
{
// TODO:
CRect rc;
GetWindowRect(rc);

if(!rc.PtInRect(point))
return CStatic::OnNcHitTest(point);

//you can do anything here , ...........

return CStatic::OnNcHitTest(point);
}