I found this code on planetsourcecode and I need to know how to get it to work.
code:
Private Sub Click(Btnhwnd As Integer)
Dim ChildID As Integer
Dim Nul As Integer
Const GWW_ID = (-12)
ChildID = GetWindowWord(Btnhwnd, GWW_ID)
Nul = SendMessageByNum(GetParent(Btnhwnd), WM_COMMAND, ChildID, ByVal CLng(Btnhwnd))
End Sub
Private Sub Command1_Click()
'On Error Resume Next
Dim Btn As Integer, CurHwnd As Integer, T As String
Dim Length As Integer, x As Integer, y As Integer
' Trying to find the handle of the View
' Code Button so that
' by clicking this program's button, we
' can see the code
' window for this form.
CurHwnd = GetDesktopWindow() 'Get Desktop handle
CurHwnd = GetWindow(CurHwnd, GW_Child) 'Find Child Windows of Desktop
Do
If CurHwnd = 0 Then Exit Do 'No (more) matches found
' Find out how Integer the text in this win
' dow is
Length = GetWindowTextLength(CurHwnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(CurHwnd, T, Length + 1)
If InStr(UCase$(T), "PROJECT") Then
' The word "Project" was found in this W
' indow's text
' so this is likely VB's "Project" windo
' w
CurHwnd = GetWindow(CurHwnd, GW_Child)
' Looking now for the Project Window's c
' hild windows
Do
If CurHwnd = 0 Then Exit Sub 'No (more) matches found
' Find out how Integer the text in this win
' dow is
Length = GetWindowTextLength(CurHwnd)
T = Space$(Length + 1) 'Allocate buffer space
Length = GetWindowText(CurHwnd, T, Length + 1)
If InStr(UCase$(T), "VIEW CODE") Then
' This is the handle we want
Click CurHwnd 'Click the View Code Button
Exit Sub 'Exit the Sub
End If
CurHwnd = GetWindow(CurHwnd, GW_HWNDNEXT) 'Keep looking
Loop
End If
CurHwnd = GetWindow(CurHwnd, GW_HWNDNEXT) 'Keep looking
Loop
End Sub
Module Code:
code:
Global Const WM_COMMAND = &H111
Global Const GW_Child = 5
Global Const GW_HWNDFIRST = 0
Global Const GW_HWNDLAST = 1
Global Const GW_HWNDNEXT = 2
Global Const GW_HWNDPREV = 3
Global Const GW_OWNER = 4
Declare Function GetDesktopWindow Lib "User32" () As Integer
Declare Function GetParent Lib "User32" (ByVal hWnd As Integer) As Integer
Declare Function GetWindow Lib "User32" (ByVal hWnd%, ByVal wCmd%) As Integer
Declare Function GetWindowText Lib "User32" (ByVal hWnd%, ByVal lpString$, ByVal nMaxCount%) As Integer
Declare Function GetWindowTextLength Lib "User32" (ByVal hWnd As Integer) As Integer
Declare Function GetWindowWord Lib "User32" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
Declare Function SendMessageByNum& Lib "User32" Alias "SendMessage" (ByVal hWnd%, ByVal wMsg%, ByVal wparam%, ByVal lparam&)
I get this error when I run the code