Results 1 to 6 of 6

Thread: VB Help Reqd

  1. #1
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499

    Unhappy VB Help Reqd

    API Help

    What I can give.
    I want to be able to identify a window and get the contents of its dialogue.
    The window class is #32770
    I know how to get the hwnd of this window but I need to be able to get the hwnd of its children and identify them.

    Anyone know if this can be done.

  2. #2
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953

    Talking

    hey remember the old VB-AOL prog days...
    there was that guy "dos32" remember him-
    man he was pretty cool- he wrote a really nice tutorial on API hWnd kind stuff...
    it's a great resource IMO, and a must read for Window handling...
    yeah, I\'m gonna need that by friday...

  3. #3
    Junior Member
    Join Date
    Oct 2001
    Posts
    2
    Check out the EnumChildWindows API call. Funny that, a reasonably well-named function!

    More on this if you're interested @ http://www.mvps.org/vb/hardcore/hhindex.htm

  4. #4
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953
    hey doesn't the Window CLass change whenever it is loaded anew?

    Handle
    - Returns a long value
    - Ever-changing
    - Required to send API calls to that window

    Class Name
    - Is a String data type
    - Stays the same
    - Will be used in our code to find the handle we need
    these might help too, here are some great API calls to help... although you will need to look up their usage yourself
    Code:
    Option Explicit
    
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (destination As Any, source As Any, ByVal Length As Long)
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
    Public Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Public Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
    Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    Public Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByVal lpBuffer As String, ByVal nSize As Long, ByRef lpNumberOfBytesWritten As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
    Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
    Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Public Declare Function ReleaseCapture Lib "user32" () As Long
    Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    
    Public Const BM_GETCHECK = &HF0
    Public Const BM_SETCHECK = &HF1
    
    Public Const HWND_NOTOPMOST = -2
    Public Const HWND_TOPMOST = -1
    
    Public Const LB_GETCOUNT = &H18B
    Public Const LB_GETITEMDATA = &H199
    Public Const LB_GETTEXT = &H189
    Public Const LB_GETTEXTLEN = &H18A
    Public Const LB_SETCURSEL = &H186
    Public Const LB_SETSEL = &H185
    
    Public Const SND_ASYNC = &H1
    Public Const SND_NODEFAULT = &H2
    Public Const SND_FLAG = SND_ASYNC Or SND_NODEFAULT
    
    Public Const SW_HIDE = 0
    Public Const SW_SHOW = 5
    
    Public Const SWP_NOMOVE = &H2
    Public Const SWP_NOSIZE = &H1
    
    Public Const VK_DOWN = &H28
    Public Const VK_LEFT = &H25
    Public Const VK_MENU = &H12
    Public Const VK_RETURN = &HD
    Public Const VK_RIGHT = &H27
    Public Const VK_SHIFT = &H10
    Public Const VK_SPACE = &H20
    Public Const VK_UP = &H26
    
    Public Const WM_CHAR = &H102
    Public Const WM_CLOSE = &H10
    Public Const WM_COMMAND = &H111
    Public Const WM_GETTEXT = &HD
    Public Const WM_GETTEXTLENGTH = &HE
    Public Const WM_KEYDOWN = &H100
    Public Const WM_KEYUP = &H101
    Public Const WM_LBUTTONDBLCLK = &H203
    Public Const WM_LBUTTONDOWN = &H201
    Public Const WM_LBUTTONUP = &H202
    Public Const WM_MOVE = &HF012
    Public Const WM_SETTEXT = &HC
    Public Const WM_SYSCOMMAND = &H112
    
    Public Const PROCESS_READ = &H10
    Public Const RIGHTS_REQUIRED = &HF0000
    
    Public Const ENTER_KEY = 13
    Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    
    Public Type POINTAPI
            X As Long
            Y As Long
    End Type
    yeah, I\'m gonna need that by friday...

  5. #5
    Senior Member
    Join Date
    Jan 2003
    Posts
    1,499
    Woo Hoo,

    Got that bit working.

    Next, This particular form has a yes button a no button and a help button.

    I want to press the yes button.

    Sendkeys is not an option because it sends them to the window to quickly.

    Ideas ?

  6. #6
    Senior Member tampabay420's Avatar
    Join Date
    Aug 2002
    Posts
    953
    this was taken from the tutorial i just posted

    First we will deal with those that have a class name of "Button". You will need only the window handle of the button and the following API calls.

    SendMessage
    WM_KEYDOWN
    WM_KEYUP
    VK_SPACE

    Dim sButton As Long
    Call SendMessage(sButton&, WM_KEYDOWN, VK_SPACE, 0&)
    Call SendMessage(sButton&, WM_KEYUP, VK_SPACE, 0&)

    As you can see, we are sending a window's message to the button. This message is a virtual key message which simulates the pressing of the space bar. You need to have the WM_KEYUP too though. Without it, the button is held down.

    SendMessage
    WM_LBUTTONDOWN
    WM_LBUTTONUP

    Dim dButton As Long
    Call SendMessage(dButton&, WM_LBUTTONDOWN, 0&, 0&)
    Call SendMessage(dButton&, WM_LBUTTONUP, 0&, 0&)

    As you can see, this is a little simpler than the last. We find our button, then instead of using virtual keys, we use the left mouse button constants.
    /edit->
    oh btw- API calls are just as fast (if not faster) - what is the problem about it being too fast? use a timing function (you will need extra code, SLEEP isn't an option anymore, l0l- old BASIC humor) anyway- good luck
    yeah, I\'m gonna need that by friday...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •