Results 1 to 6 of 6

Thread: Automation questions

  1. #1

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Automation questions

    Three questions that should be simple, though I don't know the proper way to do it:

    1) Given an hwnd of a window, how can I get the titlebar caption?

    2) Given an hwnd of a button, how can I get the button's caption?

    3) Given an hwnd of a control, how can I tell what type of control it is?

    EDIT: Nevermind, I think I figured everything out thanks to this MSDN article.
    Last edited by Ellis Dee; Feb 27th, 2010 at 02:36 AM.

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Automation questions

    1)

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
    (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    
    Private Sub Command1_Click()
        Dim lngHwndOne As Long, lngHwndTwo As Long
        Dim WindTitle As String * 256
        
        '~~> Sample Internet Explorer. You already have a hwnd so
        '~~> you may comment it
        lngHwndOne = FindWindow("IEFrame", vbNullString)
        
        '~~> Get the title bar text
        lngHwndTwo = GetWindowText(lngHwndOne, WindTitle, 255)
        
        '~~> Display it
        MsgBox Left$(WindTitle, lngHwndTwo)
    End Sub
    2)

    Code:
    '~~> Create a form1 and place a command button on. Set it's caption to anything
    '~~> that you like
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
    (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    
    Private 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
    
    
    Private Sub Command1_Click()
        Dim lngHwndOne As Long, lngHwndTwo As Long
        Dim WindTitle As String * 256
        
        lngHwndOne = FindWindowEx(Me.hwnd, 0, "ThunderCommandButton", vbNullString)
        
        lngHwndTwo = GetWindowText(lngHwndOne, WindTitle, 255)
        
        '~~> Display it
        MsgBox Left$(WindTitle, lngHwndTwo)
    End Sub
    3)

    Code:
    '~~> Create a form1 and place a command button
    
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
    (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    
    Private Sub Command1_Click()
        Dim lngHwndOne As Long, WindTitle As String * 256
        
        lngHwndOne = GetClassName(Command1.hwnd, WindTitle, 255)
        
        '~~> Displays the class of the control
        '~~> For example "ThunderCommandButton" for the command button
        MsgBox Left$(WindTitle, lngHwndOne)
    End Sub
    Last edited by Siddharth Rout; Feb 27th, 2010 at 03:56 AM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Automation questions

    Sweet, perfect. I'm trying to compile a comprehensive automation library to post in the CodeBank, so any tips, tricks or ideas are welcome.

    (And doh! Can't give you rep again so soon.)

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Automation questions

    Updated the code for point 2 and Working on point 3

    (And doh! Can't give you rep again so soon.)
    I know
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Automation questions

    All updated
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Automation questions

    You're the man.

    I may have followup questions as I put together the library module over the next few days, so keep an eye out for this thread getting bumped. Once I finish and post to the codebank I'll mark the thread resolved.

    Thanks much.

Posting Permissions

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



Click Here to Expand Forum to Full Width