使用api获取文件框里的内容!

本操作在已知文本框hwnd的前提下。

 

1.首先声明api,主要用到GetWindowTextLength获取文本的长度,GetWindowText获取文本的内容

 

< System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential) >  _
Public   Structure  HWND__

    
''' int
     Public  unused  As   Integer
End Structure

Partial   Public   Class  NativeMethods

    
''' Return Type: int
    
''' hWnd: HWND->HWND__*
     < System.Runtime.InteropServices.DllImportAttribute( " user32.dll " , EntryPoint: = " GetWindowTextLengthA " ) >  _
    
Public   Shared   Function  GetWindowTextLengthA( < System.Runtime.InteropServices.InAttribute() >   ByVal  hWnd  As  System.IntPtr)  As   Integer
    
End Function

    
''' Return Type: int
    
''' hWnd: HWND->HWND__*
    
''' lpString: LPSTR->CHAR*
    
''' nMaxCount: int
     < System.Runtime.InteropServices.DllImportAttribute( " user32.dll " , EntryPoint: = " GetWindowTextA " ) >  _
    
Public   Shared   Function  GetWindowTextA( < System.Runtime.InteropServices.InAttribute() >   ByVal  hWnd  As  System.IntPtr,  < System.Runtime.InteropServices.OutAttribute(), System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr) >   ByVal  lpString  As  System.Text.StringBuilder,  ByVal  nMaxCount  As   Integer As   Integer
    
End Function
End Class

 

 

声明api可以用相应的工具生成,我使用的是winsiggen.exe
2.传入句柄获取控件的内容
      Dim  Tlong  As   Integer , s  As   New  System.Text.StringBuilder

        Tlong 
=  NativeMethods.GetWindowTextLengthA( Me .TextBox1.Handle)  +   1

        NativeMethods.GetWindowTextA(
Me .TextBox1.Handle, s, Tlong)

        
MsgBox (s.ToString)

 

如何获取hwnd可以使用FindWindowEx, GetClientRect获取指定坐标的的hwnd

转载于:https://www.cnblogs.com/zqonline/archive/2009/11/24/1609638.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值