SendMessage, from MSDN:If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure.
你要干什么事,直接在ontimer里做就是了。
是SendMessage(WM_COMMAND,id,0) 到Parent吗?
启用另一个线程是一个选择。
但是,如果你自己调用PEEKMESSAGE,也可以解决。
// CRepeatBtn windowclass CRepeatBtn : public CButton
{
// Construction
public:
CRepeatBtn();// Attributes
public:
DWORD m_dwRepeatTimer;// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CRepeatBtn)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CRepeatBtn(); // Generated message map functions
protected:
//{{AFX_MSG(CRepeatBtn)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};RepeatBnt.cpp :省略了所有 MFC 源文件都有的代码#define ID_TIMER_REPEATBTN 1024/////////////////////////////////////////////////////////////////////////////
// CRepeatBtnCRepeatBtn::CRepeatBtn()
{
m_dwRepeatTimer = 0;
}CRepeatBtn::~CRepeatBtn()
{
if (m_dwRepeatTimer)
{
KillTimer(m_dwRepeatTimer);
}
}BEGIN_MESSAGE_MAP(CRepeatBtn, CButton)
//{{AFX_MSG_MAP(CRepeatBtn)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CRepeatBtn message handlersvoid CRepeatBtn::OnLButtonDown(UINT nFlags, CPoint point)
{
m_dwRepeatTimer = SetTimer(ID_TIMER_REPEATBTN, 100, NULL);
CButton::OnLButtonDown(nFlags, point);
}void CRepeatBtn::OnLButtonUp(UINT nFlags, CPoint point)
{
if (m_dwRepeatTimer)
{
KillTimer(m_dwRepeatTimer);
m_dwRepeatTimer = 0;
}
CButton::OnLButtonUp(nFlags, point);
}void CRepeatBtn::OnTimer(UINT nIDEvent)
{
CWnd *pParent = GetParent(); if (ID_TIMER_REPEATBTN == nIDEvent && pParent)
{
pParent->SendMessage(WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)GetSafeHwnd());
}
}
给分啦!!