Win32 SDK中窗口全屏处理
首先是考虑全屏处理的时机,是在创建窗口时还是显示窗口时进行,若是前者,则可以:
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。
posted on 2008-02-14 21:41 Phinecos(洞庭散人) 阅读(4136) 评论(0) 编辑 收藏 举报