hey196
May 15th, 2000, 07:57 AM
Hi anyone,
I am trying to use API to
1. find out how many Windows is currently running in my computer
2. How to programmatically change the caption of another program??
Please email me if you can help.
hey196@hotmail.com
Ok I can answer the second on...
First thing you need is a APY SPY, YOu should have a program called SPY++, if not, there are thousands available on the internet... anyways..
Say you got a folder, named "APISpy" (in windows 98)... so you open this folder up, now you use the API to collect information from this window, many api spy's give you information when you move your mouse over stuff, if your api spy does that, then just point to the title bar, and record these information:
Class Name, Window Text/Caption(usually tells you the caption of the window)... well after you got these 2 information, what you do is use these 2 API funtions:
here's what you do, (includes comments)
Make a form, and put a command button on there
'API function to find a window's Handle, using it's class name as well as the caption sometimes...
Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
'Send Messages, this is the whole thing, anytime you need to do something to another window, u send a message to it, and this is the function you use...
Public Declare Function SendMessageByString Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As String) As Long
Private Sub Command1_Click()
'Find a window, which is a folder, and has the caption "APISpy"
blah& = FindWindow("CabinetWClass", "APISpy")
'Change Window's Caption to "WhatsUP"
SendMessageByString blah&, WM_SETTEXT, 0&, "WhatsUP"
End Sub
Ok, now the blah& = FindWindow("CabinetWClass","APISpy") finds the window and returns the handle, the reason I'm using the second one "ApiSpy" is because there could be many objects of the same class open at the same time (in this case folders), so I narrow the search down to one folder with a specific caption, "API SPY"... if you know that there's only one object of a unique class running at one time, then u don't need to use the second field, you could just put 'vbNullString' in there, and it will just find the class and give u the handle......... Mess around with it... Hope this helps a bit, any questions, I'd be happy to answer... if I can answer