如何从DLL内获得HWND? [英] How do I get a HWND from inside a DLL?

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

问题描述

我有一个DLL,我想使用直接声音播放声音。为了播放声音,我需要可执行文件的HWND。我没有加载DLL的可执行文件的HWND。如何在DLL中没有将其从可执行文件中传入?

解决方案

您可以使用 GetCurrentProcessId 以获取当前进程Id。



然后,您可以调用EnumWindows,并使用 GetWindowThreadProcessId 来查找与您的进程关联的窗口。



然而,更简单的选择可能就是生成自己的窗口。您可以创建一个不可见的1x1像素窗口,并使用Direct Sound。



即使您的调用进程没有可用窗口(或定期删除窗口句柄)。


I have a DLL that I want to play sounds using Direct Sound. In order to play sounds, I need the HWND of the executable. I don't have a HWND of the executable that loads the DLL. How do I get that in the DLL without passing it in from the executable?

解决方案

You could use GetCurrentProcessId to get the current process Id.

You could then call EnumWindows, and check each window with GetWindowThreadProcessId to find a window associated with your process.

However, an easier option might be to just generate your own Window. You can create a 1x1 pixel window that is not visible, and use it with Direct Sound.

This has the advantage of working even if your calling process doesn't have a usable window (or deletes window handles regularly).

这篇关于如何从DLL内获得HWND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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