C++ 处理为 HWND? [英] C++ Handle as HWND?

查看:37
本文介绍了C++ 处理为 HWND?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想知道您是否可以将句柄转换为窗口HWND".我需要使用FindWindow"方法调用PostMessage"函数.


I was wondering whether you can convert a handle to a window "HWND". I need to call the "PostMessage" function using the "FindWindow" method.

我目前必须寻找来源

HANDLE mainProcess;
BOOL APIENTRY ATTACH_PROCESS(int ProcessID)
{

    mainProcess = OpenProcess(PROCESS_ALL_ACCESS, true, ProcessID);

    return TRUE;
}
BOOL APIENTRY SEND_INPUT(/*NOT USED FOR THIS SAMPLE*/ const char* String, bool Keydown)
{

    int ToDo = WM_KEYUP;
    if (Keydown)
        ToDo = WM_KEYDOWN;
    return PostMessage((HWND)mainProcess, ToDo, VK_TAB, NULL); 
}

推荐答案

使用 mainProcess 句柄调用 GetProcessId() 以获取 ProcessID.

call GetProcessId() using the mainProcess handle to get the ProcessID.

调用 EnumWindows()

call EnumWindows()

对于每个窗口,调用 GetWindowThreadProcessId() 以获取与该窗口关联的进程的 ProcessId.

For Each Window, call GetWindowThreadProcessId() to get the ProcessId of the process associated with the window.

比较 ProcessID,如果它们匹配 - 您已找到所需的 HWND.

Compare the ProcessID's, if they match -- you've found the HWND you want.

这是一项有点昂贵的任务,所以最好提前找到您想要的硬件并存储它.

This is a somewhat expensive task, so best to find the hwnd you want upfront and just store it.

这篇关于C++ 处理为 HWND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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