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

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

问题描述

结果
我不知道你是否可以在手柄转换为一个窗口HWND。我需要使用FindWindow函数的方法来调用PostMessage的功能。

我现在有源

  HANDLE mainProcess;
BOOL APIENTRY ATTACH_PROCESS(INT的ProcessID)
{    mainProcess =调用OpenProcess(PROCESS_ALL_ACCESS,真实,的ProcessID);    返回TRUE;
}
BOOL APIENTRY SEND_INPUT(/ *不使用这个样本* /为const char *字符串,布尔KEYDOWN)
{    INT待办事项= WM_KEYUP;
    如果(KEYDOWN)
        待办事项= WM_KEYDOWN;
    返回PostMessage的((HWND)mainProcess,待办事项,VK_TAB,NULL);
}


解决方案

调用使用mainProcess手柄得到的ProcessID GetProcessId()。

调用EnumWindows的()

对于每个窗口,调用GetWindowThreadProcessId()来获取与窗口关联的进程的进程ID。

比较的ProcessID的,如果两者匹配 - 你找到你想要的HWND

这是一个有点昂贵的任务,所以最好找HWND你想要的前期,只是存放。


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

I currently have to source

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); 
}

解决方案

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

call EnumWindows()

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

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天全站免登陆