我想为CButton子类化以处理ON_WM_LBUTTONDOWN消息。
DownButton.cpp:
#include "stdafx.h"
#include "DownButton.h"
//CDownButton
IMPLEMENT_DYNAMIC(CDownButton, CButton)
CDownButton::CDownButton()
{
}
CDownButton::~CDownButton()
{
}
BEGIN_MESSAGE_MAP(CDownButton, CButton)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// CDownButton message handlers
void CDownButton::OnLButtonDown(UINT nFlags, CPoint point)
{
}
DownButton.h
#pragma once
// CDownButton
class CDownButton : public CButton
{
DECLARE_DYNAMIC(CDownButton)
public:
CDownButton();
virtual ~CDownButton();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};
但是如何通知包含此按钮的对话框呢?似乎唯一可以接收的消息是ON_BN_CLICKED。
最佳答案
您需要在OnLButtonDown-事件中将消息重新发送给父级:
void CDownButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// do what you want to do ...
GetParent()->SendMessage(WM_COMMAND, GetDlgCtrlID() | WM_LBUTTONDOWN << 16, (LONG) GetSafeHwnd());
}
关于c++ - 如何向父对话框通知按钮按下消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31704562/