-2

I am writing an application that automatically draws something on a canvas, depending on the user's preferences. For starters, how can I send a click event to the MS Paint application?

Smehrt Tonni
  • 193
  • 2
  • 2
  • 16

2 Answers2

0

First, you need to find the Paint application:

static HWND findMSPaintDrawWindow(void)
{
    HWND target;
    target = FindWindow(TARGET_PAINT_WINDOW, NULL);
    if (NULL != target)
    {
        target = FindWindowEx(target, NULL, TARGET_PAINT_INPUT_SUBWINDOW, NULL);

        if (NULL != target)
        {
            target = FindWindowEx(target, NULL, NULL, NULL);
        }
    }

    if (/*ENABLE_DEBUG_CONSOLE*/ 0)
    {
        char name[256];
        GetClassName(target, name, 255);
        printf("Detected ms paint Draw area with name [%s]\n", name);
    }

    return target;
}

Second, you interact with it:

static void sendMouseButton(int buttonState)
{
    HWND target;
    UINT buttonMode = WM_LBUTTONUP;

    target = findMSPaintDrawWindow();
    if (target)
    {
        if (buttonState)
        {
            buttonMode = WM_LBUTTONDOWN;
            g_MouseDown = 0;
        }
        printf("INFO: Mouse [%d] msg %d\n", buttonState, buttonMode);
        PostMessage(target, buttonMode, MK_LBUTTON, X, Y));
    }

}

You can always browse the MSDN documentation for more details.

George Netu
  • 2,758
  • 4
  • 28
  • 49
-2

You have to search google for how to send windows message to different application. The mouse click is composed of 2 different messages: WM_LBUTTONDOWN and WM_LBUTTONUP.

http://stefanstools.sourceforge.net/SendMessage.html http://www.codeproject.com/Articles/137/Sending-a-message-to-the-Main-Frame-Window-of-Anot

AndreiM
  • 815
  • 9
  • 17
  • I'm flagging this answer to be purged for low quality. There is no wm_mousedown or wm_mouseup message in Windows. With the only information in the answer being wrong, it turns into a link-only answer. This is not [how you write a good answer](http://stackoverflow.com/help/how-to-answer). – IInspectable Jul 13 '15 at 13:46
  • There is no essential part of the answer ... the issue at hand is a rather broad question, and since the OP doesn't have a clue about implementing the issue (he uses mouse events instead of windows messages), then the issue must be studied in greater detail. I just pointed to a direction for further study. – AndreiM Jul 13 '15 at 15:01