Here's a little more robust version:
Code:
// Simulate ALT-ENTER keystrokes
void AltEnter()
{
// NOTE: This method only works if the console window has the keyboard
// focus and the user isn't hitting keys on the keyboard.
SetForegroundWindow(GetConsoleWindow());
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0);
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
}//AltEnter
If you're running on an NT based verison of Windows, here is the best way to do it:
Code:
/*-----------------------------------------------------------------------------
NT_SetConsoleDisplayMode - Set the console display to fullscreen or windowed.
Parameters:
hOutputHandle - Output handle of cosole, usually
"GetStdHandle(STD_OUTPUT_HANDLE)"
dwNewMode - 0=windowed, 1=fullscreen
Returns Values:
TRUE if successful, otherwise FALSE is returned. Call GetLastError() for
extened information.
Remarks:
This only works on NT based versions of Windows.
If dwNewMode is anything other than 0 or 1, FALSE is returned and
GetLastError() returns ERROR_INVALID_PARAMETER.
If dwNewMode specfies the current mode, FALSE is returned and
GetLastError() returns ERROR_INVALID_PARAMETER. Use the (documented)
function GetConsoleDisplayMode() to determine the current display mode.
-----------------------------------------------------------------------------*/
BOOL NT_SetConsoleDisplayMode(HANDLE hOutputHandle, DWORD dwNewMode)
{
typedef BOOL (WINAPI *SCDMProc_t) (HANDLE, DWORD, LPDWORD);
SCDMProc_t SetConsoleDisplayMode;
HMODULE hKernel32;
BOOL bFreeLib = FALSE, ret;
const char KERNEL32_NAME[] = "kernel32.dll";
hKernel32 = GetModuleHandleA(KERNEL32_NAME);
if (hKernel32 == NULL)
{
hKernel32 = LoadLibraryA(KERNEL32_NAME);
if (hKernel32 == NULL)
return FALSE;
bFreeLib = true;
}//if
SetConsoleDisplayMode =
(SCDMProc_t)GetProcAddress(hKernel32, "SetConsoleDisplayMode");
if (SetConsoleDisplayMode == NULL)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
ret = FALSE;
}//if
else
{
DWORD dummy;
ret = SetConsoleDisplayMode(hOutputHandle, dwNewMode, &dummy);
}//else
if (bFreeLib)
FreeLibrary(hKernel32);
return ret;
}//NT_SetConsoleDisplayMode
adrianxw is more than welcome to clean this up and use it in his tutorials
gg