请教大家 怎样获取窗口的标题

请教大家 怎样获取窗口的标题,第1张

[DllImport("user32dll", EntryPoint="GetWindowText")]

public static extern int GetWindowText (

int hwnd,

string lpString,

int cch

);

调用的时候这样:

StringBuilder s = new StringBuilder(512);

int i = GetWindowText(句柄, s, sCapacity);

MessageBoxShow(sToString());

添加一个时钟写下代码

时钟周期=100

版本

2

DLL命令

GetForegroundWindow,

整数型,

,

"GetForegroundWindow"

DLL命令

GetWindowText,

,

,

"GetWindowTextA"

参数

Hwnd,

整数型

参数

lpString,

文本型

参数

cch,

整数型

版本

2

子程序

_时钟1_周期事件

局部变量

hwnd,

整数型

局部变量

窗口标题,

文本型

hwnd

GetForegroundWindow

()

窗口标题

取空白文本

(255)

GetWindowText

(hwnd,

窗口标题,

255)

_启动窗口标题

窗口标题

有什么不懂的加我QQ

821788778

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)

使用以下命令:

Hwnd = PluginWindowForeground()

命令功能:

得到当前窗口句柄,返回值赋值给Hwnd

Hwnd = PluginWindowMousePoint()

命令功能:得到鼠标指向的窗口句柄,返回值赋值给Hwnd

那是一个空字符, 就是 chr(0)

s = Space$(l)

GetWindowText hWnd, s, l

GetWindowTitle = Left$(s, l)

这样就行了,没必要 +1

' NET 的数据类型和 VB6 的完全不同。API 声明也完全不一样。

Private Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr

Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer

Private Structure TitleEXD

<VBFixedString(255)> Public Text As String

End Structure

Private Sub Button1_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles Button1Click

Dim x As Integer = MousePositionX, y As Integer = MousePositionY, res As String

Label1Text = "鼠标当前坐标:" & x & "," & y

Dim hwnd As IntPtr = WindowFromPoint(x, y)

Label2Text = "句柄:" & hwndToString()

Dim Tlong As Integer = GetWindowTextLength(hwnd) Mod 65536 + 1

Dim TitleE As TitleEXD

TitleEText = Space(255)

Dim dlld As Integer = GetWindowText(MeHandle, TitleEText, Tlong) Mod 65536

Label3Text = "窗口标题:" & TitleEText

If dlld = 0 Then

res = "失败"

Else

res = "成功"

End If

Label4Text = "获取标题" & res

End Sub

先获取 正在运行的程序列表

Process[] allprocess = ProcessGetProcesses();

尽量使列表中唯一并且那个就是你需要的程序

那么接下来获取 这个程序的标题 对象浏览器里找下 Process的属性 相信能找到

以上就是关于请教大家 怎样获取窗口的标题全部的内容,包括:请教大家 怎样获取窗口的标题、易语言 取当前窗口标题、VB如何得到窗口的标题等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9473762.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存