471,627 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Closing Window

Hi All,
I want to close a directory which is being opened.what i have is only
the path of the directory.How can i emulate clicking the close button
on this window programmatically.Thanks in Advance.
Rakesh

Jan 3 '06 #1
6 2577
Hi,

What kind of window r u talking about?

If you are refering to an Explorer windows then you would have to check for
the window title , if it does match your dir you can send a process.kill()

For this to work Explorer needs to be configured to display the path in the
title. if you cannot set this apriori then I have no idea how to do it.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"rakesh_nits" <co*********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi All,
I want to close a directory which is being opened.what i have is only
the path of the directory.How can i emulate clicking the close button
on this window programmatically.Thanks in Advance.
Rakesh

Jan 3 '06 #2
Hi Ignacio,
Thanks for your reply.Yes i am talking about Explorer windows.How I can
configure explorer to display path in the title.I need to do it
programmatically.Is it not the default behaviour of explorer.As It
displays the DirecoryName im the title.And while trying to use
process.kill i am getting the following exception.
System.InvalidOperationException ::no process is associated with this
object
..Any Suggestions?Thanks in Advance.

Rakesh

Jan 3 '06 #3
Hi,
"rakesh_nits" <co*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi Ignacio,
Thanks for your reply.Yes i am talking about Explorer windows.How I can
configure explorer to display path in the title.I need to do it
programmatically.Is it not the default behaviour of explorer.As It
displays the DirecoryName im the title.
Frankly I have no idea, it's probably stored in the registry somewhere, do
this , download regmon from sysinternals.com and change this setting in the
windows explorer, see what changes in the registry.
And while trying to use
process.kill i am getting the following exception.
System.InvalidOperationException ::no process is associated with this
object
.Any Suggestions?Thanks in Advance.


Are you trying to kill a valid process? Acording to MSDN you get that
exception when the process has already exited.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 3 '06 #4
Hi Ignacio,
Thanks for replying.My mistake that I hadn't specified the process name
"explorer.exe" in the process.now I am able to get the handle but
process.kill gives the error that the process is already exited.and
closeHandle does not do anything.using getlasterror i am getting the
following error.
ERROR_MOD_NOT_FOUND
126 The specified module could not be found.
here is the code
static int WM_CLOSE = 0x0010;
string path = @"C:\Documents and Settings\rakesh\Desktop\A"
pr.StartInfo.CreateNoWindow = true;
pr.StartInfo.Verb = "Open";
pr.StartInfo.FileName = "explorer.exe";
pr.StartInfo.Arguments = path;
pr.Start();
//pr.Kill();//gives the error the process has already exited
iptr = pr.Handle;
SendMessage(iptr,(uint)WM_CLOSE,0,0);
int errorCode = Marshal.GetLastWin32Error();
Console.WriteLine("errorCode::"+errorCode.ToString ());//gives errorcode
126
**************************************
can you tell me how to change the explorer setting manaully.and what
registrykeys i should watch.because even if i watch only explorer.exe
it gives a lot of keys.Any help will be greatly appreciated.Thanks in
Advance.
Rakesh

Jan 4 '06 #5
Hi,
"rakesh_nits" <co*********@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi Ignacio,
Thanks for replying.My mistake that I hadn't specified the process name
"explorer.exe" in the process.now I am able to get the handle but
process.kill gives the error that the process is already exited.and
closeHandle does not do anything.using getlasterror i am getting the
following error. pr.StartInfo.CreateNoWindow = true;
What is the point in creating an Explorer and not showing it?

//pr.Kill();//gives the error the process has already exited
Well, probably it did, it does depend of how the process interprete your
call.
can you tell me how to change the explorer setting manaully.and what
registrykeys i should watch.because even if i watch only explorer.exe
it gives a lot of keys.Any help will be greatly appreciated.Thanks in
Advance.


Do two things:
1- Create a dummy win app, that all you do is intercept the Close event, and
display a MessageBox or something.
2- Create a new instance of this app and send it the close event,
3- See what happens?
Still do not understand what you are trying to accomplish here though.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 4 '06 #6
Hi Ignacio,
Thanks for all the help.I was able to close the window using EndTask.I
was sending the wrong parameters in the SendMessage that's why it was
not working.
int WM_SYSCOMMAND = 0x0112;
int SC_CLOSE = 0xF060;
SendMessage(hWnd,(uint)WM_SYSCOMMAND,SC_CLOSE,0);
when i used this code it worked fine.thanks again.

Rakesh

Jan 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Derek | last post: by
5 posts views Thread by Ron L | last post: by
1 post views Thread by Chris Bruce | last post: by
3 posts views Thread by Saradhi | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.