T
Nun habe ich es auch so geschafft,
für die nächste arme Seele:
Man sollte den Hook kurzzeitig deaktivieren, um dann mit mouse_event ein rbuttondown zu simulieren, bevor man den hook weiterleitet. So lösen sich alle Probleme von selbst.
Hier nochmal der (nicht ganz optimale, aber funktionierende) code:
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// MSDN says: "Return if nCode < 0"
if (nCode < 0)
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
if (nCode == HC_ACTION)
{
if ( ((wParam == WM_RBUTTONDOWN)||(wParam == WM_NCRBUTTONDOWN)) && !rbdown)
{
MSLLHOOKSTRUCT *mhs = (MSLLHOOKSTRUCT*)lParam;
int x = mhs->pt.x;
int y = mhs->pt.y;
firstx = x;
firsty = y;
rbdown = true;
showContextMenu = false;
// Gesture starts
PostMessage(g_gestures, PM_GESTURE_BEGIN, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
return 1;
}
// Gesture was already initiated, rb is down
else if ( ((wParam == WM_MOUSEMOVE)||(wParam == WM_NCMOUSEMOVE)) && rbdown )
{
MSLLHOOKSTRUCT *mhs = (MSLLHOOKSTRUCT*)lParam;
//Post new position
PostMessage(g_gestures, PM_GESTURE_CHANGE, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
//return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
// Gesture ends / right click is finished
else if ( (wParam == WM_RBUTTONUP)||(wParam == WM_NCRBUTTONUP) )
{
MSLLHOOKSTRUCT *mhs = (MSLLHOOKSTRUCT*)lParam;
int x = mhs->pt.x;
int y = mhs->pt.y;
if ( (abs(firstx-x) > 5) || (abs(firsty-y) > 5))
{
showContextMenu = false;
}
else
{
showContextMenu = true;
}
POINT WindowPos;
WindowPos.x = x;
WindowPos.y = y;
if (showContextMenu) //Mouse wasn't moved
{
SetForegroundWindow(WindowFromPoint(WindowPos));
if ((wParam == WM_RBUTTONUP))
{
PostMessage(g_gestures, PM_GESTURE_DISCARD, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
UninstallHook();
mouse_event(MOUSEEVENTF_RIGHTDOWN, mhs->pt.x, mhs->pt.y, 0, mhs->dwExtraInfo);
InstallHook();
//SendMessage(GetForegroundWindow(), WM_RBUTTONDOWN, wParam, MAKELPARAM(mhs->pt.x, mhs->pt.y));
}
else // NCRBUTTONUP
{
PostMessage(g_gestures, PM_GESTURE_DISCARD, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
UninstallHook();
mouse_event(MOUSEEVENTF_RIGHTDOWN, mhs->pt.x, mhs->pt.y, 0, mhs->dwExtraInfo);
InstallHook();
//SendMessage(GetForegroundWindow(), WM_NCRBUTTONDOWN, wParam, MAKELPARAM(mhs->pt.x, mhs->pt.y));
}
rbdown = false;
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
else
{
PostMessage(g_gestures, PM_GESTURE_END, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
rbdown = false;
return 1; // Keep other windows from handling this event
}
}
else if ( ((wParam == WM_MOUSEMOVE)||(wParam == WM_NCMOUSEMOVE)) && rbdown )
{
MSLLHOOKSTRUCT *mhs = (MSLLHOOKSTRUCT*)lParam;
//Post new position
PostMessage(g_gestures, PM_GESTURE_CHANGE, 0, MAKELPARAM(mhs->pt.x, mhs->pt.y));
return 1;
//return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
else // non of the messages being of interest for us
{
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
}
else // nCode < 0
{
return CallNextHookEx(g_hMouseHook, nCode, wParam, lParam);
}
}
Danke für eure vielen Antworten!