FullScreen

1: 用于隐藏、显示任务栏、开始菜单、输入面板,BOOL SHFullScreen( HWND hwndRequester,  DWORD dwState) 

 

 MSDN里的参考代码: 

 

#include <aygshell.h>

LRESULT CALLBACK SHFullScreenWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

    static fFullScreen = FALSE;

    switch (message)

    {

        case WM_KEYDOWN:

        {

            // Toggle between full screen and normal mode when the user presses the space bar.

            if (VK_SPACE == wParam)

            {

                DWORD dwState;

                RECT rc;

                if (fFullScreen)

                {

                    // To switch to normal mode, first show all of the shell parts.

                    dwState = (SHFS_SHOWTASKBAR | SHFS_SHOWSTARTICON | SHFS_SHOWSIPBUTTON);

                    SHFullScreen(hwnd, dwState);

                    // Next resize the main window to the size of the work area.

                    SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE);

                    MoveWindow(hwnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);

                    fFullScreen = !fFullScreen;

                }

                else

                {

                    // To switch to full screen mode, first hide all of the shell parts.

                    dwState = (SHFS_HIDETASKBAR | SHFS_HIDESTARTICON | SHFS_HIDESIPBUTTON);

                    SHFullScreen(hwnd, dwState);

                    // Next resize the main window to the size of the screen.

                    SetRect(&rc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));

                    MoveWindow(hwnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);

                    fFullScreen = !fFullScreen;

                }

            }

        }

        break;

    }

    return DefWindowProc(hwnd, message, wParam, lParam);

}

 

 

2:获取桌面分辨率,下面2种方法都可以

a:SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE)

b:GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)

 

 

3:重置窗口,BOOL MoveWindow( HWND hWnd, int X, int Y, int nWidth, int nHeight, BOOL bRepaint );

 

#include <windows.h>    

#include <aygshell.h>

 

LRESULT CALLBACK MainWndProc (HWND, UINT, WPARAM, LPARAM);

 

 

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

                    LPWSTR lpCmdLine, int nCmdShow) {

    WNDCLASS wc;

    HWND hWnd;

    MSG msg;

 

    // Register application main window class.

    wc.style = 0;                             // Window style

    wc.lpfnWndProc = MainWndProc;             // Callback function

    wc.cbClsExtra = 0;                        // Extra class data

    wc.cbWndExtra = 0;                        // Extra window data

    wc.hInstance = hInstance;                 // Owner handle

    wc.hIcon = NULL,                          // Application icon

    wc.hCursor = LoadCursor (NULL, IDC_ARROW);// Default cursor

    wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

    wc.lpszMenuName =  NULL;                  // Menu name

    wc.lpszClassName = TEXT("MyClass");       // Window class name

 

    if (RegisterClass (&wc) == 0) return -1;

 

    // Create main window.

    hWnd = CreateWindowEx(WS_EX_NODRAG, // Ex style flags

                          TEXT("MyClass"),    // Window class

                          TEXT("Hello"),      // Window title

                          // Style flags

                          //WS_VISIBLE | WS_CAPTION | WS_SYSMENU,

                              WS_VISIBLE,

                          CW_USEDEFAULT,      // x position

                          CW_USEDEFAULT,      // y position

                          CW_USEDEFAULT,      // Initial width

                          CW_USEDEFAULT,      // Initial height

                          NULL,               // Parent

                          NULL,               // Menu, must be null

                          hInstance,          // Application instance

                          NULL);              // Pointer to create

                                              // parameters

    if (!IsWindow (hWnd)) return -2;  // Fail code if not created.

 

    // Standard show and update calls

    ShowWindow (hWnd, nCmdShow);

    UpdateWindow (hWnd);

 

    // Application message loop

    while (GetMessage (&msg, NULL, 0, 0)) {

        TranslateMessage (&msg);

        DispatchMessage (&msg);

    }

    // Instance cleanup

    return msg.wParam;

}

 

 

LRESULT CALLBACK MainWndProc (HWND hWnd, UINT wMsg, WPARAM wParam,

                              LPARAM lParam) {

    PAINTSTRUCT ps;

    RECT rect;

    HDC hdc;

     RECT rc;

 

    switch (wMsg) {

    case WM_PAINT:

        // Get the size of the client rectangle

        GetClientRect (hWnd, &rect);

 

        hdc = BeginPaint (hWnd, &ps);

        DrawText (hdc, TEXT ("Hello World!"), -1, &rect,

                  DT_CENTER | DT_VCENTER | DT_SINGLELINE);

 

        EndPaint (hWnd, &ps);

        

         SHFullScreen(hWnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);

 

         //效果1

//       SetRect(&rc, 0, 0, GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));   

//       MoveWindow( hWnd,rc.left, rc.top,rc.right, rc.bottom,FALSE);

 

         //效果2

         SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, FALSE);

        MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, TRUE);     

 

        return 0;

 

    case WM_DESTROY:

        PostQuitMessage (0);

        break;

    }

    return DefWindowProc (hWnd, wMsg, wParam, lParam);

}

 

 

效果1:

 

 

效果2:

 

 

 

具体可以参考SDK Samples:/Common/CPP/Win32/FullScreen

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值