开发者

Get window handle of calling window

there is a software which calls a method in my C# dll. In this dll method i need to have the window handle of the program/window which called my dll.

how to g开发者_运维知识库et this "calling window handle"?

Thanks!


This can return the main window handle.

System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle

As i know there is no way to get a concrete window because it's no more than Form object. But Form class has a property Handle. You can pass it as an argument to dll method calls.


You can't: windows don't call methods, code calls methods.

You should ideally add a window handle parameter to your method. If that's absolutely impossible, you could use, say, the GetActiveWindow API function to get the window active on the current thread. This isn't guaranteed to work; maybe there are no windows open.

What do you need the window handle for?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜