Destroy window

I'm trying to destroy a window no questions asked it runs without errors or warnings, and finds the window but won't destroy it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <windows.h>


using namespace std;


int main()
{
	
	

HWND hMovie;
hMovie = FindWindow(NULL,"movies - notepad");
if(hMovie)
{
cout <<  "Window found!";
}
else cout << "Window not found";





DestroyWindow(hMovie);

system("PAUSE");
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
#include <windows.h>

int main()
{
	if (HWND hWnd = FindWindow(NULL, L"Untitled - Notepad"))
	{
		SendMessage(hWnd, WM_CLOSE, 0, 0);
	}

	return 0;
}
That works great I had to remove the 'L' in findwindow though.

So why didn't my DestroyWindow work?
closed account (N36fSL3A)
As far as I know, it's because you don't actually own the window, the program does. kbw corrects your code by sending the notepad process a WM_CLOSE message, letting the program know that something (usually the OS) would like it to close.
Topic archived. No new replies allowed.