user1433881
user1433881

Reputation: 3

MK_CONTROL i WM_MOUSEWHEEL

I try to implement zoom feature by using ctrl+ mouse wheel. If i use this code, the active window is scrolling, but not zooming - it looks like all apps that receive this message don't recognize MK_CONTROL flag. Can someone tell me if I'm doing something wrong?

#include "stdafx.h"
#include<Windows.h>
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
while(true)
    {
    WORD wLow=MK_CONTROL;
    WORD wHigh=240;
    WPARAM par= MAKEWPARAM(wLow, wHigh);
    HWND WindowToScroll =  GetForegroundWindow();
    SendMessage(WindowToScroll, WM_MOUSEWHEEL,par,NULL);
    Sleep(1000);
    cout<<WindowToScroll<<endl;
    }
return 0;
}

Upvotes: 0

Views: 1369

Answers (1)

Hans Passant
Hans Passant

Reputation: 941217

You assume that the program uses the MK_CONTROL flag. That is however not typical, programs very commonly check the actual keyboard state to check for modifiers. GetKeyState() function.

That's a problem, you cannot fake the keyboard state for another process with SendMessage(). You'll need to use SendInput() instead and actually send a keydown for the control key. Also good to fake the mouse wheel input. Don't forget keyup to restore the keyboard state.

Upvotes: 4

Related Questions