【发布时间】:2013-07-08 15:38:48
【问题描述】:
我有这些代码链接:
WMMouseWheel not working in Delphi
How to disable MouseWheel if mouse is not over VirtualTreeView (TVirtualStringTree)
将其翻译成 C++ Builder 但它不起作用:
更新:在缩小问题范围后,WM_MOUSEWHEEL 消息似乎不适用于未聚焦的TVirtualStringTree 控件,它们适用于其他控件。当焦点在例如TMemo 控制,其他TMemo 控制在滚轮上滚动,但不是TVirtualStringTree 控制。当焦点位于TVirtualStringTree 时,它会滚动TVirtualStringTree,但不会滚动其他控件。所以问题现在只针对TVirtualStringTree。
void __fastcall TForm1::ApplicationEventsMessage(tagMSG &Msg, bool &Handled)
{
TPoint Pt;
HWND Wnd;
if (Msg.message == WM_MOUSEWHEEL ||
Msg.message == WM_VSCROLL ||
Msg.message == WM_HSCROLL)
{
if (GetCursorPos(&Pt))
{
Wnd = WindowFromPoint(Pt);
// It must be a VCL control otherwise we could get access violations
if (IsWindowEnabled(Wnd) && FindControl(Wnd) != NULL)
{
Msg.hwnd = Wnd; // change the message receiver to the control under the cursor
}
}
}
}
不同版本的类似代码,同样不行:
TPoint pnt;
TWinControl *ctrl;
if ((Msg.message == WM_MOUSEWHEEL ||
Msg.message == WM_VSCROLL ||
Msg.message == WM_HSCROLL) &&
GetCursorPos(&pnt))
{
ctrl = FindVCLWindow(pnt);
if (ctrl != NULL)
{
SendMessage(ctrl->Handle, Msg.message, Msg.wParam, Msg.lParam); // No effect
// SendMessage(ctrl->Handle, WM_VSCROLL, 1, 0); // This is the only thing that actually moves scrollbars but this is not exactly the same message like above
// Msg.hwnd = ctrl->Handle; // No effect
this->Caption=ctrl->Name; // This shows correct control name so the message IS GETTING THROUGH!
Handled = true;
}
}
它应该工作,但它没有。也尝试了其他代码。无效 - 鼠标滚轮不会在未聚焦的控件上运行。如您所见,我检查了所有 3 种滚轮消息变体,它在鼠标下得到了正确的控制,它显示了该控件名称但该控件没有收到滚轮消息。
任何想法我缺少哪一块拼图才能让它发挥作用?
【问题讨论】:
-
目标控件是什么?它收到消息后会做什么?
-
VirtualTreeView 是目标控件。它什么也不做,滚动条不会在鼠标滚轮上移动。在 Delphi 中也可以使用相同的代码。
-
ApplicationEventsMessage附属于什么? -
它被放到一个主窗体(TForm1)上。
-
我相信我确实缩小了范围。在表单上放置了 2 个
TMemo和 1 个TListView和 1 个TVirtualStringTree控件。当焦点位于TMemo时,滚轮会滚动除TVirtualStringTree之外的所有内容。当焦点位于TVirtualStringTree时,滚轮仅滚动TVirtualStringTree,而不是其他未获得焦点的控件。
标签: c++ delphi c++builder virtualtreeview