Get Console Window Handle/HWND

This code will get the HWND/handle of a console window (only applicable to console applications).

#include <windows.h>

HWND GetConsoleHandle()
{
	#define BUFFSIZE 768
	HWND hwnd;
	char pszWindowTitle[BUFFSIZE]; 

	GetConsoleTitle(pszWindowTitle, BUFFSIZE);
	int i = strlen(pszWindowTitle);
	_itoa(GetTickCount(), &pszWindowTitle[i], 16);
	_itoa(GetCurrentProcessId(), &pszWindowTitle[strlen(pszWindowTitle)], 16);
	SetConsoleTitle(pszWindowTitle);
	Sleep(50);
	hwnd = FindWindow(NULL, pszWindowTitle);
	pszWindowTitle[i] = 0;
	SetConsoleTitle(pszWindowTitle);
	return(hwnd);
}