Results 1 to 8 of 8

Thread: [RESOLVED] How to Set Focus To A Specific Hwnd In An External App?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Resolved [RESOLVED] How to Set Focus To A Specific Hwnd In An External App?

    Hi all there is list in another application that i don't have its source code. However i have the list hwnd and wondering how i can set focus on it when it loses focus ?current if i click on any item in that list that item get highlighted and it shows that it has the focus but sometime it loses focus so how i can set the focus on it? hope some one show me how this can be done.Thanks
    Last edited by tony007; May 20th, 2011 at 09:29 PM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    Suggestion:

    1) Use the API AttachThreadInput on seinfeldsuperman after getting thread id with GetWindowThreadProcessId
    2) Then use SetFocus API on caccordionctl
    3) Then use AttachThreadInput on seinfeldsuperman to undo step #1

    Examples of the above API declarations and usage can be found by a simple search on this site
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    lavlpe thanks for your reply but how to get thread id and can you give me example of api attachthreadinput i couldn't find an example in the fourm!

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    Your searching skills are lacking
    http://www.vbforums.com/showthread.php?t=281947
    Last edited by LaVolpe; May 20th, 2011 at 10:27 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    Thanks this code brings the application to front but how to set the focus on list first item not the list category name(which is on the top of first item of list) ? how to declare setfocus ?
    Last edited by tony007; May 20th, 2011 at 09:30 PM.

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    Quote Originally Posted by tony007 View Post
    Thanks this code brings the application to front but how to set the focus on Accordion ctl list first item not the Accordion category name(which is on the top of first item of Accordion ctl list) ? how to declare setfocus ?
    SetFocus API as I mentioned in my first reply
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7
    New Member VuVanHoanh's Avatar
    Join Date
    May 2011
    Location
    Viet Nam
    Posts
    9

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    @LaVolpe: Can we use the SendMessage function with WM_ACTIVE constant to set focus to a handle?

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?

    Many thanks i found that thread of you and it solved the problem!

    Code:
    Private Declare Function AttachThreadInput Lib "user32.dll" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
    Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As Long, ByRef lpdwProcessId As Long) As Long
    Private Declare Function SetFocusAPI Lib "user32.dll" Alias "SetFocus" (ByVal hwnd As Long) As Long
    
    
    Private Sub Command1_Click()
        
        Dim lThreadID As Long, lChildhWnd As Long
        
        lChildhWnd = &H1505BC ' << provide correct value
        
        lThreadID = GetWindowThreadProcessId(lChildhWnd, ByVal 0&)
        AttachThreadInput lThreadID, App.ThreadID, True
        SetFocusAPI lChildhWnd
        SendKeys "{DOWN}"
        AttachThreadInput lThreadID, App.ThreadID, False
    
    End Sub

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