1

I would like to close notepad file without prompting "Would you like to save changes" dialog box. I tried:

SendMessage(handle, 0x0010, IntPtr.Zero, IntPtr.Zero);

But asks me whether I'd like to save changes or not. Also DestroyWindow(HWND) doesn't work.

How to overcome this problem?

Thanks a lot...

Mesut
  • 1,845
  • 4
  • 24
  • 32
  • What are you attempting to achieve in doing this? (i.e why do you need to use notepad and not a control within your own program etc) – Sayse Sep 11 '14 at 06:23
  • @Sayse It seems he's controlling a Notepad process/window from his own process. – mostruash Sep 11 '14 at 06:28
  • @Mesut btw you should use constants instead of explicit values like `0x0010` if you want your question to be answered. It's too much hassle to look for what constants they actually refer to. – mostruash Sep 11 '14 at 06:30
  • http://stackoverflow.com/questions/2237628/c-sharp-process-killing just replace the process name with notepad process name – Yogseh pathak Sep 11 '14 at 06:50

2 Answers2

1

If you don't care about the data on notepad then simply kill its process.

[DllImport("user32.dll", SetLastError=true)]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);

Now kill the process using its process id

Process p = Process.GetProcessById(processId);
p.Kill();
prem
  • 3,348
  • 1
  • 25
  • 57
0

Just to add to the answer posted by @prem, there is absolutely no need for using APIs. .NET already includes everything to do this like in the example below.

var processes = Process.GetProcessesByName("notepad");
foreach (var process in processes)
    process.Kill();
Mo Patel
  • 2,321
  • 4
  • 22
  • 37