vehinhchonmau
#define IDR_MENU1 101
#define ID_CHONMAUVE_DO 40001
#define ID_CHONMAUVE_XANH 40002
#define ID_CHONMAUVE_VANG 40003
#define ID_CHONMAUVE_TIM 40004
#define ID_CHONMAUTO_DO 40005
#define ID_CHONMAUTO_XANH 40006
#define ID_CHONMAUTO_VANG 40007
#define ID_CHONMAUTO_TIM 40008
#define ID_CHONHINHVE_CHUNHAT 40009
#define ID_CHONHINHVE_ELIP 40010
#define ID_CHONHINHVE_DUONGTHANG 40011
#define ID_CHONHINHVE_XOATATCA 40012
#define ID_THOAT 40013
IDR_MENU1 MENU DISCARDABLE
BEGIN
POPUP "chon mau ve"
BEGIN
MENUITEM "DO", ID_CHONMAUVE_DO
MENUITEM "XANH", ID_CHONMAUVE_XANH
MENUITEM "VANG", ID_CHONMAUVE_VANG
MENUITEM "TIM", ID_CHONMAUVE_TIM
END
POPUP "CHON MAU TO"
BEGIN
MENUITEM "DO", ID_CHONMAUTO_DO
MENUITEM "XANH", ID_CHONMAUTO_XANH
MENUITEM "VANG", ID_CHONMAUTO_VANG
MENUITEM "TIM", ID_CHONMAUTO_TIM
END
POPUP "CHON HINH VE"
BEGIN
MENUITEM "CHU NHAT", ID_CHONHINHVE_CHUNHAT
MENUITEM "ELIP", ID_CHONHINHVE_ELIP
MENUITEM "DUONG THANG", ID_CHONHINHVE_DUONGTHANG
MENUITEM "XOA TAT CA", ID_CHONHINHVE_XOATATCA
END
MENUITEM "", 65535
MENUITEM "THOAT", ID_THOAT
END
#include<afxwin.h>
#include"resource.h"
class CMyApp:public CWinApp
{
public:
BOOL InitInstance();
};
class CMyWin:public CFrameWnd
{
private:
CDC m_memDC;
CBitmap m_bmp;
CBrush m_bkbrush;
//-------------------
int maxX,maxY,hinhve;
CPoint oldPoint;
CPen p;
CBrush b;
public:
CMyWin();
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags,CPoint point);
afx_msg void OnLButtonUp(UINT nFlags,CPoint point);
afx_msg void OnMouseMove(UINT nFlags,CPoint point);
void OnChooseCommand(UINT id);
DECLARE_MESSAGE_MAP()
};
CMyApp theApp;
BEGIN_MESSAGE_MAP(CMyWin,CFrameWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_COMMAND_RANGE(ID_CHONMAUVE_DO,ID_THOAT,OnChooseCommand)
END_MESSAGE_MAP()
BOOL CMyApp::InitInstance()
{
m_pMainWnd=new CMyWin;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMyWin::CMyWin()
{
CMenu mn;
Create(NULL,"Vi du 04-chuong 04");
mn.LoadMenu(IDR_MENU1);
SetMenu(&mn);
p.CreatePen(PS_SOLID,1,RGB(0,0,0));
b.CreateSolidBrush(RGB(0,0,0));
//--------------------
maxX=GetSystemMetrics(SM_CXSCREEN);
maxY=GetSystemMetrics(SM_CYSCREEN);
CClientDC DC(this);
m_memDC.CreateCompatibleDC(&DC);
m_bmp.CreateCompatibleBitmap(&DC,maxX,maxY);
m_memDC.SelectObject(&m_bmp);
//------------------------
m_bkbrush.CreateStockObject(WHITE_BRUSH);
m_memDC.SelectObject(&m_bkbrush);
m_memDC.PatBlt(0,0,maxX,maxY,PATCOPY);
//--------------------------------
hinhve=3;
}
void CMyWin::OnPaint()
{
CPaintDC DC(this);
//copy tu cua so ao
//len cua so that
DC.BitBlt(0,0,maxX,maxY,&m_memDC,0,0,SRCCOPY);
}
void CMyWin::OnLButtonDown(UINT nFlags,CPoint point)
{
oldPoint =point;
}
void CMyWin::OnLButtonUp(UINT nFlags,CPoint point)
{
m_memDC.SelectObject(&b);
m_memDC.SelectObject(&p);
switch(hinhve)
{
case 1:
m_memDC.Rectangle(oldPoint.x,oldPoint.y,point.x,point.y);
break;
case 2:
m_memDC.Ellipse(oldPoint.x,oldPoint.y,point.x,point.y);
break;
case 3:
m_memDC.MoveTo(oldPoint.x,oldPoint.y);
m_memDC.LineTo(point.x,point.y );
break;
}
InvalidateRect(NULL);//tu yeu cau
//ve lai cua so
}
void CMyWin::OnChooseCommand(UINT id)
{
switch(id)
{
case ID_THOAT:
DestroyWindow();
break;
case ID_CHONMAUVE_DO:
p.DeleteObject();
p.CreatePen(PS_SOLID,1,RGB(255,0,0));
break;
case ID_CHONMAUVE_XANH:
p.DeleteObject();
p.CreatePen(PS_SOLID,1,RGB(0,0,255));
break;
case ID_CHONMAUVE_VANG:
p.DeleteObject();
p.CreatePen(PS_SOLID,1,RGB(255,255,0));
break;
case ID_CHONMAUVE_TIM:
p.DeleteObject();
p.CreatePen(PS_SOLID,1,RGB(255,0,255));
break;
case ID_CHONMAUTO_DO:
b.DeleteObject();
b.CreateSolidBrush(RGB(255,0,0));
break;
case ID_CHONMAUTO_XANH:
b.DeleteObject();
b.CreateSolidBrush(RGB(0,0,255));
break;
case ID_CHONMAUTO_VANG:
b.DeleteObject();
b.CreateSolidBrush(RGB(255,255,0));
break;
case ID_CHONMAUTO_TIM:
b.DeleteObject();
b.CreateSolidBrush(RGB(255,0,255));
break;
case ID_CHONHINHVE_CHUNHAT:
hinhve=1;
break;
case ID_CHONHINHVE_ELIP:
hinhve=2;
break;
case ID_CHONHINHVE_DUONGTHANG:
hinhve=3;
break;
case ID_CHONHINHVE_XOATATCA:
m_memDC.SelectObject(&m_bkbrush);
m_memDC.PatBlt(0,0,maxX,maxY,PATCOPY);
InvalidateRect(NULL);
break;
}
}
void CMyWin::OnMouseMove(UINT nFlags,CPoint point)
{
/*
if(nFlags!=MK_LBUTTON) return;
CDC *dc=GetDC();
dc->SelectObject(&p);
dc->SelectObject(&b);
dc->MoveTo(oldPoint);
switch(hinhve)
{
case 1:
dc->Rectangle(oldPoint.x,oldPoint.y,point.x,point.y);
break;
case 2:
dc->Ellipse(oldPoint.x,oldPoint.y,point.x,point.y);
break;
case 3:
dc->LineTo(point);
break;
}*/
}
Bạn đang đọc truyện trên: AzTruyen.Top