• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

Enumerate Child Windows (Not MDI children)

HI,
I'm creating an application that automatically logs into an exchange web interface.
To close the pop up that asks for a password (with sendkeys)
I would like to enumerate the child windows (not MDI-children) of my form and close them.

how can I do this?
0
theonlyfreaky
Asked:
theonlyfreaky
  • 5
  • 3
  • 2
  • +1
1 Solution
 
RonaldBiemansCommented:
isn't it just me.ownedforms
0
 
theonlyfreakyAuthor Commented:
sadly enough, the solution won't be that easy

me.ownedforms.lengt = 0 even when there is a modal security warning displayed

I used winspector to spy my app and the highlighted window is the one I want to address: http://users.pandora.be/theonlyfreaky/window.jpg

I think I will need to use some API, but I can't figure out how to use EnumChildWindows
and it's not really the .net way.
0
 
wguerramCommented:
Here is an example

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21192664.html

I don't see a reason for not using APIs in .NET, i think Microsft used them too.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
theonlyfreakyAuthor Commented:
Thx, I'm a step closer now
I can list all the windows that are currently in use.
I can even find the security warning one
but,
I don't find a way of checking that it definitely is the one
that my web browser created,
I don't want to interfere with the normal browsing

PS: tried EnumChildWindows but with the handle of my form and the handle of the web browser control but they returned no childwindows.
0
 
grayeCommented:
Is there anything in the Title bar of the window?   If so, you can find it by that... (in fact, that's the normal way of finding a window... using the FindWindow API)

0
 
theonlyfreakyAuthor Commented:
there is: "Security Warning" but,
there can be other security warnings then the one's created by my app
0
 
grayeCommented:
Well, if you're in control of the Title Bar of the application... then that's an obvious solution.   Just make the text in the title bar unique.

But I supose you've probably already thought of that... so there must have been a reason that you didn't go that route.

Another technique would be to get the Class names/Text from all of the controls, menus, etc.

Here is an example (in C++, but hey, the concepts are the same)

#include <windows.h>

int CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
      char buf[256];

      GetClassName(hwndChild, buf, 255);
      if (!strcmp(buf, "TButton")) {
            GetWindowText(hwndChild, buf, 255);
            if (!strcmp(buf, "Exit")) {
                  EnableWindow(hwndChild, false);
                  return 0;
            }
      }
      return 1;
}

int main(int argc, char* argv[])
{
      HWND h;
      HMENU sm;
      int i, c;
      char buf[256];

      // get the handle to the window
      h = FindWindow(NULL, "SatSked32  Version 4.04 4/17/02");
      if (h == NULL)
            return 1;

      // get handle to the System Menu
      sm = GetSystemMenu(h, false);

      // how many items are there?
      c = GetMenuItemCount(sm);

      for (i=0; i<c; i++) {
            // pull the strings, one at a time
            GetMenuString(sm, i, buf, 255, MF_BYPOSITION);
            // if found, remove that menu item
            if (!strncmp(buf, "&Close", 6)) {
                  EnableMenuItem(sm, i, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
                  DrawMenuBar(h);
            }
      }

      // find and whack the Exit button
      EnumChildWindows(h, EnumChildProc, (LPARAM) NULL);
      return 0;
}
0
 
theonlyfreakyAuthor Commented:
I'm not really in control of the title bar (if I was I would be in control of the whole form :))
"Class names/Text from all of the controls" would give the same results for different windows of the same type I presume.

These are the windows that need to be closed:

http://users.pandora.be/theonlyfreaky/warning.jpg
http://users.pandora.be/theonlyfreaky/login.jpg

so I need to know if they are executed from my web browser control.

according to winspector (http://users.pandora.be/theonlyfreaky/window.jpg) there is a relationship, but I can't find it.



0
 
wguerramCommented:
Maybe you can use the processid. to see if are the forms you created.
0
 
theonlyfreakyAuthor Commented:
That's it!

by comparing the GetWindowThreadProcessId of all windows with my window, I can be sure it's created by my app

now, let's send some key's :D

thx!!!!
0
 
wguerramCommented:
You're welcome!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now