[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
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
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!
Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?
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 ?
Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?
Quote:
Originally Posted by
tony007
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
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?
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