C++ 处理为 HWND?

编程入门 行业动态 更新时间:2024-10-28 02:23:48
本文介绍了C++ 处理为 HWND?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..


我想知道您是否可以将句柄转换为窗口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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 06:10:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/932653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HWND

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!