http://www.cnblogs.com/phinecos/archive/2008/02/14/1069117.html
首先是考虑全屏处理的时机,是在创建窗口时还是显示窗口时进行,若是前者,则可以:
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://zhidao.baidu.com/link?url=TucQ6ISLNXUgOA3dvDX9GE9VG-RO31F8vq9lQQQqdB6v_EqpDXLqsykd612_6cHg6Vk-CYBFdnxgbLZlFj0JNq
给你完整的代码吧。这应该是你想要的。 //请用alt+f4关闭该窗口,以下代码可运行于vc6至vc9(vs2008)版本 #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("HelloWin") ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName= szAppName ; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow( szAppName, // window class name TEXT ("Full Screen Display"), // window caption // WS_OVERLAPPEDWINDOW, // window style WS_POPUP, // CW_USEDEFAULT,// initial x position // CW_USEDEFAULT,// initial y position // CW_USEDEFAULT,// initial x size // CW_USEDEFAULT,// initial y size 0, 0, ::GetSystemMetrics(SM_CXSCREEN), ::GetSystemMetrics(SM_CYSCREEN), NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_CREATE: // PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("This window can cover the task item!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
-
提问者评价
-
谢谢