Win32API How to set a full screen for a window

Source: Internet
Author: User
Tags bool

The first is to consider the timing of full-screen processing, whether you are creating a window or displaying a window, and if the former, you can:

BOOL InitInstance (hinstance hinstance, int ncmdshow)

{

HWND hwnd;

Hinst = hinstance; To store an instance handle in a global variable

UINT width = getsystemmetrics (sm_cxscreen);

UINT height = getsystemmetrics (sm_cyscreen);

Create a window

Hwnd=createwindow (

Szwindowclass,

SzTitle,

Ws_popup,

0,0,

Width,height,

Null,null,

HINSTANCE,

NULL);

if (!hwnd)

{

return FALSE;

}

ShowWindow (HWnd, ncmdshow);

UpdateWindow (HWND);

return TRUE;

}

If you are working on the display window:

BOOL InitInstance (hinstance hinstance, int ncmdshow)

{

HWND hwnd;

Hinst = hinstance; To store an instance handle in a global variable

HWnd = CreateWindow (Szwindowclass, SzTitle, Ws_overlappedwindow,

Cw_usedefault, 0, cw_usedefault, 0, NULL, NULL, HINSTANCE, NULL);

if (!hwnd)

{

return FALSE;

}

HWND Hdesk;

RECT RC;

Hdesk = GetDesktopWindow ();

GetWindowRect (Hdesk, &RC);

SetWindowLong (HWnd, Gwl_style, Ws_border);

SetWindowPos (hWnd, hwnd_topmost, 0, 0, rc.right, Rc.bottom, Swp_showwindow);

ShowWindow (HWnd, ncmdshow);

UpdateWindow (HWND);

return TRUE;

}

You can also allow users to control the full screen time, such as press the "ESC" key to enter the full screen

BOOL InitInstance (hinstance hinstance, int ncmdshow)

{

HWND hwnd;

Hinst = hinstance; To store an instance handle in a global variable

HWnd = CreateWindow (Szwindowclass, SzTitle, Ws_overlappedwindow,

Cw_usedefault, 0, cw_usedefault, 0, NULL, NULL, HINSTANCE, NULL);

if (!hwnd)

{

return FALSE;

}

ShowWindow (HWnd, ncmdshow);

UpdateWindow (HWND)

return TRUE;

}

To handle the ESC key in a window-handling function:

Switch (message)

{

Case WM_KEYDOWN:

Switch (WParam)

{

Case Vk_escape:

{

HWND Hdesk;

RECT RC;

Hdesk = GetDesktopWindow ();

GetWindowRect (Hdesk, &RC);

SetWindowLong (HWnd, Gwl_style, Ws_border);

SetWindowPos (hWnd, hwnd_topmost, 0, 0, rc.right, Rc.bottom, Swp_showwindow);

}

Break

}

return 0;

}

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.