简体   繁体   English

获取窗口的句柄

[英]get handle of window

I have a window which runs in separate thread. 我有一个在单独的线程中运行的窗口。 I need to get the handle of that window in another thread. 我需要在另一个线程中获取该窗口的句柄。

I can't use ::FindWindow API, because the window name will change, as my application can run in other languages. 我不能使用:: FindWindow API,因为窗口名称会更改,因为我的应用程序可以使用其他语言运行。 Plus, I don't have access to the resource string used for window name. 另外,我无权访问用于窗口名称的资源字符串。

I can't use ::GetActiveWindow also, as the calling thread id and the active window thread id is different. 我也不能使用:: GetActiveWindow,因为调用线程ID和活动窗口线程ID是不同的。

Please suggest some solution. 请提出一些解决方案。

It is not necessary to pass the window name to the FindWindow function. 不必将窗口名称传递给FindWindow函数。 You can pass NULL for the window name and find the window using only the lpClassName parameter. 您可以传递NULL作为窗口名称,并仅使用lpClassName参数查找窗口。

MFC normally assigns window class names automatically, but you can control a window's class name by registering a unique name with AfxRegisterClass and creating the window with that registered class name. MFC通常自动分配窗口类名称,但是您可以通过在AfxRegisterClass中注册唯一名称并使用该注册的类名称创建窗口来控制窗口的类名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM