C++ - Getting Active Window Title

#include "stdafx.h"
#include <Windows.h>
#include <string>

using namespace std;

int main()
{
	Sleep(5000);

	POINT ptMouse;
	GetCursorPos(&ptMouse);
	HWND	w = WindowFromPoint(ptMouse);
	TCHAR t[256];
	GetWindowText(w, t, sizeof(t));
	MessageBox(nullptr, t, t, MB_OK);

	TCHAR wnd_title[256];
	HWND hwnd = GetForegroundWindow(); // get handle of currently active window
	GetWindowText(hwnd, wnd_title, sizeof(wnd_title));
	MessageBox(nullptr, wnd_title, wnd_title, MB_OK);

	return 0;
}