DJeX
Veteran Member
Posts: 1138 Reputation: 11
– / / –
Joined: Jul 2003
|
O.P. RE: Visual Basic Code Help
Ok I did what you said and now I get this error
My Code With Changes:
code: Private Sub Click(Btnhwnd As Long)
Dim ChildID As Long
Dim Nul As Long
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 Long, CurHwnd As Long, T As String
Dim Length As Long, x As Long, y As Long
' 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 Long 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 Long 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: 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 Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Integer) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd%, ByVal wCmd%) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd%, ByVal lpString$, ByVal nMaxCount%) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Long
Declare Function SendMessageByNum& Lib "user32" Alias "SendMessage" (ByVal hwnd%, ByVal wMsg%, ByVal wparam%, ByVal lparam&)
|
|