// test3Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "test3.h"
#include "test3Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
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()
/////////////////////////////////////////////////////////////////////////////
// CTest3Dlg dialog
CTest3Dlg::CTest3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest3Dlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest3Dlg)
DDX_Control(pDX, IDC_BUTTONBIG, m_ShowBig);
DDX_Control(pDX, IDC_CLOSEBTN, m_CloseBtn);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest3Dlg, CDialog)
//{{AFX_MSG_MAP(CTest3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SETCURSOR()
ON_WM_LBUTTONDOWN()
ON_BN_CLICKED(IDC_CLOSEBTN, OnClosebtn)
ON_BN_CLICKED(IDC_BUTTONBIG, OnButtonbig)
ON_WM_SIZE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest3Dlg message handlers
BOOL CTest3Dlg::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
//只有加了这一句后,才能将整个画面显示整个窗口,不至于仅仅在中心。
ModifyStyle(WS_CAPTION, WS_MINIMIZEBOX, SWP_DRAWFRAME); //设置图标
m_bmpBackground.LoadBitmap(IDB_BITMAPBACKGROUND);
//记住:Botton的属性值(Style)
m_ShowBig.LoadBitmaps(IDB_BITMAPBIG,IDB_BITMAPBIG);
m_CloseBtn.LoadBitmaps(IDB_BITMAPCLOSENORMAL,IDB_BITMAPON);
SetTimer(1,2000,NULL);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
/*
值 含义
SC_CLOSE 关闭按钮
SC_MAXIMIZE 最大化按钮
SC_MINIMIZE 最小化按钮
SC_RESTORE 恢复按钮*/
void CTest3Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
if(nID==SC_MINIMIZE)
{
}
if(nID==SC_MAXIMIZE)
{
ShowWindow(SW_MAXIMIZE);
// MessageBox("OK");
}
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 CTest3Dlg::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();
CPaintDC dc(this); //对话框的dc
CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(&rect);
BITMAP bitMap;
m_bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bmpBackground); //将背景位图选入内存dc中
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY); //将内存dc中的位图拉伸显示在对话框的dc中
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTest3Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CTest3Dlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if((pWnd->GetDlgCtrlID()==IDC_CLOSEBTN)||pWnd->GetDlgCtrlID()==IDC_BUTTONBIG)
{
SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR2));
return true; //必须返回True否则无效
}
SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
return true;
//return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
//拖动整个窗体移动。
void CTest3Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x, point.y)); //向系统发送HTCAPTION消息,让系统以为鼠标点在标题栏上
CDialog::OnLButtonDown(nFlags, point);
}
void CTest3Dlg::OnClosebtn()
{
// TODO: Add your control notification handler code here
OnOK();
}
//最大化
void CTest3Dlg::OnButtonbig()
{
ShowWindow(SW_MAXIMIZE);
// TODO: Add your control notification handler code here
}
void CTest3Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CTest3Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}