📄 sampledlg.cpp
字号:
// sampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sample.h"
#include "sampleDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ROP4_TRANSPARENTBLIT 0xCCAA0020
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSampleDlg dialog
CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSampleDlg)
// 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 CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSampleDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
//{{AFX_MSG_MAP(CSampleDlg)
ON_WM_SYSCOMMAND()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSampleDlg message handlers
BOOL CSampleDlg::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
SetTimer(1,50,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSampleDlg::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.
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSampleDlg::AnimationPic(int x1, int y1, int x2, int y2)
{
CWnd *pWnd=GetDlgItem(IDC_STATIC_PIC);
CDC *pDC=pWnd->GetDC();
BITMAP bmPlane,bmSatellite,bmBackground;
CBitmap bitmapplane,planeMaskBitmap,bitmapsatellite,satelliteMaskBitmap,bitmapbackground;
//加载图片
if(!(bitmapplane.LoadBitmap(IDB_AEROPLANE)&&bitmapsatellite.LoadBitmap(IDB_SATELLITE)&&
bitmapbackground.LoadBitmap(IDB_BACKGROUND)))
{
AfxMessageBox("Can not load the 3 pictures correctly!");
return;
}
//获取图片大小
bitmapplane.GetObject(sizeof(bmPlane),&bmPlane);
bitmapsatellite.GetObject(sizeof(bmSatellite),&bmSatellite);
bitmapbackground.GetObject(sizeof(bmBackground),&bmBackground);
//生成CDC对象,创建与显示设备上下文兼容的内存设备上下文CDC对象
CDC dcplane,dcsatellite,dcsatellitemask,dcbackground,dcplanemask;
dcplanemask.CreateCompatibleDC(pDC) ;
dcsatellitemask.CreateCompatibleDC(pDC);
dcbackground.CreateCompatibleDC(pDC);
dcplane.CreateCompatibleDC(pDC);
dcsatellite.CreateCompatibleDC(pDC);
//创建航天飞机的mask图片
planeMaskBitmap.CreateBitmap(bmPlane.bmWidth,bmPlane.bmHeight, 1, 1, NULL ) ;
CBitmap* OldPlaneMaskBitmap = dcplanemask.SelectObject( &planeMaskBitmap ) ;
//创建卫星的mask图片
satelliteMaskBitmap.CreateBitmap(bmSatellite.bmWidth,bmSatellite.bmHeight,1,1,NULL);
CBitmap *OldSatelliteMaskBitmap=dcsatellitemask.SelectObject(&satelliteMaskBitmap);
//将位图对象选入创建的内存设备上下文
CBitmap *oldplane=dcplane.SelectObject(&bitmapplane);
CBitmap *oldsatellite=dcsatellite.SelectObject(&bitmapsatellite);
CBitmap *oldbackground=dcbackground.SelectObject(&bitmapbackground);
//创建航天飞机的mask
COLORREF l_crOldBack = dcplane.SetBkColor( RGB( 0, 255, 0 ) ) ;
dcplanemask.BitBlt(0,0,bmPlane.bmWidth,bmPlane.bmHeight,&dcplane, 0, 0, SRCCOPY ) ;
dcplane.SetBkColor( l_crOldBack ) ;
//创建卫星的mask
l_crOldBack = dcsatellite.SetBkColor( RGB( 0, 0, 0 ) ) ;
dcsatellitemask.BitBlt(0,0,bmSatellite.bmWidth,bmSatellite.bmHeight,&dcsatellite, 0, 0, SRCCOPY ) ;
dcsatellite.SetBkColor( l_crOldBack ) ;
//加载航天飞机
dcbackground.MaskBlt(x1,y1,bmPlane.bmWidth,bmPlane.bmHeight,&dcplane,0,0,planeMaskBitmap,0,0,ROP4_TRANSPARENTBLIT );
//加载卫星
dcbackground.MaskBlt(x2,y2,bmSatellite.bmWidth,bmSatellite.bmHeight,&dcsatellite,0,0,satelliteMaskBitmap,0,0,ROP4_TRANSPARENTBLIT );
//显示图片
pDC->BitBlt(0,0,bmBackground.bmWidth,bmBackground.bmHeight,&dcbackground,0,0,SRCCOPY);
//释放
dcsatellitemask.SelectObject(OldSatelliteMaskBitmap);
dcplanemask.SelectObject(OldPlaneMaskBitmap);
dcplane.SelectObject(oldplane);
dcsatellite.SelectObject(oldsatellite);
dcbackground.SelectObject(oldbackground);
}
void CSampleDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int x1=-128,y1=200,x2,y2,judge;
if(x1<500)
x1++;
else
x1=-128;
if(y2>=320)
judge=1;
if(x2>=372)
judge=2;
if(y2<0)
judge=3;
if(x2<0)
judge=0;
switch(judge)
{
case 0:x2++;y2+=2;break;
case 1:x2+=2;y2-=2;break;
case 2:x2-=2;y2--;break;
case 3:x2--;y2+=2;break;
}
AnimationPic(x1,y1,x2,y2);
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -