VC修改窗口屬性 GetWindowLong(), SetWindowLong()
修改窗口屬性
說明:
以下函數對於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);
//關閉按鈕有效
::EnableMenuItem(::GetSystemMenu(m_hWnd,false),SC_CLOSE,MF_BYCOMMAND | MF_GRAYED);
//關閉按鈕無效
::EnableMenuItem(::GetSystemMenu(m_hWnd,false),SC_CLOSE,MF_BYCOMMAND | MF_ENABLED);
//工具欄窗口。在任務欄上沒有程序顯示,需要添加在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);
//添加標題欄
::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);
//取消標題欄
::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);
//取消標題欄,保留3d邊框,可調整窗口大小
::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); //一定要加這句設置才會立即生效
//取消標題欄和3d邊框,保留一個線條的細邊框,不能調整窗口大小
::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向導生成的SDI程序中視圖邊框的3D效果2010-03-24 17:48先要去掉view的邊框,代碼如下:
BOOL CSDIView::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &=~WS_BORDER;//加入的代碼
return CFormView::PreCreateWindow(cs);
}
然後在去掉外部Frame的客戶區邊框,代碼如下:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.dwExStyle&=~WS_EX_CLIENTEDGE;//加入的代碼,一定要在CFrameWnd::PreCreateWindow(cs)之後執行
return TRUE;
}