|
-
Nov 2nd, 2006, 06:01 AM
#1
Thread Starter
New Member
[RESOLVED] How to get Window Caption using its exe name?
Hi all!
Is it possible to get the window caption of an active process given its ".exe name"? If it's possible, how to do it?
Thanks for any reply.
-
Nov 2nd, 2006, 11:05 AM
#2
Re: How to get Window Caption using its exe name?
 Originally Posted by Momotae
Hi all!
Is it possible to get the window caption of an active process given its ".exe name"? If it's possible, how to do it?
Thanks for any reply.
Take a look at this LINK
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Nov 2nd, 2006, 12:06 PM
#3
Re: How to get Window Caption using its exe name?
 Originally Posted by Mark Gambo
It does not work for me
I tried to use GetWindowText from the returned hWnd, and it does not work... (returns empty string, or returns "M"...)
VB Code:
Option Explicit
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private lProcessID As Long
Private Sub Command1_Click()
lProcessID = Shell("Notepad.exe", vbNormalFocus)
End Sub
Private Sub Command2_Click()
Dim lhRet As Long, LN As Long, WindowText As String
lhRet = hWndFromProcID(lProcessID)
LN = GetWindowTextLength(lhRet)
WindowText = String(LN + 10, 0)
GetWindowText lhRet, WindowText, Len(WindowText)
Debug.Print WindowText
'Call BringWindowToTop(lhRet)
End Sub
Public Function hWndFromProcID(ProcID As Long) As Long
Dim lhTmp As Long
Dim lRetVal As Long
Dim lCurrentProcID As Long
On Error GoTo errhWndFromProcID
lhTmp = GetDesktopWindow()
lhTmp = GetWindow(lhTmp, GW_CHILD)
Do While lhTmp <> 0
lRetVal = GetWindowThreadProcessId(lhTmp, lCurrentProcID)
If lCurrentProcID = ProcID Then
hWndFromProcID = lhTmp
Exit Do
End If
lhTmp = GetWindow(lhTmp, GW_HWNDNEXT)
Loop
Exit Function
errhWndFromProcID:
hWndFromProcID = 0
End Function
-
Nov 2nd, 2006, 09:55 PM
#4
Thread Starter
New Member
Re: How to get Window Caption using its exe name?
Works for me, thanks Mark...
-
Nov 3rd, 2006, 05:31 AM
#5
Lively Member
Re: [RESOLVED] How to get Window Caption using its exe name?
Very Nice, it work for me too, Thx
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
|