Results 1 to 7 of 7

Thread: [RESOLVED] trying to determine if a button is enabled or disabled in another programs window..

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] trying to determine if a button is enabled or disabled in another programs window..

    I'm basically trying to automate a task that has come to annoy me over the past few days, what i need to do is check if a specific button on another program is enabled or not. i have no clue where to begin, any suggestions? (with examples if you got please)

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: trying to determine if a button is enabled or disabled in another programs window

    try this. I used a test app executable with windowName = "testExe", + the button I was testing = "Button2":

    Code:
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        <DllImport("user32.dll")> _
        Private Shared Function IsWindowEnabled(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function
    
        Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim iHwnd As IntPtr = FindWindow(vbNullString, "testExe")
            Dim iHwndChild As IntPtr = FindWindowEx(iHwnd, IntPtr.Zero, vbNullString, "Button2")
            MsgBox(IsWindowEnabled(iHwndChild))
        End Sub
    
    End Class

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: trying to determine if a button is enabled or disabled in another programs window

    EDIT ... <Sigh>or .paul can just beat me to it.</sigh>
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: trying to determine if a button is enabled or disabled in another programs window

    thanks for the replies.. .paul. that one seemed to do the job perfectly. thank you.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: trying to determine if a button is enabled or disabled in another programs window

    Quote Originally Posted by dunfiddlin View Post
    EDIT ... <Sigh>or .paul can just beat me to it.</sigh>
    err... <Sigh>You had 52 minutes to answer before I answered. I'd say you had a fair chance if you had anything useful to say</sigh>

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: [RESOLVED] trying to determine if a button is enabled or disabled in another prog

    That assumes that I have nothing better to do with my time than sit watching the forum for every new post and leaping upon it the instant it's posted. I actually read the OP a few minutes before you posted at most! About the amount of time I read your latter post prior to this reply on account of indulging in an episode of Miss Fisher's Murder Mysteries in the meantime (a far better use of my time all round!)
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] trying to determine if a button is enabled or disabled in another prog

    Quote Originally Posted by dunfiddlin View Post
    I actually read the OP a few minutes before you posted at most!
    well unfortunately that is the nature of asynchronous communication. some you win, some you lose

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