模拟点击进入一个隐藏的窗口 [英] Simulate click into a hidden window

查看:241
本文介绍了模拟点击进入一个隐藏的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#问题,

我能够模拟点击当前窗口,但我想这样做,如果窗口最小化或隐藏。

I am able to simulate a click to the current window, but I would like to do it if the window is minimized or hidden.

任何想法?

推荐答案

下面是一个完全工作片段,这将给你的窗口句柄,目标子窗口,并发布消息到子窗口。

Here is a fully working snippet which will give you the window handle, target sub window and post a message to that subwindow.

#include "TCHAR.h"
#include "Windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
    HWND hwndWindowTarget;
    HWND hwndWindowNotepad = FindWindow(NULL, L"Untitled - Notepad");
    if (hwndWindowNotepad)
    {
        // Find the target Edit window within Notepad.
        hwndWindowTarget = FindWindowEx(hwndWindowNotepad, NULL, L"Edit", NULL);
        if (hwndWindowTarget) {
            PostMessage(hwndWindowTarget, WM_CHAR, 'G', 0);
        }
    }

    return 0;
}



目前,它会发送字符记事本无题(打开新的记事本,什么也不做。

At the moment it will send the G character to notepad "Untitled" (open a new notepad, do nothing.

您可以使用的 间谍++ 。附带的Visual Studio

You can find the sub-window using spy++ which comes with visual studio.

下面是一个使用SendInput发送鼠标事件的例子:

Here is an example using SendInput to send mouse events:

#include "TCHAR.h"
#include "Windows.h"

int _tmain(int argc, _TCHAR* argv[])
{
    POINT pt;
    pt.x = 300;
    pt.y = 300;

    HWND hwndWindowTarget;
    HWND hwndWindowNotepad = FindWindow(NULL, L"Untitled - Notepad");
    if (hwndWindowNotepad)
    {
        // Find the target Edit window within Notepad.
        hwndWindowTarget = FindWindowEx(hwndWindowNotepad, NULL, L"Edit", NULL);
        if (hwndWindowTarget) {
            PostMessage ( hwndWindowTarget, WM_RBUTTONDOWN, 0, (pt.x) & (( pt.y) << 16) );
            PostMessage ( hwndWindowTarget, WM_RBUTTONUP, 0, (pt.x ) & (( pt.y) << 16) );
        }
    }

return 0;



}

}

这篇关于模拟点击进入一个隐藏的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆