📄 wndcontrolview.cpp
字号:
// WndControlView.cpp : implementation of the CWndControlView class
//
#include "stdafx.h"
#include "WndControl.h"
#include "WndControlDoc.h"
#include "WndControlView.h"
#include "HotSnapDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWndControlView
IMPLEMENT_DYNCREATE(CWndControlView, CView)
BEGIN_MESSAGE_MAP(CWndControlView, CView)
//{{AFX_MSG_MAP(CWndControlView)
ON_COMMAND(ID_WNDCONTROL_ICON, OnWndcontrolIcon)
ON_COMMAND(ID_WNDCONTROL_CAPTION, OnWndcontrolCaption)
ON_WM_ERASEBKGND()
ON_COMMAND(ID_WNDCONTROL_BKCLR, OnWndcontrolBkclr)
ON_COMMAND(ID_WNDCONTROL_TOP, OnWndcontrolTop)
ON_COMMAND(ID_WNDCONTROL_MOVE, OnWndcontrolMove)
ON_WM_LBUTTONDOWN()
ON_COMMAND(ID_WNDCONTROL_CHILDICON, OnWndcontrolChildicon)
ON_UPDATE_COMMAND_UI(ID_WNDCONTROL_TOP, OnUpdateWndcontrolTop)
ON_COMMAND(ID_WNDCONTROL_HOTSNAP, OnWndcontrolHotsnap)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWndControlView construction/destruction
CWndControlView::CWndControlView()
{
m_rgbBack = RGB(128 , 0 , 128);
m_bMoveOnView = FALSE;
m_bTopMost = FALSE;
}
CWndControlView::~CWndControlView()
{
}
BOOL CWndControlView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWndControlView drawing
void CWndControlView::OnDraw(CDC* pDC)
{
CWndControlDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CWndControlView printing
BOOL CWndControlView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWndControlView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWndControlView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CWndControlView diagnostics
#ifdef _DEBUG
void CWndControlView::AssertValid() const
{
CView::AssertValid();
}
void CWndControlView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWndControlDoc* CWndControlView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWndControlDoc)));
return (CWndControlDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWndControlView message handlers
void CWndControlView::OnWndcontrolIcon()
{
HICON hIcon=AfxGetApp() ->LoadIcon(IDI_ICON);
ASSERT(hIcon);
AfxGetMainWnd() ->SendMessage(WM_SETICON ,TRUE,(LPARAM)hIcon);
}
void CWndControlView::OnWndcontrolCaption()
{
AfxGetMainWnd()->SetWindowText("新的标题");
GetParent()->SetWindowText("新的标题");
}
BOOL CWndControlView::OnEraseBkgnd(CDC* pDC)
{
// 创建一个新的刷子
CBrush Brush (m_rgbBack);
// 把刷子选入设备环境
CBrush* pOldBrush = pDC->SelectObject (&Brush);
// 获得需要檫除背景的区域
CRect reClip;
pDC->GetClipBox(&reClip);
//重绘该区域
pDC->PatBlt(reClip.left , reClip.top , reClip.Width () , reClip.Height() , PATCOPY);
//释放刷子
pDC->SelectObject (pOldBrush);
return TRUE;
}
void CWndControlView::OnWndcontrolBkclr()
{
m_rgbBack = RGB(0,255,0);
Invalidate();
}
void CWndControlView::OnWndcontrolTop()
{
if (!m_bTopMost)
{
AfxGetMainWnd()->SetWindowPos(&CWnd::wndTopMost,0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
m_bTopMost = TRUE;
}
else
{
AfxGetMainWnd()->SetWindowPos(&wndNoTopMost,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
m_bTopMost = FALSE;
}
}
void CWndControlView::OnWndcontrolMove()
{
if (!m_bMoveOnView)
m_bMoveOnView = TRUE;
else
m_bMoveOnView = FALSE;
}
void CWndControlView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_bMoveOnView)
{
GetParentFrame()->PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM (point.x,point.y));
}
else
CView::OnLButtonDown(nFlags, point);
}
void CWndControlView::OnWndcontrolChildicon()
{
HICON hIcon = AfxGetApp()->LoadIcon(IDI_CHILD);
ASSERT(hIcon);
GetParent()->SendMessage(WM_SETICON,TRUE,(LPARAM)hIcon);
}
void CWndControlView::OnUpdateWndcontrolTop(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bTopMost);
}
void CWndControlView::OnWndcontrolHotsnap()
{
CHotSnapDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -