Valhalla Legends Forums Archive | .NET Platform | FindWindowEx failing me.

AuthorMessageTime
laurion
For some reason, FindWindowEx is not working as it should be for me.

If I find the window using Spy++, it shows my parent window as what I'd expect, the .NET created Form1:
[img]http://i32.tinypic.com/2j0gvmd.png[/img]

Therefore, using that same handle with the window open, I would expect a FindWindowEx to return as it should, giving the child window (code made in VB for simplicity; plus, the .NET project had to stay open and running for me to test it)
[code]Debug.Print FindWindowEx(&H308B6, ByVal 0&, "#32770", vbNullString)[/code]

As you can see, I took the window handle right from Spy++, and used the same window class. Spy++ actually shows the window class as "#32770 (Dialog)" but just "#32770" works fine. VB6 returns '0' when I try this, indicating failure (MSDN).

Now. To recap, using FindWindowEx in VB6 using the specified Parent window, shown by Spy++ to be the parent which should therefore make FindWindowEx work as intended, right? Now, it is not an error in my WindowClass, the third variable passed to the FindWindowEx funct, because if I try it like this:
[code]Debug.Print FindWindowEx(ByVal 0&, ByVal 0&, "#32770", vbNullString)[/code]
It returns as expected, showing the hWnd of the window I'm looking for, not '0'. Setting the first parameter, the parent window, to 0 will search all windows instead of only children of the specified parent.

HOWEVER! I cannot rely on setting the parent window variable passed to the FindWindowEx function as null. If I do that, I can't verify that it's the child of my C# program, which is what I'm looking for. On top of that, if I have NOD32 open, using FindWindowEx with a null parent window returns the NOD32 window first, not the C# window I'm looking for.

Now I'm not sure why Spy++ shows the parent window as my .NET window but yet FindWindowEx fails to work properly with it. I need this function to work properly and I will be grateful for any help concerning the matter.

Thanks in advance.

-sorry about any major grammatical errors or if my typing is distracting you from what I'm trying to get across; it's late, I've been staring at this for far too long lol

NOTE: I had the code for FindWindowEx written in .NET but because the window I'm looking for is created by C# in my program it's easier to use an outside app to test. Here's the .NET code, basically the same but not using a constant for the parent window obviously:
[code]
private void tmrDialog_Tick(object sender, EventArgs e)
        {
            IntPtr ret = FindWindowEx(this.Handle, IntPtr.Zero, "#32770 (Dialog)", string.Empty);

            if (ret != IntPtr.Zero)
            {
                this.txt.Text += "dialog present: " + ret.ToString() + "\r\n";
                return;
            }

            this.txt.Text += "dialog NOT present\r\n";

        }
[/code]

June 11, 2008, 2:43 AM
Myndfyr
What's the result from GetLastError() ?
June 11, 2008, 3:09 AM
laurion
[quote author=MyndFyre[vL] link=topic=17518.msg178501#msg178501 date=1213153766]
What's the result from GetLastError() ?
[/quote]
The MSDN article for GetLastError in VB says to use Err.LastDllError instead, and it just returns '0'.

[code]
    Dim lngret As Long
   
    lngret = FindWindowEx(&H308B6, ByVal 0&, "#32770", vbNullString)
   
    If lngret = 0 Then Debug.Print Err.LastDllError[/code]
June 11, 2008, 11:09 AM
laurion
Hey, could a mod move this to General programming, please? It's not really .NET or VB6 specific and I think it would get more attention there. Thanks :) (oh and delete this post, too, when you move it - if you could be so kind 8)) sorry for not posting in the correct place!
June 12, 2008, 3:39 PM

Search