在C#中获取当前窗口句柄 [英] get current window handle in C#

查看:1553
本文介绍了在C#中获取当前窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我是智能手机开发的新手。我正在编写程序梳理C#和非托管代码win32。

   i am newbie to the smartphone development. i am now coding program combing C# and unmanaged code win32.

C#是我的主程序,win32是导出为dll。

C# is my main program and win32 is export as an dll.

我需要获取C#当前窗口表单处理程序并将其传递给Pinvoke win32 dll,我需要在win32编程中做一些绘画或加载bmp文件或* .nv5(papago map)。我的意图是win32函数可以在C#中创建的同一窗口表单上执行。

i need to get the C# current window form handler and pass it to the Pinvoke win32 dll , cos i need to do some paint in win32 programming or load the bmp file or *.nv5 (papago map). My intention is that win32 function can do on the same window form that was created in C#.

在C#中

handle = GetForegroundWindow(); //获取当前窗口表单句柄

PPG_OpenMap(handle); //传递窗口句柄以加载papago地图

[DllImport(" ppgsdk.dll",EntryPoint =" PPG_OpenMap" ;)]
private static extern void PPG_OpenMap(IntPtr hwnd);

当我运行程序时,似乎在智能手机上加载了papago地图,但没有显示在C#窗体上。我认为它可能不是已经通过的正确的窗口句柄。

我不熟悉win32。

i am not familiar with win32.

但我知道在win32中,有WinMain(...)函数和CreateWindow(...)函数。在WinMain中,有一个HINSTANCE参数,CreateWindow将返回HWND。我需要在C#中使用这两个变量,以便我可以将它传递给我的win32程序。由于某些原因,我不能简单地写c#或win32,我需要结合这两个来完成我的目标。

but i know that in win32, there is WinMain(...)  function and CreateWindow(...) function . in WinMain , there is a HINSTANCE parameter and the CreateWindow will return HWND. i need these two variables in C# so that i can pass this to the my win32 program. Because of some reasons, i can't write simply c# or win32, i need to combine these two to finish my target.

任何人都知道,我怎样才能在C#中获得这两个变量。我需要将它们传递给ppgsdk.dll以在C#表单上绘制一些内容。

Anybody knows , how can i get these two variables in C# . i need to pass them to the ppgsdk.dll to paint something on the C# form.

非常感谢

推荐答案

我搞定了工作:)

i got it work :)

谢谢你


这篇关于在C#中获取当前窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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