Full-screen mode switch for console programs in Windows

Source: Internet
Author: User
Tags bool documentation win32

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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.