gpt4 book ai didi

c++ - 如何在 CMainFrame 中处理鼠标点击

转载 作者:行者123 更新时间:2023-12-04 07:20:42 27 4
gpt4 key购买 nike

如何检测“空”CMainFrame 鼠标点击?空我的意思是一个还没有任何文档/ View 的 MDI。
我试图用以下方法检测鼠标点击:

   afx_msg void OnLButtonDown(UINT nFlags, CPoint point);  
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg);

最佳答案

MDI 主框架窗口有一个“不可见”的客户窗口,它占据主框架的客户区。使用“普通”类覆盖技术无法访问此窗口,但是,如果该主框架窗口源自 CMDIFrameWndCMDIFrameWndEx ,您可以使用它的m_hWndMDIClient成员(该不可见窗口的 HWND)通过覆盖其 WindowProc 来将其子类化.
我在主框架的 UpdateWindow 的覆盖中执行此操作(实际上是为了在该客户区中绘制)程序,使用 bool成员变量(在构造时设置为 false)以跟踪子类化是否已经完成。
这是一个可能的解决方案(改编自我自己的代码),它可能适用于拦截鼠标点击。 (我对其进行了测试,确实在单击鼠标时得到了 Beep() 诊断信息!)

// Local function pointer to store the 'original' (default) window procedure...
LRESULT (CALLBACK *DefCliPrc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = nullptr;

// Static definition of our override procedure...
static LRESULT CALLBACK ClientProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT answer = DefCliPrc(hWnd, uMsg, wParam, lParam); // First, call default proc.
if (uMsg == WM_LBUTTONDOWN) {
Beep(1000,1000); // Make a sound to show that it's working!
// <Insert your handling code here>
}
//...
// Intercept/handle other messages, as required ...
//...
return answer;
}

// Override of the UpdateWindow function, to enact the subclassing...
void MyMainFrame::UpdateWindow(void)
{
if (!funchange) { // Only do the sub-classing ONCE ...
DefCliPrc = (WNDPROC)(intptr_t)(::GetWindowLongPtr(m_hWndMDIClient, GWLP_WNDPROC));
::SetWindowLongPtr(m_hWndMDIClient, GWLP_WNDPROC, (intptr_t)(ClientProc));
funchange = true; // Set this 'flag' to prevent repetition!
}
CMDIFrameWnd::UpdateWindow(); // Should always call base class
return;
}

关于c++ - 如何在 CMainFrame 中处理鼠标点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68520457/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com