Advertisement
Guest User

Untitled

a guest
Jul 12th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.34 KB | None | 0 0
  1. 'Tutorial #3 in series of Paltalk programming tutorials....
  2.  
  3. Imports System.Runtime.InteropServices
  4.  
  5.  
  6. Public Partial Class MainForm
  7.    
  8.     Public Class PalHwnds
  9.         Public hMainHwnd As IntPtr
  10.         Public hIncommingHwnd As IntPtr
  11.         Public hOutgoingHwnd As IntPtr
  12.         Public hNickListHwnd As IntPtr
  13.     End Class
  14.    
  15.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
  16.     Private Shared Function EnumChildWindows(ByVal hWndParent As System.IntPtr, ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As PalHwnds) As Boolean
  17.     End Function
  18.    
  19.     Private Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As PalHwnds) As Boolean
  20.    
  21.     <DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True, CharSet:=CharSet.Auto)> _
  22.     Private Shared Function FindWindowByClass( _
  23.     ByVal lpClassName As String, _
  24.     ByVal zero As IntPtr) As IntPtr
  25.     End Function
  26.    
  27.     <DllImport("user32.dll", SetLastError:=True)> _
  28.     Private Shared Function IsWindowVisible(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
  29.     End Function
  30.    
  31.     <DllImport("user32.dll")> _
  32.     Public Shared Function GetDlgCtrlID(ByVal hwndCtl As Integer) As Integer
  33.     End Function
  34.    
  35.    
  36.     Public Sub New()
  37.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  38.         Me.InitializeComponent()
  39.        
  40.         '
  41.         ' TODO : Add constructor code after InitializeComponents
  42.         '
  43.     End Sub
  44.    
  45.    
  46.     Public Shared Function ProcessChildWindows(ByVal hWnd As IntPtr, ByVal lParam As PalHwnds) As Boolean
  47.         Dim ID As Integer = GetDlgCtrlID(hWnd.ToInt32)
  48.        
  49.         If IsWindowVisible(hWnd) = True Then
  50.         Select Case ID
  51.          Case 202
  52.             LParam.hIncommingHwnd = hWnd
  53.          Case 203
  54.             LParam.hOutgoingHwnd = hWnd
  55.          Case 1789
  56.             LParam.hNickListHwnd = hWnd
  57.          Case Else
  58.             Return True
  59.          End Select
  60.         End If
  61.        Return True     
  62.     End Function
  63.    
  64.    
  65.     Sub Button1Click(sender As Object, e As EventArgs)
  66.         Dim wInfo As New PalHwnds
  67.        
  68.         wInfo.hMainHwnd = FindWindowByClass("DlgGroupChat Window Class", IntPtr.Zero)
  69.        
  70.         If wInfo.hMainHwnd = IntPtr.zero Then
  71.             Exit sub
  72.         End If
  73.        
  74.         EnumChildWindows(wInfo.hMainHwnd, AddressOf ProcessChildWindows, wInfo)
  75.        
  76.         txtIncomming.Text = wInfo.hIncommingHwnd.tostring
  77.         txtOutgoing.Text = wInfo.hOutgoingHwnd.tostring
  78.         txtNicklist.Text = wInfo.hNicklistHwnd.tostring
  79.         txtMainHwnd.Text = wInfo.hMainHwnd.tostring
  80.     End Sub
  81.    
  82. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement