例如:如果要把一个按钮m_btn放在TreeCtrl上,并始终保持在TreeCtrl前面,可以这样做
m_TreeCtrl.ModifyStyle(0, WS_CLIPCHILDREN); m_btn.SetParent(CWnd::FromHandle(m_TreeCtrl.m_hWnd));
但是加了SetParent之后,Click事件就不响应了,应该在它的新的父窗口类的PreTranslateMessage函数中处理,如:
BOOL CToolStatic::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message==WM_LBUTTONUP && GetWindowLong(pMsg->hwnd,GWL_ID)==IDC_BUTTON1) { //自己处理按钮点击事件响应 } return CStatic::PreTranslateMessage(pMsg); }
时间: 2025-01-02 05:14:28