|
-
Mar 12th, 2009, 04:30 AM
#1
Thread Starter
Lively Member
[RESOLVED] Change caption or text of running Application
Hi,
for once again i am trying something difficult...
Well i want my VB6 program see the current application running at my desktop (that the easy part) and with one click change for example the title of running application (Application - EXE - that is not mine)...
For example if Windows Calculator running... with one click to my program at the button change title of "Calculator" - i want to turn the title of this program to something else like "C-a-l-c-u-l-a-t-o-r"...
is that possible to change the captions or text of a running application ?
and how ?
Thanks in advance... :-)
-
Mar 12th, 2009, 05:18 AM
#2
Thread Starter
Lively Member
Re: Change caption or text of running Application
...i ve found that code.... that changes text of Start button of Windows XP...
vb Code:
Private Const WM_SETTEXT = &HC
Private Const WM_GETTEXT = &HD
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Sub SetStartCaption(str As String)
Dim StartBar As Long
Dim StartBarText As Long
Dim sCaption As String
StartBar = FindWindow("Shell_TrayWnd", vbNullString)
StartBarText = FindWindowEx(StartBar, 0&, "button", vbNullString)
Debug.Print StartBarText
sCaption = Left(str, 5)
SendMessageSTRING StartBarText, WM_SETTEXT, 256, sCaption
Exit Sub
End Sub
code found here
but i don;t know how to "cycle" the controls to see caption/texts before change...
-
Mar 12th, 2009, 12:37 PM
#3
Frenzied Member
Re: Change caption or text of running Application
Code:
'System & API - How to Change Other Window's Caption
Option Explicit
'Add two Text Boxes and a Command Button to your form.
'Insert the caption of the window you want to change in Text1.
'Insert the new caption in Text2.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim target_hwnd As Long
Dim target_name As String
Dim new_caption As String
target_name = Text1.Text
target_hwnd = FindWindow(vbNullString, target_name)
If target_hwnd = 0 Then
MsgBox "Cannot find target"
Exit Sub
End If
new_caption = Text2.Text
SendMessage target_hwnd, WM_SETTEXT, 0, ByVal new_caption
End Sub
Private Sub Form_Load()
Text1.Text = "My Computer"
Text2.Text = "New Caption"
End Sub
Good Luck
-
Mar 13th, 2009, 02:30 AM
#4
Thread Starter
Lively Member
Re: Change caption or text of running Application
@vb5prgrmr thank for your answer.. but i didn't mean that ... exactly... i want my programs reads the Controls of Calculator... the title that may be in German / Greek or any other Language... and change it with the text i want...
In generic words i want to read all controls and caption of other application.
if that code was possible will be ok for me .. but it isnt:
vb Code:
k=0
for x=1 to otherapplication.controls.count
if otherapplication.control(x).typeof is label then
if otherappliction.control(x).caption="Calculator" then
otherapplication.control(x).caption="C-A-l-C-u-l-a-t-o-r"
k=k+1
end if
end if
next x
debug.print "From " & otherapplication.controls.count & " change only " & k
i want to cycle all the controls of the other Application... at least that i can view...
-
Mar 13th, 2009, 06:35 AM
#5
Frenzied Member
Re: Change caption or text of running Application
Ok, you will need to add the API EnumChildWindows to enumerate through the controls of the target application and then use the SendMessage API.
Good Luck
-
Mar 13th, 2009, 06:37 AM
#6
Thread Starter
Lively Member
Re: Change caption or text of running Application
@vb5prgrmgr can you give the code or the example of how to do it ?
-
Mar 13th, 2009, 07:13 AM
#7
Frenzied Member
Re: Change caption or text of running Application
You can find some example code here
http://www.acky.net/forums/index.php?showtopic=7497
or search the web for enumerate child windows
-
Mar 13th, 2009, 07:17 AM
#8
Thread Starter
Lively Member
Re: Change caption or text of running Application
-
Mar 13th, 2009, 12:18 PM
#9
Thread Starter
Lively Member
Re: Change caption or text of running Application
vb Code:
Option Explicit
Public Const WM_SETTEXT = &HC
Public Const WM_GETTEXT = &HD
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessageSTRING Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Static winnum As Integer
winnum = winnum + 1
ReDim winhandle(winnum) As Long
winhandle(winnum) = hwnd
EnumChildProc = 1
End Function
'-------------------
'-Form code:
Public Sub SetStartCaption(str As String)
Dim StartBar As Long
Dim StartBarText As Long
Dim sCaption As String
StartBar = FindWindow("Shell_TrayWnd", vbNullString)
StartBarText = FindWindowEx(StartBar, 0&, "button", vbNullString)
Debug.Print StartBarText
sCaption = Left(str, 5)
SendMessageSTRING StartBarText, WM_SETTEXT, 256, sCaption
Exit Sub
End Sub
Private Sub Form_Load()
Dim pHandle As Long
Dim bHandle As Long, h As Long, i As Long, length As Long
Dim caption As String
pHandle = FindWindow(vbNullString, "Áñéèìïìç÷áíÞ")
h = EnumChildWindows(pHandle, AddressOf EnumChildProc, 0)
bHandle = 0
If (h = 1) Then
For i = 1 To (UBound(winhandle) - LBound(winhandle))
caption = Space$(1024)
length = GetWindowText(winhandle(i), caption, Len(caption))
caption = Left$(caption, length)
Debug.Print caption, length
If caption = "OK" Then
bHandle = winhandle(i)
Exit For
End If
Next i
End If
End Sub
I am getting error at ubound(winhandle) why ?
vb Code:
[I]For i = 1 To (UBound(winhandle) - LBound(winhandle))[/I]
Type mismatch.
-
Mar 13th, 2009, 12:30 PM
#10
Frenzied Member
Re: Change caption or text of running Application
to begin with I do not see where winhandle is declared, is it declared?
-
Mar 14th, 2009, 03:39 AM
#11
Thread Starter
Lively Member
Re: Change caption or text of running Application
vb Code:
ReDim winhandle(winnum) As Long winhandle(winnum) = hwnd
what do you suggest ?
-
Mar 14th, 2009, 04:24 AM
#12
Fanatic Member
Re: Change caption or text of running Application
 Originally Posted by cyberd
Hi,
for once again i am trying something difficult...
Well i want my VB6 program see the current application running at my desktop (that the easy part) and with one click change for example the title of running application (Application - EXE - that is not mine)...
For example if Windows Calculator running... with one click to my program at the button change title of "Calculator" - i want to turn the title of this program to something else like "C-a-l-c-u-l-a-t-o-r"...
is that possible to change the captions or text of a running application ?
and how ?
Thanks in advance... :-)
Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Sub Form_Load()
Dim H As Long
H = FindWindow(vbNullString, "Calculator")
If H > 0 Then
SetWindowText H, "C-a-l-c-u-l-a-t-o-r"
Else
MsgBox "Calculator not found"
End If
End Sub
-
Mar 14th, 2009, 04:45 AM
#13
Thread Starter
Lively Member
Re: Change caption or text of running Application
@chunk you didn't read after 1st post ? - i want to cycle all controls of form...
thanks anyway but i have already this answer..
-
Mar 14th, 2009, 06:11 AM
#14
Frenzied Member
Re: Change caption or text of running Application
proper declaration would be say at form level
Code:
dim winhandle() as Long
and then keep the rest of your code as is
Good Luck
-
Mar 14th, 2009, 06:23 AM
#15
Thread Starter
Lively Member
Re: Change caption or text of running Application
hmm... seems ok.. i am continue the project... seems no error.. thanx again
-
Mar 14th, 2009, 06:28 AM
#16
Frenzied Member
Re: Change caption or text of running Application
-
Mar 14th, 2009, 06:45 AM
#17
Thread Starter
Lively Member
Re: Change caption or text of running Application
caugh.. hmmm..
what about the menus of forms how i can enumerate them... ? is it possible ?
(the title and the buttons, and captions enumerated by the code i ve write - but menus... not...)
-
Mar 14th, 2009, 07:19 AM
#18
Frenzied Member
Re: Change caption or text of running Application
Hmmm.... Not sure. Try to send via sendmessage "&File" to main app and see if the file menu drops (that is if it has a file menu item). I would think that during your enumeration you should recieve a handle to a window with no caption but its class should be something like ToolbarWindow32.
Just used SPY++ on IE and it reported that the captionless window (the menu bar) does have a child.
Good Luck
-
Mar 14th, 2009, 01:27 PM
#19
Fanatic Member
Re: Change caption or text of running Application
 Originally Posted by cyberd
caugh.. hmmm..
what about the menus of forms how i can enumerate them... ? is it possible ?
(the title and the buttons, and captions enumerated by the code i ve write - but menus... not...)
i dont this this is possible. If this is possible then i would also like to learn it
because it will always show 32676 something like that on menus
-
Mar 14th, 2009, 08:20 PM
#20
Frenzied Member
Re: Change caption or text of running Application
Okay, with a little research, I found some more API's for you...
SetForegroundWindow (not really needed but will allow you to see if the rest of the API's work)
In help look up GetSystemMenu
At the bottom look into the Menu Functions and the WM_SYSCOMMAND>Keyboard Accelerator Messages
Good Luck
-
Mar 14th, 2009, 08:31 PM
#21
Frenzied Member
Re: Change caption or text of running Application
Try this code to turn a string like "ABCD" into "A-B-C-D"
Code:
Public Function dashString(sInput As String) As String
Dim tempArray() As String, i As Integer
ReDim tempArray(1 To Len(sInput))
For i = 1 To Len(sInput)
tempArray(i) = Mid$(sInput, i, 1)
Next i
dashString = Join(tempArray, "-")
End Function
-
Mar 16th, 2009, 01:26 AM
#22
Thread Starter
Lively Member
Re: Change caption or text of running Application
@Zach_VB6 please read the topic .. thanks again..
@vb5prgrmr ...can't get it.. can you give a simple example...
-
Mar 16th, 2009, 01:55 AM
#23
Frenzied Member
Re: Change caption or text of running Application
Don't know if I have one... Will search systems... If anybody else perhaps has an example please post...
-
Mar 17th, 2009, 11:19 AM
#24
Thread Starter
Lively Member
Re: Change caption or text of running Application
did anyone found something... (?)...
-
Mar 17th, 2009, 11:32 AM
#25
Frenzied Member
Re: Change caption or text of running Application
No not yet.. I have to work sometimes... 
Perhaps, that you are now on a bit of a different subject, start a new thread with something like
How to enumerate seperate program's menu items
Or whatever
-
Mar 17th, 2009, 11:43 AM
#26
Thread Starter
Lively Member
Re: [RESOLVED] Change caption or text of running Application
ok thanks, you have right
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
|