📄 test1dlg.cpp
字号:
// Test1Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Test1.h"
#include "Test1Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg dialog
CTest1Dlg::CTest1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest1Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTest1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest1Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest1Dlg, CDialog)
//{{AFX_MSG_MAP(CTest1Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest1Dlg message handlers
BOOL CTest1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
InitRgn();
m_flag=0;
CRgn rgn;
rgn.CreateFromData(NULL,m_size[0],m_data[0]);
SetWindowRgn(rgn,TRUE);
InitBmp();
CClientDC dc(this);
DrawBitmap(&dc,0);
m_timer=TRUE;
SetTimer(1,100,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CTest1Dlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTest1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTest1Dlg::InitRgn()
{
CRgn rgn;
//生成矩形区域
rgn.CreateRectRgn(50,50,150,150);
m_size[0]=rgn.GetRegionData(NULL,0);
m_data[0]=(LPRGNDATA)new BYTE[m_size[0]];
rgn.GetRegionData(m_data[0],m_size[0]);
for(int i=2;i<8;i+=2)//公用区域数据
{
m_size[i]=m_size[0];
m_data[i]=m_data[0];
}
rgn.DeleteObject();
//生成菱形区域
POINT point[4];
point[0].x=100;point[0].y=29;
point[1].x=29;point[1].y=100;
point[2].x=100;point[2].y=171;
point[3].x=171;point[3].y=100;
rgn.CreatePolygonRgn(point,4,0);
m_size[1]=rgn.GetRegionData(NULL,0);
m_data[1]=(LPRGNDATA)new BYTE[m_size[1]];
rgn.GetRegionData(m_data[1],m_size[1]);
for(i=1;i<8;i+=2)
{
m_size[i]=m_size[1];
m_data[i]=m_data[1];
}
rgn.DeleteObject();
}
void CTest1Dlg::InitBmp()
{
m_bitmap[0].LoadBitmap(IDB_BITMAP1);
m_bitmap[1].LoadBitmap(IDB_BITMAP2);
m_bitmap[2].LoadBitmap(IDB_BITMAP3);
m_bitmap[3].LoadBitmap(IDB_BITMAP4);
m_bitmap[4].LoadBitmap(IDB_BITMAP5);
m_bitmap[5].LoadBitmap(IDB_BITMAP6);
m_bitmap[6].LoadBitmap(IDB_BITMAP7);
m_bitmap[7].LoadBitmap(IDB_BITMAP8);
}
BOOL CTest1Dlg::DrawBitmap(CDC *pDC, int Number)
{
if(m_bitmap[Number].m_hObject==NULL)return FALSE;
CDC memDC;
BITMAP bm;
CRect rect;
GetClientRect(&rect);
m_bitmap[m_flag].GetObject(sizeof(BITMAP),&bm);
memDC.CreateCompatibleDC(pDC);
CBitmap * oldbitmap=memDC.SelectObject(&m_bitmap[Number]);
pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
memDC.SelectObject(oldbitmap);
return TRUE;
}
void CTest1Dlg::OnTimer(UINT nIDEvent)
{
CRgn rgn;
m_flag++;
if(m_flag>=8)m_flag=0;
rgn.CreateFromData(NULL,m_size[m_flag],m_data[m_flag]);
SetWindowRgn(rgn,TRUE);
CClientDC dc(this);
DrawBitmap(&dc,m_flag);
CDialog::OnTimer(nIDEvent);
}
void CTest1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
m_timer=!m_timer;
if(m_timer)SetTimer(1,100,NULL);
else KillTimer(1);
PostMessage(WM_SYSCOMMAND,0xf012);
CDialog::OnLButtonDown(nFlags, point);
}
void CTest1Dlg::OnRButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnRButtonDown(nFlags, point);
PostMessage(WM_CLOSE);
}
void CTest1Dlg::OnClose()
{
if(m_timer)KillTimer(1);
delete m_data[0];
delete m_data[1];
CDialog::OnClose();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -