向画图应用程序发送点击事件
Sending a click event to a Paint application
我正在编写一个应用程序,可以根据用户的喜好自动在 canvas 上绘制内容。
对于初学者,如何向 MS Paint 应用程序发送 click 事件?
您必须搜索 google 以了解如何将 windows 消息发送到不同的应用程序。鼠标点击由 2 条不同的消息组成:WM_LBUTTONDOWN 和 WM_LBUTTONUP.
http://stefanstools.sourceforge.net/SendMessage.html
http://www.codeproject.com/Articles/137/Sending-a-message-to-the-Main-Frame-Window-of-Anot
首先,您需要找到画图应用程序:
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;
}
其次,你与它互动:
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));
}
}
您可以随时浏览 MSDN 文档以获取更多详细信息。
我正在编写一个应用程序,可以根据用户的喜好自动在 canvas 上绘制内容。 对于初学者,如何向 MS Paint 应用程序发送 click 事件?
您必须搜索 google 以了解如何将 windows 消息发送到不同的应用程序。鼠标点击由 2 条不同的消息组成:WM_LBUTTONDOWN 和 WM_LBUTTONUP.
http://stefanstools.sourceforge.net/SendMessage.html http://www.codeproject.com/Articles/137/Sending-a-message-to-the-Main-Frame-Window-of-Anot
首先,您需要找到画图应用程序:
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;
}
其次,你与它互动:
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));
}
}
您可以随时浏览 MSDN 文档以获取更多详细信息。