1:要生成平面工具栏是十分简单的。你只需要在CMainFrame的OnCreate()函数中添
加一句话就可以(必须加在工具栏生成函数之后,因为MFC在生成工具栏时,要清除
其式样)
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{ if(!m_wndToolBar.Create(this)
//!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_wndToolBar.ModifyStyle(0,TBSTYLE_FLAT);}//设置工具栏为平面格式
2:从窗口中删除了极大按钮并设置了初始位置和大小:
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{cs.style = WS_OVERLAPPED | WS_SYSMENU | WS_BORDER;
// Set the position of the window to the upper -left corner.
cs.x =cs. y =0;
//Set the width and height of the window .
cs. cx=GetSystemMetrics (SM_CXSCREEN);
cs. cy=GetSystemMetrics (SM_CYSCREEN) /2;
return CFrameWnd::PreCreateWindow(cs);}
3:用户可以在
代码的任何地方调用Cwnd : :ShowWindow将窗口设置为极大或极小。
BOOL CSampleApp : : InitInstance ( )
{
pMainWnd ->Show Window (SW_SHOWMINMIZED或者SW_SHOWMAXIMIZED);}
4:如何移动窗口
调用CWnd : : SetWindowPos并指定SWP_NOSIZE标志。目的位置与父窗口有关
(顶层窗口与屏幕有关)。调用CWnd : : MoveWindow时必须要指定窗口的大小。
//Move window to positoin 100 , 100 of its parent window .
SetWindowPos (NULL, 100 , 100 , 0 , 0 , SWP_NOSIZE |SWP_NOACTIVATE);
5:如何改变视窗的背景颜色
Windows向窗口发送一个WM_ERASEBKGND消息通知该窗口擦除背景,可以使用
ClassWizard重载该消息的缺省处理程序来擦除背景(实际是画),并返回TRUE以
防止Windows擦除窗口。
BOOL CBoxView::OnEraseBkgnd(CDC* pDC)
{CBrush brush(RGB (128 , 0 , 128) );
// Select the brush into the device context .
CBrush* pOldBrush = pDC->SelectObject (&brush);.
CRect rcClip ;
pDC->GetClipBox (&rcClip);//Paint the area.
pDC-> PatBlt (rcClip.left , rcClip.top ,rcClip.Width() , rcClip.Height()
,PATCOPY );
pDC->SelectObject (pOldBrush );
return TRUE;}