Results 1 to 7 of 7

Thread: FindWindow API call...not working

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    2

    Red face

    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...

  2. #2
    Guest
    the mine sweeper class is "Minesweeper"

    do this
    Code:
    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.

  3. #3
    Guest
    why are you using

    Code:
    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..


  4. #4
    Guest
    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2000
    Posts
    2

    Talking Got it working...

    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...

  6. #6
    Guest
    i am a beginner at API too, but I know my way around the findwindow API

  7. #7
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb Win32 API Bugs

    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.


    Code:
    '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]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width