none
请帮忙看一下这段代码?? RRS feed

  • 问题

  • 请看一下,这段代码...

    怎么,他只运行时第一次能正确获取"句柄",但再单击时就不能得到"句柄"了呢???

    请大侠指点@

    感谢!!

    Imports System.Runtime.InteropServices Public Partial Class MainForm Public Sub New() ' The Me.InitializeComponent call is required for Windows Forms designer support. Me.InitializeComponent() ' ' TODO : Add constructor code after InitializeComponents ' End Sub Private Const WM_GETTEXT As Integer = &HD Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, _ ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr 'Declare Auto Function isWindowVisible Lib "user32.dll" (byval hWnd as IntPtr) as IntPtr <DllImport("user32.dll",CharSet:=CharSet.Auto)> _ Public Shared Function IsWindowVisible(ByVal hWnd As IntPtr) As Boolean End Function <DllImport("user32.dll",CharSet:=CharSet.Auto,ExactSpelling:=True)> _ Public Shared Function GetDlgItem(ByVal nDlg As IntPtr ,Byval nIDDlgItem as Integer) As IntPtr End Function <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _ ByVal childAfter As IntPtr, _ ByVal lclassName As String, _ ByVal windowTitle As String) As IntPtr End Function Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As IntPtr Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim HwndTop As IntPtr = FindWindow(Nothing, "◣电话调度◥") Dim Handle As IntPtr = Marshal.AllocHGlobal(100) Dim NumText As Integer = SendMessage(HwndTop, WM_GETTEXT, 50, Handle) Dim strText As String = Marshal.PtrToStringUni(Handle) '此处单击第一次可以正确取得句柄及内容,但第二次就不行了!!! '第二次的话所有的句柄及内容都不能正确获取了!! me.text=strText messagebox.Show (GetDlgItem(HwndTop,cint(00000001)),"HwndTop") dim ChildHandle1 as IntPtr =GetDlgItem(HwndTop,00000003)'任务句柄 Dim childHandle3 As IntPtr =GetDlgItem(ChildHandle1,00000006)'来电 Dim Hndl As IntPtr = Marshal.AllocHGlobal(200) NumText = SendMessage(childHandle3, WM_GETTEXT, 200, Hndl) strText = Marshal.PtrToStringUni(Hndl) messagebox.Show (strText,"来电") Dim childHandle4 As IntPtr =GetDlgItem(ChildHandle1,00000007)'联系 Hndl= Marshal.AllocHGlobal(200) NumText = SendMessage(childHandle4, WM_GETTEXT, 200, Hndl) strText = Marshal.PtrToStringUni(Hndl) messagebox.Show (strText,"联系") End Sub End Class
    2011年1月6日 15:15

全部回复