Click to See Complete Forum and Search --> : Help with code - close a window
ChrisEffinSmith
August 12th, 2008, 02:50 PM
I'm pretty new to C# so this may be something ultra simple that I'm just missing. I'm trying to write a very basic script that will simply close another application's window (if present). Despite how easy it sounds, I'm having no luck finding anything on msdn or google to even point me in the right direction. Anyone?
Talikag
August 12th, 2008, 03:00 PM
What to you know about the application's window you want to close? Is it the only window of that application? If not, how do you recognize it?
Basiclly what you need to do is to send a WM_CLOSE, WM_QUIT or WM_DESTROY messages to that window, but again, you need to know some stuff about that window before.
ChrisEffinSmith
August 13th, 2008, 07:59 AM
We have a VBscript that constantly crashes out and dumps to a com+ debug window. The script itself will restart, but only after the debug window has been closed. I started learning C# so that I could eventually replace the sub-par script, but for a "starter project" I though I would just have a script that closes the window when it comes up (or have it on a timer to just occasional clear the window if it's up - avoiding the need for "detection" code).
darwen
August 13th, 2008, 09:14 AM
How about fixing the VBScript so that it doesn't crash ? Seems like you're treating the symptoms and not the cause. If your car engine won't start, you don't go out and buy another car to tow it do you ? You fix the engine.
Darwen.
ChrisEffinSmith
August 13th, 2008, 10:14 AM
Yeah. Thanks for that. Maybe read past the first line and a half. If you still don't understand/agree, then don't reply. To use your analogy: if my car doesn't start because it has a bad ignition switch, I'll replace the ignition switch with anything I have around that will work, until I'm capable of replacing it properly. Or would you suggest I stay stranded on a deserted road until I fix my car properly?
messycan
August 13th, 2008, 03:16 PM
I'm pretty new to C# so this may be something ultra simple that I'm just missing. I'm trying to write a very basic script that will simply close another application's window (if present). Despite how easy it sounds, I'm having no luck finding anything on msdn or google to even point me in the right direction. Anyone?
You can import WIN32 functions over. You will need these two:
FindWindow & DestroyWindow
IntPtr hWnd = FindWindow(string ClassName, string WindowName);
DestroyWindow(hWnd); // You can use PostMessage and WM_CLOSE, or ShowWindow...look in MSDN.
You can find the class name by using Spy++, which is included with Visual Studio. WindowName is just the string of the window caption...
http://msdn.microsoft.com/en-us/library/ms633499.aspx
Example on how to use it in C#: http://bytes.com/forum/thread267595.html
Enjoy ;)
ChrisEffinSmith
August 13th, 2008, 03:19 PM
Many thanks!
messycan
August 13th, 2008, 03:25 PM
Many thanks!
No problem!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.