|
-
May 20th, 2011, 06:11 AM
#1
Thread Starter
Frenzied Member
[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.
-
May 20th, 2011, 08:45 AM
#2
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
-
May 20th, 2011, 09:04 AM
#3
Thread Starter
Frenzied Member
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!
-
May 20th, 2011, 09:46 AM
#4
Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?
Last edited by LaVolpe; May 20th, 2011 at 10:27 AM.
-
May 20th, 2011, 02:56 PM
#5
Thread Starter
Frenzied Member
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.
-
May 20th, 2011, 03:24 PM
#6
Re: How to Set Focus To A Specific Hwnd(Accordion ctl hwnd) In An External App?
 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
-
May 20th, 2011, 07:59 PM
#7
New Member
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?
-
May 20th, 2011, 09:21 PM
#8
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|