PDA

Click to See Complete Forum and Search --> : Icon enabled or not?


Steve Stunning
Dec 10th, 1999, 02:56 AM
How can I tell if an icon (or anything else) in another program is enabled or disabled?

Thanks for reading this.....

rino_2
Dec 10th, 1999, 03:12 AM
What do you mean "an icon is enabled"???

Aaron Young
Dec 10th, 1999, 03:15 AM
You can check the GWL_STYLE flags of a Window Handle to determine if a Window/Control has been disabled, using the GetWindowLong API with the WS_DISABLED Constant, eg.

Add a Timer Control to a Form..

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hwnd As Long, ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Const WS_DISABLED = &H8000000
Private Const GWL_STYLE = (-16)

Private Sub Form_Load()
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim tPOINT As POINTAPI
Dim lHwnd As Long
Dim lChild As Long
'Get Current Cursor Position in Screen Coords
Call GetCursorPos(tPOINT)
'Get Window Under the Cursor if there is one
lHwnd = WindowFromPoint(tPOINT.x, tPOINT.y)
'If there is, convert the Coords to Coords Relative to the Window
If lHwnd Then Call ScreenToClient(lHwnd, tPOINT)
'Check for Child Windows, (Only Way to Detect Disabled/Invisible Windows)
lChild = ChildWindowFromPoint(lHwnd, tPOINT.x, tPOINT.y)
If lHwnd > 0 Then
If lChild Then lHwnd = lChild
'Check to see if the Window/Control has been Disabled
If (GetWindowLong(lHwnd, GWL_STYLE) And WS_DISABLED) = WS_DISABLED Then
Caption = "Disabled"
Else
Caption = "Enabled"
End If
Else
Caption = ""
End If
End Sub

Run this then Point to a Disabled Control/Window and it should Display "Disabled" in the Forms Caption.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Steve Stunning
Dec 10th, 1999, 03:16 AM
Oops... :)

A picture on a toolbar