• Welcome to Valhalla Legends Archive.
 

FindWindowEx failing me.

Started by Tazo, June 10, 2008, 09:43 PM

Previous topic - Next topic

Tazo

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:


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)
Debug.Print FindWindowEx(&H308B6, ByVal 0&, "#32770", vbNullString)

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:
Debug.Print FindWindowEx(ByVal 0&, ByVal 0&, "#32770", vbNullString)
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:

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";

        }



MyndFyre

What's the result from GetLastError() ?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Tazo

#2
Quote from: MyndFyre[vL] on June 10, 2008, 10:09 PM
What's the result from GetLastError() ?
The MSDN article for GetLastError in VB says to use Err.LastDllError instead, and it just returns '0'.


    Dim lngret As Long
   
    lngret = FindWindowEx(&H308B6, ByVal 0&, "#32770", vbNullString)
   
    If lngret = 0 Then Debug.Print Err.LastDllError

Tazo

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!