Mini Paint Application Example Program in VC++
//Note:Should need some resource files and need to map
#include<afxwin.h>
#include<afxext.h>
#include "resource.h"
class Frame : public CFrameWnd {
private:
CToolBar Bar1, Bar2;
public:
int Xaxis, Yaxis, col, Style, Width;
int Red, Blue, Green;
Frame() {
Create(0, "MiniPaint", WS_OVERLAPPEDWINDOW,
rectDefault, 0, MAKEINTRESOURCE(IDR_MENU1));
}
void OnLButtonDown(UINT i, CPoint Point) {
Xaxis = Point.x;
Yaxis = Point.y;
}
void StyleFn(int Value) {
switch (Value) {
case 40004: Style = 0;
break;
case 40005: Style = 1;
break;
case 40006: Style = 2;
break;
case 40007: Style = 3;
break;
}
}
void WidthFn(int Value) {
switch (Value) {
case 40008: Width = 0;
break;
case 40009: Width = 1;
break;
case 40010: Width = 2;
break;
}
}
void ColorFn(int Value) {
Red = 0;
Blue = 0;
Green = 0;
switch (Value) {
case 40001: Red = 255;
break;
case 40002: Green = 255;
break;
case 40003: Blue = 255;
break;
}
}
void OnLButtonUp(UINT i, CPoint Cur) {
CClientDC Obj(this);
CPen Pen;
Pen.CreatePen(0, 1, RGB(Red, Green, Blue));
Obj.SelectObject(&Pen);
if (Style == 0)
Obj.Rectangle(Xaxis, Yaxis, Cur.x, Cur.y);
else if (Style == 1) {
Obj.MoveTo(Xaxis, Yaxis);
Obj.LineTo(Cur.x, Cur.y);
} else {
Obj.Ellipse(Xaxis, Yaxis, Cur.x, Cur.y);
}
Xaxis = Cur.x;
Yaxis = Cur.y;
}
void OnMouseMove(UINT Flag, CPoint Point) {
CClientDC Obj(this);
CPen Pen;
Pen.CreatePen(0, Width, RGB(Red, Green, Blue));
if (Style == 3) {
Obj.SelectObject(&Pen);
Obj.MoveTo(Xaxis, Yaxis);
Obj.LineTo(Point.x, Point.y);
Xaxis = Point.x;
Yaxis = Point.y;
}
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(Frame, CFrameWnd)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_CREATE()
ON_WM_MOUSEMOVE()
ON_COMMAND_RANGE(40001, 40003, ColorFn)
ON_COMMAND_RANGE(40004, 40007, StyleFn)
ON_COMMAND_RANGE(40008, 40010, WidthFn)
END_MESSAGE_MAP()
class Applet : public CWinApp {
public:
int InitInstance() {
Frame *Pointer = new Frame();
Pointer->ShowWindow(3);
m_pMainWnd = Pointer;
return true;
}
};
Applet Instance;