Win32api怎么设置窗口全屏
发布网友
发布时间:2022-09-19 20:47
我来回答
共1个回答
热心网友
时间:2023-10-31 01:40
首先是考虑全屏处理的`时机,是在创建窗口时还是显示窗口时进行,若是前者,则可以:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // 将实例句柄存储在全局变量中
UINT width = GetSystemMetrics(SM_CXSCREEN);
UINT height = GetSystemMetrics(SM_CYSCREEN);
//创建窗口
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;
}
若是在显示窗口时进行处理:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // 将实例句柄存储在全局变量中
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;
}
也可以让用户控制全屏的时机,比如按下”ESC“键后进入全屏
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // 将实例句柄存储在全局变量中
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;
}
在窗口处理函数中对ESC键进行处理:
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;
}