VC修改窗口屬性 GetWindowLong(), SetWindowLong()
VC修改窗口屬性 GetWindowLong(), SetWindowLong() 2015-07-01 19:06 425人閱讀 評論(0) 收藏 舉報(bào)分類:
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
修改窗口屬性
說明:
以下函數(shù)對于POPUP窗口有效,對于子窗口好像不行。
//最小化按鈕有效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) | WS_MINIMIZEBOX ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//最小化按鈕無效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) &~WS_MINIMIZEBOX ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//最大化按鈕有效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) | WS_MAXIMIZEBOX ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//最大化按鈕無效
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE) &~WS_MAXIMIZEBOX ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//關(guān)閉按鈕有效
::EnableMenuItem(::GetSystemMenu(m_hWnd,false),SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
//關(guān)閉按鈕無效
::EnableMenuItem(::GetSystemMenu(m_hWnd,false),SC_CLOSE,MF_BYCOMMAND | MF_ENABLED);
//工具欄窗口。在任務(wù)欄上沒有程序顯示,需要添加在OnInitDialog()里
::SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)?
? &~WS_EX_APPWINDOW|WS_EX_TOOLWINDOW );?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);?
//添加標(biāo)題欄
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)?
? | WS_CAPTION ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//取消標(biāo)題欄
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)?
? & ~WS_CAPTION ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//取消標(biāo)題欄,保留3d邊框,可調(diào)整窗口大小
::SetWindowLong(m_hWnd,GWL_STYLE, GetWindowLong(m_hWnd,GWL_STYLE)?
? & ~WS_CAPTION | WS_THICKFRAME ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); //一定要加這句設(shè)置才會立即生效
//取消標(biāo)題欄和3d邊框,保留一個線條的細(xì)邊框,不能調(diào)整窗口大小
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)?
? & ~WS_CAPTION & ~WS_THICKFRAME | WS_BORDER ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
//如果有WS_EX_DLGMODALFRAME還要取消WS_EX_DLGMODALFRAME
// ::SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)?
// & ~WS_EX_DLGMODALFRAME);?
// ::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);?
//取消所有邊框
::SetWindowLong(m_hWnd,GWL_STYLE,GetWindowLong(m_hWnd,GWL_STYLE)?
? & ~WS_CAPTION & ~WS_THICKFRAME ); ?
::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED);?
// //如果有WS_EX_DLGMODALFRAME還要取消WS_EX_DLGMODALFRAME
// ::SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)?
// & ~WS_EX_DLGMODALFRAME);?
// ::SetWindowPos(m_hWnd,NULL,0,0,0,0,SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE);?
VC++6.0 如何去掉MFC向?qū)傻腟DI程序中視圖邊框的3D效果2010-03-24 17:48先要去掉view的邊框,代碼如下:?
BOOL CSDIView::PreCreateWindow(CREATESTRUCT& cs)?
{?
cs.style &=~WS_BORDER;//加入的代碼?
return CFormView::PreCreateWindow(cs);?
}?
然后在去掉外部Frame的客戶區(qū)邊框,代碼如下:?
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)?
{?
if( !CFrameWnd::PreCreateWindow(cs) )?
return FALSE;?
cs.dwExStyle&=~WS_EX_CLIENTEDGE;//加入的代碼,一定要在CFrameWnd::PreCreateWindow(cs)之后執(zhí)行?
return TRUE;?
}
MFC窗體去邊框、置頂、全屏、激活
2015-07-04 11:52
400人閱讀 評論(0)
收藏
舉報(bào)分類:
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
靜態(tài)移除長提邊框很簡單,直接設(shè)置“Border”屬性為"none"即可
"Maximize Box", “Minimize Box” 設(shè)置是否顯示 最大化/最小化按鈕;
“System Menu” 設(shè)置 是否顯示 關(guān)閉按鈕;
1. 代碼中動態(tài)移除窗體邊框的方法
[cpp]
view plain
copy
DWORD?dwStyle?=?GetStyle();?//等價于GetWindowLong(m_hWnd,?GWL_STYLE);??DWORD?dwNewStyle?=?WS_SYSMENU?|?WS_MINIMIZEBOX?|?WS_MAXIMIZEBOX?|?WS_CLIPCHILDREN?|?WS_CLIPSIBLINGS;??dwNewStyle?&=?~dwStyle;??SetWindowLong(m_hWnd,?GWL_STYLE,?dwNewStyle);??
或者
[cpp]
view plain
copy
LONG?nStyle?=?GetWindowLong(m_hWnd,?GWL_STYLE);??LONG?newStyle?=?nStyle?&?(~(WS_CAPTION?|?WS_BORDER?|?WS_THICKFRAME));??//移除屬性?WS_EX_CLIENTEDGE??SetWindowLong(m_hWnd,?GWL_STYLE,?newStyle);??::SetWindowPos(m_hWnd,?NULL,?0,?0,?0,?0,?SWP_NOMOVE?|?SWP_NOSIZE?|?SWP_FRAMECHANGED);??//SWP_FRAMECHANGED確保立即生效??
2. 設(shè)置窗體為最底層窗體的方法
[cpp]
view plain
copy
SetWindowPos(&wndBottom,?0,?0,?0,?0,?SWP_NOSIZE?|?SWP_NOMOVE?|?SWP_NOACTIVATE);??或者??::SetWindowPos(GetSafeHwnd(),?HWND_TOPMOST,?0,?0,?0,?0,?SWP_NOSIZE?|?SWP_NOMOVE?|?SWP_NOACTIVATE);??
3. 設(shè)置窗體為最頂層窗體的辦法
[cpp]
view plain
copy
SetWindowPos(&wndTopMost,?0,?0,?0,?0,?SWP_NOSIZE?|?SWP_NOMOVE?|?SWP_NOACTIVATE);??或者??::SetWindowPos(GetSafeHwnd(),?HWND_TOPMOST,?0,?0,?0,?0,?SWP_NOSIZE?|?SWP_NOMOVE?|?SWP_NOACTIVATE);??
備注(1):?
wndBottom和?wndTopMost為基類CWnd的靜態(tài)成員,定義如下:
[cpp] view plain copy static?AFX_DATA?const?CWnd?wndTop;???????//?SetWindowPos's?pWndInsertAfter??static?AFX_DATA?const?CWnd?wndBottom;????//?SetWindowPos's?pWndInsertAfter??static?AFX_DATA?const?CWnd?wndTopMost;???//?SetWindowPos?pWndInsertAfter??static?AFX_DATA?const?CWnd?wndNoTopMost;?//?SetWindowPos?pWndInsertAfter??
備注(2):
[cpp]
view plain
copy
SWP_DRAWFRAME???????圍繞窗口畫一個框???SWP_FRAMECHANGED????發(fā)送一條WM_NCCALCSIZE消息進(jìn)入窗口,即使窗口的大小沒有發(fā)生改變.如果不指定這個參數(shù),消息WM_NCCALCSIZE只有在窗口大小發(fā)生改變時才發(fā)送???SWP_HIDEWINDOW??????隱藏窗口???SWP_SHOWWINDOW??????顯示窗口???SWP_NOREDRAW????????窗口不自動重畫???SWP_NOACTIVATE??????不激活窗口(避免搶焦點(diǎn))??SWP_NOCOPYBITS??????屏蔽客戶區(qū)域???SWP_NOMOVE??????????保持當(dāng)前位置(X和Y參數(shù)將被忽略)??SWP_NOSIZE??????????保持當(dāng)前大?。╟x和cy參數(shù)會被忽略)????SWP_NOZORDER????????保持窗口在列表的當(dāng)前位置(hWndInsertAfter參數(shù)將被忽略)???SWP_NOOWNERZORDER???不改變所有窗口的位置和排列順序???SWP_NOREPOSITION????與SWP_NOOWNERZORDER標(biāo)記相同???SWP_NOSENDCHANGING??防止這個窗口接受WM_WINDOWPOSCHANGING消息???
4. 設(shè)置窗體全屏顯示
[cpp]
view plain
copy
int?cxScreen,cyScreen;???cxScreen=GetSystemMetrics(SM_CXSCREEN);??cyScreen=GetSystemMetrics(SM_CYSCREEN);??SetWindowPos(&wndTopMost,0,0,cxScreen,cyScreen,SWP_SHOWWINDOW);?