📄 polybar.cpp
字号:
// PolyBar.cpp : implementation file
//
#include "stdafx.h"
#include "Drawing.h"
#include "PolyBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPolyBar
CPolyBar::CPolyBar()
{
m_nPick = m_nOldPick = 0;
m_nPickMode = 0;
m_nWidth = 1;
}
CPolyBar::~CPolyBar()
{
}
BEGIN_MESSAGE_MAP(CPolyBar, CToolBar)
//{{AFX_MSG_MAP(CPolyBar)
ON_WM_PAINT()
ON_WM_LBUTTONUP()
ON_COMMAND(ID_WIDTH_1, OnWidth1)
ON_COMMAND(ID_WIDTH_2, OnWidth2)
ON_COMMAND(ID_WIDTH_3, OnWidth3)
ON_COMMAND(ID_MODE_1, OnMode1)
ON_COMMAND(ID_MODE_2, OnMode2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPolyBar message handlers
void CPolyBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
//首先确定按纽在此窗口内的矩形,只需要初始化一次,因此设置了静态变量count记数
static int count = 0;
if(count == 0)
{
count++;
for(int i=0; i<3; i++)
{
m_rect[2*i].SetRect(20, 20+i*33, 20+27, 20+i*33+27);
m_rect[2*i+1].SetRect(20+27+6, 20+i*33, 20+27+6+27, 20+i*33+27);
}
}
//画出每一个按纽(未按下的状态)
for(int i=0; i<BtnCount; i++)
{
if(m_nPick == i)
dc.Draw3dRect(m_rect[i], RGB(0, 0, 0), RGB(255, 255, 255));
else
dc.Draw3dRect(m_rect[i], RGB(255, 255, 255), RGB(0, 0, 0));
CRgn rgn;
CPoint pt[3] = { CPoint(m_rect[i].right-6, m_rect[i].bottom-7),
CPoint(m_rect[i].right-6, m_rect[i].bottom-2),
CPoint(m_rect[i].right-2, m_rect[i].bottom-4)
};
rgn.CreatePolygonRgn(pt, 3, ALTERNATE); //WINDING
CBrush bru(RGB(0, 0, 0));
dc.FillRgn(&rgn, &bru);
rgn.DeleteObject();
}
//在按纽矩形上画出点.直线.矩形.圆.多边形等图元,表示代表什么按纽
GeoPoint pt(20+27/2, 20+27/2);//点按纽
pt.SetWidth(2);
pt.Draw(dc);
GeoLine line; //线按纽
line.SetTwoPoint(m_rect[1].left+8, m_rect[1].top+8, m_rect[1].right-8, m_rect[1].bottom-8);
line.SetWidth(2);
line.Draw(dc);
GeoRect rect; //矩形按纽
rect.SetTwoPoint(m_rect[2].left+8, m_rect[2].top+8, m_rect[2].right-8, m_rect[2].bottom-8);
rect.SetWidth(1);
rect.Draw(dc);
GeoCircle circle; //圆按纽
circle.SetTwoPoint(m_rect[3].left+8, m_rect[3].top+8, m_rect[3].right-8, m_rect[3].bottom-8);
circle.SetWidth(1);
circle.Draw(dc);
GeoPolygon polygon; //多边形按纽
polygon.AddPoint(CPoint(m_rect[4].left+4, m_rect[4].bottom-4));
polygon.AddPoint(CPoint(m_rect[4].right-8, m_rect[4].bottom-4));
polygon.AddPoint(CPoint(m_rect[4].right-4, m_rect[4].bottom-12));
polygon.AddPoint(CPoint(m_rect[4].right-12, m_rect[4].bottom-12));
polygon.AddPoint(CPoint(m_rect[4].right-8, m_rect[4].top+4));
polygon.AddPoint(CPoint(m_rect[4].right-16, m_rect[4].top+4));
polygon.SetClose();
polygon.SetWidth(1);
polygon.Draw(dc);
//第6个本打算写字用,限于时间,省略了...
dc.SetTextColor(RGB(255, 0, 0));
dc.SetBkMode(TRANSPARENT);
dc.TextOut(m_rect[5].left+4, m_rect[5].top+5, "NO");
// Do not call CToolBar::OnPaint() for painting messages
}
//当鼠标在按纽上点击后释放的消息处理
void CPolyBar::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
for(int i=0; i<BtnCount; i++)
{
//判断鼠标电击的点在哪个矩形按纽内
if(m_rect[i].PtInRect(point))
{
CClientDC dc(this);
if(m_nPick != -1)
dc.Draw3dRect(&m_rect[m_nPick], RGB(255, 255, 255), RGB(0, 0, 0));
m_nOldPick = m_nPick;
m_nPick = i;
//画出鼠标按下的状态
dc.Draw3dRect(&m_rect[i], RGB(0, 0, 0), RGB(255, 255, 255));
//然后弹出popmenu
CPoint pt(m_rect[i].right, m_rect[i].bottom);
ClientToScreen(&pt);
CMenu menu;
menu.LoadMenu(IDR_POPMENU);//载取popmenu
if(i==5)//写字
{
menu.GetSubMenu(0)->GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this, NULL);
menu.DestroyMenu();
break;
}
if(i==0 || i==1)
{
menu.GetSubMenu(0)->GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this, NULL);
menu.DestroyMenu();
break;
}
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, this, NULL);
menu.DestroyMenu();
break;
}
}
CToolBar::OnLButtonUp(nFlags, point);
}
//宽度及模式的选择消息
void CPolyBar::OnWidth1()
{
// TODO: Add your command handler code here
m_nWidth = 1;
}
void CPolyBar::OnWidth2()
{
// TODO: Add your command handler code here
m_nWidth = 2;
}
void CPolyBar::OnWidth3()
{
// TODO: Add your command handler code here
m_nWidth = 3;
}
void CPolyBar::OnMode1()
{
// TODO: Add your command handler code here
m_nPickMode = 0;
}
void CPolyBar::OnMode2()
{
// TODO: Add your command handler code here
m_nPickMode = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -