如何获得一个控件或窗体的句柄 (HWND)?

实际上有几种使用 P/Invoke 的方法可以访问控件的 HWND 句柄。下面显示了其中两种方法,一种使用 GetCapture,另一种使用 FindWindow

[DllImport("coredll.dll"]
public
  static   extern  IntPtr GetCapture();
[DllImport(
" coredll.dll " )]
public   static   extern  IntPtr FindWindow(String lpClassName, String lpWindowName);

// ----下面的this的基类为Control----
//  方法1
this .Text  =   " FindMe " ;
IntPtr hwnd1 
=  FindWindow( null " FindMe " );

//  方法2
this .Capture  =   true ;
IntPtr hwnd2 
=  GetCapture();
this .Capture  =   false ;

 
参考:

李森 – listen
E-mail:  [email protected]

声明:
这里集中了在WinCEWindows Mobile开发中的一些基本常识。我很乐意和大家分享,也希望大家提出意见,并给我投稿,我会第一时间替您发表并署上您的大名!

Announce:
Here collects general knowledge on WinCE and Windows mobile. I 'm very glad to share them with all friends, and also hope you can share your problems and opinions and contribute articles to me to share with others. I'll publish your articles and sign your name at the first time.

  

 

你可能感兴趣的:(控件)