Win32 SDK中窗口全屏处理

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

None.gif BOOLInitInstance(HINSTANCEhInstance, int nCmdShow)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifHWNDhWnd;
InBlock.gifhInst
=hInstance;//将实例句柄存储在全局变量中
InBlock.gif
UINTwidth=GetSystemMetrics(SM_CXSCREEN);
InBlock.gifUINTheight
=GetSystemMetrics(SM_CYSCREEN);
InBlock.gif
//创建窗口
InBlock.gif
hWnd=CreateWindow(
InBlock.gifszWindowClass,
InBlock.gifszTitle,
InBlock.gifWS_POPUP,
InBlock.gif
0,0,
InBlock.gifwidth,height,
InBlock.gifNULL,NULL,
InBlock.gifhInstance,
InBlock.gifNULL);
InBlock.gif
if(!hWnd)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
returnFALSE;
ExpandedSubBlockEnd.gif}

InBlock.gifShowWindow(hWnd,nCmdShow);
InBlock.gifUpdateWindow(hWnd);
InBlock.gif
returnTRUE;
ExpandedBlockEnd.gif}

None.gif

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

None.gif BOOLInitInstance(HINSTANCEhInstance, int nCmdShow)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifHWNDhWnd;
InBlock.gifhInst
=hInstance;//将实例句柄存储在全局变量中
InBlock.gif
hWnd=CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW,
InBlock.gifCW_USEDEFAULT,
0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
InBlock.gif
if(!hWnd)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
returnFALSE;
ExpandedSubBlockEnd.gif}

InBlock.gifHWNDhDesk;
InBlock.gifRECTrc;
InBlock.gifhDesk
=GetDesktopWindow();
InBlock.gifGetWindowRect(hDesk,
&rc);
InBlock.gifSetWindowLong(hWnd,GWL_STYLE,WS_BORDER);
InBlock.gifSetWindowPos(hWnd,HWND_TOPMOST,
0,0,rc.right,rc.bottom,SWP_SHOWWINDOW);
InBlock.gifShowWindow(hWnd,nCmdShow);
InBlock.gifUpdateWindow(hWnd);
InBlock.gif
returnTRUE;
ExpandedBlockEnd.gif}

None.gif

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

None.gif BOOLInitInstance(HINSTANCEhInstance, int nCmdShow)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gifHWNDhWnd;
InBlock.gifhInst
=hInstance;//将实例句柄存储在全局变量中
InBlock.gif
hWnd=CreateWindow(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW,
InBlock.gifCW_USEDEFAULT,
0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
InBlock.gif
if(!hWnd)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
returnFALSE;
ExpandedSubBlockEnd.gif}

InBlock.gifShowWindow(hWnd,nCmdShow);
InBlock.gifUpdateWindow(hWnd);
InBlock.gif
returnTRUE;
ExpandedBlockEnd.gif}

None.gif

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

None.gif switch (message)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
caseWM_KEYDOWN:
InBlock.gif
switch(wParam)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
caseVK_ESCAPE:
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifHWNDhDesk;
InBlock.gifRECTrc;
InBlock.gifhDesk
=GetDesktopWindow();
InBlock.gifGetWindowRect(hDesk,
&rc);
InBlock.gifSetWindowLong(hWnd,GWL_STYLE,WS_BORDER);
InBlock.gifSetWindowPos(hWnd,HWND_TOPMOST,
0,0,rc.right,rc.bottom,SWP_SHOWWINDOW);
ExpandedSubBlockEnd.gif}

InBlock.gif
break;
ExpandedSubBlockEnd.gif}

InBlock.gif
return0;
ExpandedBlockEnd.gif}

None.gif

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值