Win32api设置窗口全屏的方法

桃扇骨 2022-08-06 07:12 339阅读 0赞

首先是考虑全屏处理的时机,是在创建窗口时还是显示窗口时进行,若是前者,则可以:

None.gifBOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ExpandedBlockStart.gif {
InBlock.gif HWND hWnd;
InBlock.gif hInst = hInstance; // 将实例句柄存储在全局变量中
InBlock.gif UINT width = GetSystemMetrics(SM_CXSCREEN);
InBlock.gif UINT height = GetSystemMetrics(SM_CYSCREEN);
InBlock.gif //创建窗口
InBlock.gif hWnd=CreateWindow(
InBlock.gif szWindowClass,
InBlock.gif szTitle,
InBlock.gif WS_POPUP,
InBlock.gif 0,0,
InBlock.gif width,height,
InBlock.gif NULL,NULL,
InBlock.gif hInstance,
InBlock.gif NULL);
InBlock.gif if (!hWnd)
ExpandedSubBlockStart.gif {
InBlock.gif return FALSE;
ExpandedSubBlockEnd.gif }
InBlock.gif ShowWindow(hWnd, nCmdShow);
InBlock.gif UpdateWindow(hWnd);
InBlock.gif return TRUE;
ExpandedBlockEnd.gif}
None.gif

若是在显示窗口时进行处理:

None.gifBOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ExpandedBlockStart.gif {
InBlock.gif HWND hWnd;
InBlock.gif hInst = hInstance; // 将实例句柄存储在全局变量中
InBlock.gif hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
InBlock.gif CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
InBlock.gif if (!hWnd)
ExpandedSubBlockStart.gif {
InBlock.gif return FALSE;
ExpandedSubBlockEnd.gif }
InBlock.gif HWND hDesk;
InBlock.gif RECT rc;
InBlock.gif hDesk = GetDesktopWindow();
InBlock.gif GetWindowRect( hDesk, &rc );
InBlock.gif SetWindowLong( hWnd, GWL_STYLE, WS_BORDER );
InBlock.gif SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, rc.right, rc.bottom, SWP_SHOWWINDOW);
InBlock.gif ShowWindow(hWnd, nCmdShow);
InBlock.gif UpdateWindow(hWnd);
InBlock.gif return TRUE;
ExpandedBlockEnd.gif}
None.gif

也可以让用户控制全屏的时机,比如按下”ESC“键后进入全屏

None.gifBOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ExpandedBlockStart.gif {
InBlock.gif HWND hWnd;
InBlock.gif hInst = hInstance; // 将实例句柄存储在全局变量中
InBlock.gif hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
InBlock.gif CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
InBlock.gif if (!hWnd)
ExpandedSubBlockStart.gif {
InBlock.gif return FALSE;
ExpandedSubBlockEnd.gif }
InBlock.gif ShowWindow(hWnd, nCmdShow);
InBlock.gif UpdateWindow(hWnd);
InBlock.gif return TRUE;
ExpandedBlockEnd.gif}
None.gif

在窗口处理函数中对ESC键进行处理:

None.gif switch (message)
ExpandedBlockStart.gif {
InBlock.gifcase WM_KEYDOWN:
InBlock.gif switch(wParam)
ExpandedSubBlockStart.gif {
InBlock.gif case VK_ESCAPE:
ExpandedSubBlockStart.gif {
InBlock.gif HWND hDesk;
InBlock.gif RECT rc;
InBlock.gif hDesk = GetDesktopWindow();
InBlock.gif GetWindowRect( hDesk, &rc );
InBlock.gif SetWindowLong( hWnd, GWL_STYLE, WS_BORDER );
InBlock.gif SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, rc.right, rc.bottom, SWP_SHOWWINDOW);
ExpandedSubBlockEnd.gif }
InBlock.gif break;
ExpandedSubBlockEnd.gif }
InBlock.gifreturn 0;
ExpandedBlockEnd.gif}
None.gif

作者:洞庭散人

出处:http://phinecos.cnblogs.com/    

本博客遵从 Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。

发表评论

表情:
评论列表 (有 0 条评论,339人围观)

还没有评论,来说两句吧...

相关阅读