15,979
社区成员
发帖
与我相关
我的任务
分享
void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd *pParent = GetParent();
if((GetStyle() & WS_POPUP) && pParent)
{
WPARAM wParam = MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED);
pParent->PostMessage(WM_COMMAND, wParam, (LPARAM)m_hWnd);
}
CButton::OnLButtonDown(nFlags, point);
}
BOOL CDlg5Dlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
UINT uNotify = HIWORD(wParam);
UINT uID = LOWORD(wParam);
if(uNotify == BN_CLICKED && (HWND)lParam == m_TestButton.m_hWnd)
{
AfxMessageBox(_T("Button clicked!"));
}
return CDialog::OnCommand(wParam, lParam);
}
//从CButton派生新类 处理 WM_LBUTTONDOWN 消息, 发送按下消息
void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd *pParent = GetParent();
if((GetStyle() & WS_POPUP) && pParent)
{
WPARAM wParam = MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED);
pParent->PostMessage(WM_COMMAND, wParam);
}
CButton::OnLButtonDown(nFlags, point);
}
//在对话框上测试
//Dlg5Dlg.h
class CDlg5Dlg : public CDialog
{
CMyButton m_TestButton;
BOOL CDlg5Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_TestButton.CreateEx(0, _T("BUTTON"),
_T("Test"), WS_POPUP|WS_VISIBLE, CRect(0, 0, 200, 40), this, 0);
m_TestButton.SetDlgCtrlID(1000);
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CDlg5Dlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
UINT uNotify = HIWORD(wParam);
UINT uID = LOWORD(wParam);
if(uNotify == BN_CLICKED && uID == m_TestButton.GetDlgCtrlID())
{
AfxMessageBox(_T("Button clicked!"));
}
return CDialog::OnCommand(wParam, lParam);
}
//处理 WM_WINDOWPOSCHANGED 消息
void CDlg5Dlg::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CDialog::OnWindowPosChanged(lpwndpos);
// TODO: Add your message handler code here
if(m_TestButton.m_hWnd)
{
CRect rcRect;
GetWindowRect(&rcRect);
m_TestButton.MoveWindow(rcRect.left+20, rcRect.top, 100, 40);
}
}