zoukankan      html  css  js  c++  java
  • 使用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 IntegerAs 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
  • 相关阅读:
    C#调用WebService实现天气预报
    火狐完整版下载地址
    Unity3D 中 2D_Toolkit插件下载 和 导入方法
    给大家分享个 网站头像上传的 插件
    JQuery工具方法,实例方法
    ireport5.6.0 win10打不开
    JFreeChart 零散
    JS 类继承 原型继承
    技术电子书下载网址
    正则 变量替换
  • 原文地址:https://www.cnblogs.com/zqonline/p/1609638.html
Copyright © 2011-2022 走看看