Results 1 to 13 of 13

Thread: Get Active Control [Resolved]

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Get Active Control [Resolved]

    How can I get the handle of the active control on the screen? Not just my form. With the GetForegroundWindow I can get the window but not the control... Any ideas?

    Thanks
    Last edited by manavo11; Mar 3rd, 2004 at 08:38 PM.


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    I can't think of an answer right now, but I did find this on Google. It's to a thread that [I'm supposing] asks the same question, but you have to register for the site. I don't wanna do that.

    http://www.vbcity.com/forums/topic.asp?tid=31361
    Please rate my post.

  3. #3

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Thanks. I'll have a look


    Has someone helped you? Then you can Rate their helpful post.

  4. #4

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    No luck with that. It just sais to enumerate the child controls of the window and look for some flag that'll show if it's active. I listed all the controls but I have no idea for a flag


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    This may work: Form1.ActiveControl
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  6. #6

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    That would work if I was working on my form... But that and Screen.ActiveControl only show for the controls of the VB project. I need for other apps also


    Has someone helped you? Then you can Rate their helpful post.

  7. #7
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    That's what I was afraid of

    Well, time to hunt through the API guide again
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  8. #8
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Here's a C++ version that may work: http://www.experts-exchange.com/Prog..._10302522.html. It uses threads, so you never know how it would do in VB.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  9. #9

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by jemidiah
    That's what I was afraid of

    Well, time to hunt through the API guide again
    I have searched but it seems there is nothing


    Has someone helped you? Then you can Rate their helpful post.

  10. #10
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Try this...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, _
    4.                                                          ByVal idAttachTo As Long, _
    5.                                                          ByVal fAttach As Long) _
    6.                                                          As Long
    7. Private Declare Function GetForegroundWindow Lib "user32" () As Long
    8. Private Declare Function GetFocus Lib "user32" () As Long
    9. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _
    10.                                                                 lpdwProcessId As Long) _
    11.                                                                 As Long
    12. Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    13.  
    14.  
    15. Private Sub Timer1_Timer()
    16. Dim hFore As Long, hFocus As Long
    17.  
    18.     hFocus = GetFocus
    19.    
    20.     If hFocus = 0 Then
    21.         hFore = GetForegroundWindow()
    22.         Call AttachThreadInput(GetWindowThreadProcessId(hFore, 0&), GetCurrentThreadId, True)
    23.         hFocus = GetFocus
    24.         Call AttachThreadInput(GetWindowThreadProcessId(hFore, 0&), GetCurrentThreadId, False)
    25.     End If
    26.    
    27.     Me.Caption = hFocus
    28.    
    29. End Sub

    I put it in a timer to make sure it actually worked. It seems to.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  11. #11

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    I'll test it...


    Has someone helped you? Then you can Rate their helpful post.

  12. #12
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by crptcblade
    VB Code:
    1. Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, _
    2.                                                          ByVal idAttachTo As Long, _
    3.                                                          ByVal fAttach As Long) _
    4.                                                          As Long
    I wonder what else this could get accomplished. Cool function...jeez, I'm a geek.
    Please rate my post.

  13. #13

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Once again, you have found my solution...

    Thanks


    Has someone helped you? Then you can Rate their helpful post.

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