[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)
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
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>
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.
Re: trying to determine if a button is enabled or disabled in another programs window
Quote:
Originally Posted by
dunfiddlin
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>:D
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!)
Re: [RESOLVED] trying to determine if a button is enabled or disabled in another prog
Quote:
Originally Posted by
dunfiddlin
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:D