When your program is running as a console, press Alt+enter to turn the screen into Full-screen mode. But how do you implement this function in a program using WIN32 API functions? As far as I know, Microsoft has not provided any documentation on this. However, when the user presses Alt+enter, the Windows 9x sends a WM_COMMAND message to the console window with the following special accelerator key ID.
#define Id_switch_consolemode 0xe00f
This accelerator ID is not publicly available, so you can't find anything about id_switch_consolemode in the documentation for the Win32 API.
To convert back and forth between the normal window and Full-screen mode, you can use the SendMessage function as follows.
SendMessage (hwnd,wm_command,id_switch_consolemode,0);
Windows nt/2000 is not the same as the Full-screen mode switch for console programs in Windows 9x. Not universal. In Windows nt/2000, you use two Non-public Win32 API functions to access the console window. These two functions are:
BOOL SetConsoleDisplayMode (
HANDLE hOut, // 标准输出句柄
DWORD dwNewMode, // 指定显示模式
LPDWORD lpdwOldMode, // 用于前一个显示模式值的变量地址
);
BOOL GetConsoleDisplayMode (
LPDWORD lpdwMode, //用于当前显示模式值的变量地址
);
These two functions are exported from the Kernel32.dll, but they are not listed in Kernel32.lib. So we're going to load it dynamically with the GetProcAddress function. The method is as follows:
typedef BOOL (WINAPI *PROCSETCONSOLEDISPLAYMODE)(HANDLE,DWORD,LPDWORD);
typedef BOOL (WINAPI *PROCGETCONSOLEDISPLAYMODE)(LPDWORD);
PROCSETCONSOLEDISPLAYMODE SetConsoleDisplayMode;
PROCGETCONSOLEDISPLAYMODE GetConsoleDisplayMode;
HMODULE hKernel32 = GetModuleHandle("kernel32");
SetConsoleDisplayMode = (PROCSETCONSOLEDISPLAYMODEELLWND)
GetProcAddress(hKernel32,"SetConsoleDisplayMode");
GetConsoleDisplayModeplayMode = (PROCGETCONSOLEDISPLAYMODE)
GetProcAddress(hKernel32,"GetConsoleDisplayMode");
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwOldMode;
SetConsoleDisplayMode(hOut,1,&dwOldMode);