首先是考慮全屏處理的時機,是在建立視窗時還是顯示視窗時進行,若是前者,則可以:
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;
}