#include _afxwin.h_ //replace _ with “<”
#include"resource.h"
class myframe:public CFrameWnd
{
private:
CMenu menu1;
CToolBar toolShape,toolColor;
public:
myframe()
{
Create(0,"Menu & Toolbars");
}
int OnCreate(LPCREATESTRUCT m)
{
CFrameWnd::OnCreate (m);
menu1.LoadMenu(IDR_MENU1);
SetMenu(&menu1);
toolShape.Create(this,WS_CHILDWS_VISIBLECBRS_RIGHTCBRS_BORDER_LEFTCBRS_BORDER_RIGHTCBRS_BORDER_TOPCBRS_BORDER_BOTTOM);
toolShape.LoadToolBar(IDR_TOOLBAR1);
ShowControlBar(&toolShape,TRUE,FALSE);
toolColor.Create(this,WS_CHILDWS_VISIBLECBRS_RIGHTCBRS_BORDER_LEFTCBRS_BORDER_RIGHTCBRS_BORDER_TOPCBRS_BORDER_BOTTOM);
toolColor.LoadToolBar(IDR_TOOLBAR2);
ShowControlBar(&toolColor,TRUE,FALSE);
return 0;
}
void Menus(int ID)
{
CPen *pe;
static CClientDC dc(this);
switch(ID)
{
case 101:
dc.Rectangle(20,20,100,100);
break;
case 102:
dc.Ellipse(50,50,300,300);
break;
case 103:
dc.LineTo(400,400);
break;
case 104:
dc.RoundRect(250,25,600,400,50,50);
break;
case 105:
pe=new CPen(PS_SOLID,2,RGB(255,0,0));
dc.SelectObject(pe);
break;
case 106:
pe=new CPen(PS_SOLID,2,RGB(0,255,0));
dc.SelectObject(pe);
break;
case 107:
pe=new CPen(PS_SOLID,2,RGB( 0,0,255));
dc.SelectObject(pe);
break;
case 108:
pe=new CPen(PS_SOLID,2,RGB(255,255,0));
dc.SelectObject(pe);
break;
case 109:
pe=new CPen(PS_SOLID,2,RGB(0,0,0));
dc.SelectObject(pe);
break;
}
}
void OnPaint()
{
CPaintDC dc(this);
CFont mfont;
mfont.CreateFont(50,30,0,0,FW_BOLD,1,1,0,DEFAULT_CHARSET,0,0,0,0,"Arial");
dc.SelectObject (mfont);
dc.SetTextColor(RGB(20,30,233));
dc.TextOut(200,100,"Hello",5);
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CREATE()
ON_COMMAND_RANGE(101,109,Menus)
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
m_pMainWnd=p;
m_pMainWnd->ShowWindow(1);
return 1;
}
};
myapp a;
0 comments:
Post a Comment