Closing dialogs C#

Hi guys,

Im writing a management application for Windows 2k+. I am trying to listen to any new window created and check the title or class if the Window and if it's in my regularly updated XML File close the window.

So for example I may have "Registry Editor" or "Command Prompt", "Internet Explorer Options" in my XML File I want my application to, whenever a new application or window from within an application is opened check against the xml file and close the application.

I just need the Win32 API commands really I have looked into the

FindWindow andSendMessage API in user32.DLL but i'm using a timer which is the wrong way of doing things to look for windows.Does anybody know any events that my application can handle when a new dialog is created?

Thanks,

Rob Heeley

[996 byte] By [rahsoftware] at [2007-12-25]
# 1

Hi Rob,

I haven't tried it, but this article seems to explain what you're looking for.

http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/

Mike

MikeHildner at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2

Check out the following sample if it could work.

You need to specify the window's class name and window's caption. All these information can get from spy++.

also, you can call this function in a timer's Tick event.

void MyFunction(string lpClassName, string lpWindowName) {
IntPtr hWnd;

hWnd = FindWindow(lpClassName, lpWindowName);
if (!hWnd.Equals(IntPtr.Zero)) {
SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}

gqlu at 2007-9-3 > top of Msdn Tech,Windows Forms,Windows Forms General...