Click to See Complete Forum and Search --> : FindWindow API call...not working
Ender
May 19th, 2000, 10:59 PM
OK, here is my dilema:
I am just trying a simple app to find the hWnd of a window, say Minesweeper. I have looked at the 'reference' guide you all have been talking about, and it worked for giving me the basics. The only problem is, the API call will not do what it is told. I have to following declaration statement:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
and the following code in my form_load() sub:
Blah = Module1.FindWindow(Clng(0),"Minesweeper")
Supposedly that is what the 'reference' site said, the only problem is, it does not work, at all. It always returns a 0. Yes, I do have Minesweeper up, and yes, it is copied directly from the 'reference' site. Any help would be greatly appreciated.
Ender, a new user...
the mine sweeper class is "Minesweeper"
do this
Private Sub Command1_Click()
MyhWnd = FindWindow("Minesweeper", "Minesweeper")
MsgBox MyhWnd
End Sub
Put this in the genaral declarations of a .bas file(module)
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
this works.
MyhWnd should be equal to the hWnd of minesweeper window.
it was for me.
why are you using
Blah = Module1.FindWindow(Clng(0), "Minesweeper")
all you need is FindWindow(blah blah).
and you are turning 0 into a long value.. for the class...
what reference site did you go to?
because the classname is not 0..
sorry for the triple posting....
The only problem is, the API call will not do what it is told.
it is doing what it is told, you are just not telling it to do what you want.
Ender
May 20th, 2000, 01:22 AM
I got it to work, thanks for you help. I used the following site:
http://www.vbapi.com
They said to do what I did to search for the hWnd of a window with just the Title Bar text. However, as I said befor this did not work. The program that I got to work, I did not want to have to mess with the classes, just the Window Title text. I found that it works with the following:
blah = FindWindow(vbNullString, "<title bar text>")
I then incorporated it into my program so that the user enters a title bar text and it gives them the hWnd. Simple, I know, but I am a beginner at API.
Thank you again for you help.
Ender, a new user...
i am a beginner at API too, but I know my way around the findwindow API ;)
Chris
May 23rd, 2000, 03:08 PM
Actually we can change the API function atguement datatype and the reason that cause your API not working is the original datatype for the lpCalssName is declare as String. Hence, you need to provide a correct Windows Class name else the function will always return 0.
Another way to bypass this problem is changing the arguement datatype from String to Any or Long as shown below and pass a 0& to the lpClassName to represent all Window Class.
'Original Api Function
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
'Modified 1
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
'Modified 2
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
If you persist to remain the arguement type, than I suggest you to use the Spy that come with VC6.0++ to get the Windows Class Name before you hardcode you source code.
Or you can use another API function to get the Windows Class Name.
Hope this can help you much. ;)
[Edited by Chris on 05-25-2000 at 01:28 PM]
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.