You are on page 1of 3

#include <afxwin.

h>
#include <iostream>
#include "resource.h"
using namespace std;

int g = 1;
bool isrect = false,iscrcl = false;
class CSimpleFrame : public CFrameWnd
{
public:
CSimpleFrame();
void OnPaint();
DECLARE_MESSAGE_MAP()
afx_msg void OnLetItGo();
afx_msg void OnLetItGo2();
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
};

CSimpleFrame::CSimpleFrame()
{
Create(NULL, L"Resources Fundamentals",WS_OVERLAPPEDWINDOW, CRect(200, 120,
1000,1000),NULL,MAKEINTRESOURCE(IDR_MENU1));
}

struct CSimpleApp : public CWinApp


{
BOOL InitInstance();
};

BOOL CSimpleApp::InitInstance()
{
m_pMainWnd = new CSimpleFrame;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}

BEGIN_MESSAGE_MAP(CSimpleFrame , CFrameWnd)
ON_WM_PAINT()
ON_COMMAND(ID_HERE_CIRCLE, OnLetItGo2)
ON_COMMAND(ID_HERE_RECTANGLE, OnLetItGo)
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()

void CSimpleFrame::OnLetItGo()
{
CRect rect(20,60,120,120);
g = 2;
isrect = true;
InvalidateRect(rect);
}

void CSimpleFrame::OnLetItGo2()
{
CRect rect(130,60,190,120);
g = 3;
iscrcl = true;
InvalidateRect(rect);
}

void CSimpleFrame::OnRButtonDown(UINT nFlags, CPoint point)


{
//wchar_t MsgCoord[50] = L"nbbdfni";
//SendMessage(WM_SETTEXT,0,(LPARAM)(LPCTSTR)MsgCoord);
//swprintf(MsgCoord, L"Left Button at P(%d, %d)", point.x, point.y);
//MessageBox(MsgCoord);
if(point.x >= 20 && point.y <= 40)
{
if(isrect)
{
//swprintf(MsgCoord,L"In if");
//MessageBox(MsgCoord);
CRect rect(20,60,120,120);
g = 4;
InvalidateRect(rect);
}
if(iscrcl)
{
CRect rect(130,60,190,120);
g = 5;
InvalidateRect(rect);
}
}
}

void CSimpleFrame::OnPaint()
{
CPaintDC dc(this);
CRect recto(20,20,40,40),recto2(50,20,70,40);
CBrush Bru(RGB(10,10,100)),Bru2(RGB(255,0,0));
if (g==1)
{
CBrush *Br = dc.SelectObject(&Bru);
dc.Rectangle(&recto);
CBrush *Br2 = dc.SelectObject(&Bru2);
dc.Rectangle(&recto2);
}
else if(g==2)
{
dc.Rectangle(20,60,120,120);
}
else if(g==3)
{
dc.Ellipse(130,60,190,120);
}
else if(g==4)
{
CBrush Bru(RGB(10,10,100));
CBrush *Br3 = dc.SelectObject(&Bru);
dc.Rectangle(20,60,120,120);
}
else if(g==5)
{
CBrush Bru(RGB(10,10,100));
CBrush *Br3 = dc.SelectObject(&Bru);
dc.Ellipse(130,60,190,120);
}
}

CSimpleApp theApp;

You might also like