Results 1 to 4 of 4

Thread: Icon enabled or not?

  1. #1

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    How can I tell if an icon (or anything else) in another program is enabled or disabled?

    Thanks for reading this.....

  2. #2
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    What do you mean "an icon is enabled"???

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    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..
    Code:
    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

  4. #4

    Thread Starter
    Hyperactive Member Steve Stunning's Avatar
    Join Date
    Jul 1999
    Location
    Fairfax, Virginia
    Posts
    314

    Post


    Oops...

    A picture on a toolbar

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