Results 1 to 6 of 6

Thread: Error Using the FindWindow API

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question Error Using the FindWindow API

    Why is is that I get a return value when I look for a Window Name that is 2 characters long but when I go larger I get a return of 0?

    Code:
    Private Sub Command1_Click()
        'gets rid of any running instance of the program
        Dim CloseIt As Long
        CloseIt = FindWindow(vbNullString, "IA") ' This WORKS!
        'CloseIt = FindWindow(vbNullString, "METOO")' DOESN'T WORK! 
        PostMessage CloseIt, WM_CLOSE, 0&, 0&
    End Sub

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574
    A few places to consider for diagnosing your error.

    Firstly, call GetLastError immediately after the FindWindow statement to read the DLL error. Secondly, check manually in the Task Manager if the window with the caption METOO is running or not. If it is not running, the FindWindow function will fail and return 0. Finally, are you certain that the window you wish to find with the caption METOO actually HAS a caption? Is it a top level window? FindWindow even finds windows that are not top level but they must have a caption. If they do not have a caption, and you specify the second argument in FindWindow, you will get a return value of 0.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    I can verify that METOO is running in the Processes tab. See this EXE is simply a compiled VB6.0 application. The project title is the name of the Application. So why would IA work but the other doesn't?

    What do you mean by a top level window?

    Thanks

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Top level windows are like the ones that appear in the taskbar. They have no parent window.

    And FindWindow works off of the caption of the window you are looking for, not the name of the exe. So maybe that is your problem, unless I misunderstood your explanation.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574
    I think you suspect FindWindow looks for the application title. FindWindow actually looks for the caption string of the window. For e.g. when you create a form in Visual Basic, let's say your METOO application, the form has a caption property. What do(es) the caption of the form(s) in the METOO application read? Is there a window in the application with the caption METOO?

    By top level window, I mean a window that has no parent. If your application is an SDI (Single Document Interface application without an MDI form), then each of the forms in the application are top level windows since they do not have any parent window attached to them (unless you use the SetParent API in amoung them). Conversely, any windowed controls you put on each of these forms, say for instance a command button on one of the forms, are also windows either with or without captions (wherever the control exposes a caption property). These controls are windows which are not top level windows.

    As against this, if your application has an MDI form and some children, then all those forms that do not have the MDIChild property set to true are top level windows along with the MDI itself. All those forms that have the MDIChild set to true are not top level windows.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    Both you guys were right. I forgot to set the caption property of the form.

    Thanks again!

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