📄 drawformdlg.cpp
字号:
// DrawFormDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DrawForm.h"
#include "DrawFormDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#include "MyDlg.h"
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrawFormDlg dialog
//CDrawFormDlg::CDrawFormDlg(CWnd* pParent /*=NULL*/)//
// : CDialog(CDrawFormDlg::IDD, pParent)//
CDrawFormDlg::CDrawFormDlg(CWnd* pParent,UINT ID /*=NULL*/)
: m_IsDrawForm (FALSE),m_ButtonState(bsNone),CDialog(ID, pParent)
{
//{{AFX_DATA_INIT(CDrawFormDlg)
// NOTE: the ClassWizard will add member initialization here
m_FirstShow = FALSE;
m_IsMax = TRUE;
m_CapitonColor =RGB(0,0,255);
m_Caption = "系统登录";
m_LoadDll = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDrawFormDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDrawFormDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX, IDC_STATIC2, m_label2);
DDX_Control(pDX, IDC_STATIC1, m_label1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDrawFormDlg, CDialog)
//{{AFX_MSG_MAP(CDrawFormDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_RESTOREBUTTON, OnRestorebutton)
/////////////////////////////////////////
ON_WM_SIZE()
ON_WM_NCACTIVATE()
ON_WM_ACTIVATE()
ON_WM_NCMOUSEMOVE()
ON_WM_SHOWWINDOW()
ON_WM_CTLCOLOR()
ON_WM_WINDOWPOSCHANGED()
ON_WM_MOUSEMOVE()
ON_WM_NCPAINT()
ON_WM_NCLBUTTONUP()
ON_WM_NCLBUTTONUP()
ON_WM_NCLBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrawFormDlg message handlers
BOOL CDrawFormDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//////////////////////////////////////////////////////////////////
m_BorderHeight = GetSystemMetrics(SM_CYBORDER);
m_BorderWidth = GetSystemMetrics(SM_CXBORDER);
m_CaptionHeight = GetSystemMetrics(SM_CYCAPTION);
SetWindowText(m_Caption);
InitSkin();
///////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CDrawFormDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CDrawFormDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
DrawForm();/////////////////////////////////////////
m_IsDrawForm = TRUE;////////////////////////////////
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CDrawFormDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDrawFormDlg::OnSize(UINT nType, int cx, int cy)
{
SetWindowRgn(NULL,TRUE);
CDialog::OnSize(nType, cx, cy);
if (!m_LoadDll)
return;
CRect rect;
GetClientRect(rect);
CPoint pos = pSkin->GetButtonPos(6);
m_MinRect.CopyRect(CRect(m_RTitleRc.left+pos.x,(m_TitleDrawHeight +2*m_BorderHeight -m_ButtonHeight)/2+pos.y,m_ButtonWidth,m_ButtonHeight));
pos = pSkin->GetButtonPos(7);
m_MaxRect.CopyRect(CRect(m_RTitleRc.left+pos.x,(m_TitleDrawHeight+2*m_BorderHeight -m_ButtonHeight)/2+pos.y,m_ButtonWidth,m_ButtonHeight));
pos = pSkin->GetButtonPos(8);
m_CloseRect.CopyRect(CRect(m_RTitleRc.left+pos.x,(m_TitleDrawHeight+2*m_BorderHeight -m_ButtonHeight)/2+pos.y,m_ButtonWidth,m_ButtonHeight));
SetWinVisibleRect() ;
Invalidate();
}
BOOL CDrawFormDlg::OnNcActivate(BOOL bActive)
{
OnPaint() ;
return TRUE;//CDialog::OnNcActivate(bActive);
}
void CDrawFormDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
// OnPaint() ;
}
void CDrawFormDlg::OnNcMouseMove(UINT nHitTest, CPoint point)
{
if (m_LoadDll)
{
CRect tempIni,tempMin,tempMax,tempClose,ClientRect;
CWindowDC WindowDC (this);//= GetWindowDC();
CDC memDC;
memDC.CreateCompatibleDC(&WindowDC);
BITMAPINFO bInfo;
CBitmap LeftLine;
int x,y;
GetWindowRect(ClientRect);
tempMin.CopyRect(CRect(m_MinRect.left+ ClientRect.left,ClientRect.top+m_MinRect.top,m_MinRect.right+m_MinRect.left+ ClientRect.left,m_MinRect.bottom+m_MinRect.top+ClientRect.top));
tempMax.CopyRect(CRect(m_MaxRect.left+ ClientRect.left,ClientRect.top+m_MaxRect.top,m_MaxRect.right+m_MaxRect.left+ ClientRect.left,m_MaxRect.bottom+m_MaxRect.top+ClientRect.top));
tempClose.CopyRect(CRect(m_CloseRect.left+ ClientRect.left,ClientRect.top+m_CloseRect.top,m_CloseRect.right+m_CloseRect.left+ ClientRect.left,m_CloseRect.bottom+m_CloseRect.top+ClientRect.top));
if(tempMin.PtInRect(point)) //鼠标在最小化按钮上移动时,更改按钮显示的位图
{
if (m_ButtonState!= bsMin)
{
//HBITMAP hBmp = pSkin->GetBitmapRes(9);
LeftLine.Attach(pSkin->GetBitmapRes(9));
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
WindowDC.StretchBlt(m_MinRect.left,m_MinRect.top,m_MinRect.right,m_MinRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
m_ButtonState = bsMin;
LeftLine.Detach();
}
}
else if (tempMax.PtInRect(point))
{
if (m_ButtonState !=bsMax && m_ButtonState!=bsRes)
{
LeftLine.Attach(pSkin->GetBitmapRes(10));
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
WindowDC.StretchBlt(m_MaxRect.left,m_MaxRect.top,m_MaxRect.right,m_MaxRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
if (m_IsMax)
{
m_ButtonState = bsMax;
}
else
{
m_ButtonState = bsRes;
}
LeftLine.Detach();
}
}
else if (tempClose.PtInRect(point))
{
if (m_ButtonState != bsClose)
{
LeftLine.Attach(pSkin->GetBitmapRes(11));
LeftLine.GetObject(sizeof(bInfo),&bInfo);
x = bInfo.bmiHeader.biWidth;
y = bInfo.bmiHeader.biHeight;
memDC.SelectObject(&LeftLine);
WindowDC.StretchBlt(m_CloseRect.left,m_CloseRect.top,m_CloseRect.right,m_CloseRect.bottom,&memDC,0,0,x,y,SRCCOPY);
m_IsDrawForm = FALSE;
m_ButtonState = bsClose;
LeftLine.Detach();
}
}
else
{
if (m_IsDrawForm==FALSE)
{
if (m_ButtonState==bsMin)
DrawForm( fMinButton);
else if (m_ButtonState==bsClose)
DrawForm( fCloseButton);
else if (m_ButtonState==bsMax||m_ButtonState==bsRes)
DrawForm( fMaxButton);
}
m_ButtonState = bsNone;
}
LeftLine.DeleteObject();
ReleaseDC(&memDC);
}
CDialog::OnNcMouseMove(nHitTest, point);
}
void CDrawFormDlg::DrawForm(UINT Flags)
{
if (m_LoadDll)
{
m_FrameHeight= GetSystemMetrics(SM_CYFIXEDFRAME);
m_BorderHeight = GetSystemMetrics(SM_CYBORDER);
m_FrameWidth= GetSystemMetrics(SM_CXFIXEDFRAME);
m_BorderWidth = GetSystemMetrics(SM_CXBORDER);
m_CaptionHeight = GetSystemMetrics(SM_CYCAPTION);
CRect Clientrect;
GetClientRect(Clientrect);
CRect WinRC,FactRC;
GetWindowRect(WinRC);
FactRC.CopyRect(CRect(0,0,WinRC.Width(),WinRC.Height()));
//获取窗口设备上下文
CWindowDC WindowDC(this);// = GetWindowDC();
CBitmap LeftLine,*OldObj;
BITMAPINFO bitinfo;
CDC memDC;
memDC.CreateCompatibleDC(&WindowDC);
int leftwidth=0; //左标题的宽度
int rightwidth = 0; //右标题的宽度
int leftlinewidth = 0; //窗体边框和3D宽度
int rLineWidth;
int bLineHeight;
DeleteObject(LeftLine);
LeftLine.Attach(pSkin->GetBitmapRes(2)); //加载右标题
LeftLine.GetObject(sizeof(bitinfo),&bitinfo);
rightwidth = bitinfo.bmiHeader.biWidth;
LeftLine.Detach();
int x,y;
/*******************************绘制左边线*****************************************/
//获取位图大小
if ( Flags & fLeftBand )
{
DeleteObject(LeftLine);
LeftLine.Attach(pSkin->GetBitmapRes(3));
LeftLine.GetObject(sizeof(bitinfo),&bitinfo);
LeftLine.GetObject(sizeof(bitinfo),&bitinfo);
x = bitinfo.bmiHeader.biWidth;
y = bitinfo.bmiHeader.biHeight;
OldObj = memDC.SelectObject(&LeftLine);
//判断位图的宽度与窗体边缘的宽度
leftlinewidth = (x> m_FrameWidth+m_BorderWidth)? x:m_FrameWidth+m_BorderWidth;
WindowDC.StretchBlt(0,m_CaptionHeight,leftlinewidth,FactRC.Height()-m_CaptionHeight,&memDC,0,0,x,y,SRCCOPY);
memDC.SelectObject(OldObj);
LeftLine.Detach();
}
/*******************************绘制左边线*****************************************/
/*****************************绘制左标题**************************************/
if ( Flags & fLeftTitle)
{
DeleteObject(LeftLine);
LeftLine.Attach(pSkin->GetBitmapRes(0));
//获取位图大小
LeftLine.GetObject(sizeof(bitinfo),&bitinfo);
OldObj = memDC.SelectObject(&LeftLine);
leftwidth = x = bitinfo.bmiHeader.biWidth;
y = bitinfo.bmiHeader.biHeight;
m_TitleDrawHeight = (m_CaptionHeight+4>y)?m_CaptionHeight+4: y;
// m_TitleDrawHeight+= m_BorderHeight;
// m_LTitleRc.CopyRect(CRect(-m_BorderWidth,0,x+m_BorderWidth,m_TitleDrawHeight));
m_LTitleRc.CopyRect(CRect(0,0,x,m_TitleDrawHeight));
WindowDC.StretchBlt(m_LTitleRc.left,m_LTitleRc.top,m_LTitleRc.Width(),m_LTitleRc.Height(),&memDC,0,0,x,y,SRCCOPY);
memDC.SelectObject(OldObj);
LeftLine.Detach();
}
/*****************************绘制左标题****************************************/
/*****************************绘制右标题*****************************************/
if ( Flags & fRightTitle)
{
DeleteObject(LeftLine);
LeftLine.Attach(pSkin->GetBitmapRes(2));
//获取位图大小
LeftLine.GetObject(sizeof(bitinfo),&bitinfo);
OldObj = memDC.SelectObject(&LeftLine);
x = bitinfo.bmiHeader.biWidth;
y = bitinfo.bmiHeader.biHeight;
m_TitleDrawHeight = (m_CaptionHeight+4>y)?m_CaptionHeight+4: y;
//m_TitleDrawHeight+= m_BorderHeight;
m_RTitleRc.CopyRect(CRect(FactRC.right-x,0,FactRC.right,m_TitleDrawHeight));
WindowDC.StretchBlt(m_RTitleRc.left,m_RTitleRc.top,m_RTitleRc.Width(),m_RTitleRc.Height(),&memDC,0,0,x,y,SRCCOPY);
DeleteObject( memDC.SelectObject(OldObj));
LeftLine.Detach();
}
/*****************************绘制右标题***************************************/
/*****************************绘制中间标题**************************************/
if ( Flags & fMidTitle)
{
DeleteObject(LeftLine);
LeftLine.Attach(pSkin->GetBitmapRes(1));
//获取位图大小
LeftLine.GetObject(sizeof(bitinfo),&bitinfo);
OldObj = memDC.SelectObject(&LeftLine);
x = bitinfo.bmiHeader.biWidth;
y = bitinfo.bmiHeader.biHeight;
m_TitleDrawHeight = (m_CaptionHeight+4>y)?m_CaptionHeight+4: y;
//m_TitleDrawHeight+= m_BorderHeight;
m_MTitleRc.CopyRect(CRect(m_LTitleRc.right,0,m_RTitleRc.left,m_TitleDrawHeight));
WindowDC.StretchBlt(m_MTitleRc.left,m_MTitleRc.top,m_MTitleRc.Width(),m_MTitleRc.Height(),&memDC,0,0,x,y,SRCCOPY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -