Dear all,
I used the following code to change the title of an application open by shell
command, it works for notepad and some other applications, but not working for
others (eg. mspaint.exe) i dont know why (but if i put the the setwindowtext in
a timer it works !!!) can you explain why ? and how to make it work without
timer.
Thank you.
P. Anand
---------------------------------------------------------------
Private Sub Command1_Click()
Dim hProcessID As Long
Dim nHwnd As Long
' hProcessID = Shell("notepad.exe", vbNormalFocus) working
hProcessID = Shell("mspaint.exe", vbNormalFocus) 'not working
' if i put following two lines in timer then it works !!!!
nHwnd = GethWndFromProcessID(hProcessID)
SetWindowText nHwnd, "Title Changed !!"
End Sub
-------------------------------------------------------------------------------------------
Public Function GethWndFromProcessID(hProcessIDToFind As Long) As Long
Dim hWndDesktop As Long
Dim hWndChild As Long
Dim hWndChildProcessID As Long
On Local Error GoTo GethWndFromProcessID_Error
'get the handle to the desktop
hWndDesktop = GetDesktopWindow()
'get the first child under the desktop
hWndChild = GetWindow(hWndDesktop, GW_CHILD)
'hwndchild will = 0 when no more child windows are found
Do While hWndChild <> 0
'get the ThreadProcessID of the window
Call GetWindowThreadProcessId(hWndChild, hWndChildProcessID)
'if it matches the target, exit returning that value
If hWndChildProcessID = hProcessIDToFind Then
GethWndFromProcessID = hWndChild
Exit Do
End If
'not found, so get the next hwnd
hWndChild = GetWindow(hWndChild, GW_HWNDNEXT)
Loop
Exit Function
GethWndFromProcessID_Error:
GethWndFromProcessID = 0
Exit Function
End Function
---------------------------------------------------------
---------------------------------
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
[Non-text portions of this message have been removed]
'// =======================================================
Rules : http://ReliableAnswers.com/List/Rules.asp
Home : http://groups.yahoo.com/group/vbHelp/
=======================================================
Post : [email protected]
Join : [EMAIL PROTECTED]
Leave : [EMAIL PROTECTED]
'// =======================================================
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/vbhelp/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/