📄 platebutton.cpp
字号:
// PlateButton.cpp : implementation file
//
#include "stdafx.h"
#include "GtMpegWnd.h"
#include "PlateButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////
//
/////////////////////////////
CPlateButton::CPlateButton()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetResourceHandle();
if (!(::GetClassInfo(hInst, "PlateButtonCtrl", &wndcls)))
{
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = NULL;
wndcls.hbrBackground = NULL;//(HBRUSH) (Brush.operator HBRUSH());//COLOR_3DFACE + 1
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = "PlateButtonCtrl";
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();
}
m_pToolTip = NULL;
}
CPlateButton::~CPlateButton()
{
if (m_pToolTip)
{
delete (m_pToolTip);
m_pToolTip = NULL;
}
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CPlateButton, CWnd)
//{{AFX_MSG_MAP(CPlateButton)
ON_WM_CREATE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateButton::Create(CStringArray &arCaption,CRect rect, CWnd* pParentWnd, UINT nID)
{
m_arCaption.SetSize(0);
m_arCaption.Copy(arCaption);
return CWnd::Create("PlateButtonCtrl",NULL,WS_CHILD|WS_VISIBLE,rect,pParentWnd,nID);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateButton::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
if (m_pToolTip)
{
CPoint ptCurrentPos;
ptCurrentPos.x = LOWORD(pMsg->lParam);
ptCurrentPos.y = HIWORD(pMsg->lParam);
if (m_rectSearch.PtInRect(ptCurrentPos) == FALSE)
{
m_pToolTip->Activate(FALSE);
}
m_pToolTip->Activate(TRUE);
m_pToolTip->RelayEvent(pMsg);
}
}
return CWnd::PreTranslateMessage(pMsg);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateButton::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
NMHDR *Msg=(NMHDR *)lParam;
if(wParam==_CTRL_INFO)
{
Msg->hwndFrom=m_hWnd;
GetParent()->SendMessage(WM_NOTIFY,_CTRL_INFO,(LPARAM)Msg);
return TRUE;
}
return CWnd::OnNotify(wParam, lParam, pResult);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CPlateButton::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rect;
GetClientRect(rect);
int r;
r=min(rect.Width(),rect.Height())/2;
CPoint ptCenter=rect.CenterPoint();
int nTmp=BORDER_NUM/2;
for(int i=0;i<BORDER_NUM;i++)
{
m_ptBorder[i].x=(int)(cos(i*PI/nTmp)*r)+ptCenter.x;//
m_ptBorder[i].y=-(int)(sin(i*PI/nTmp)*r)+ptCenter.y; //BORDER_NUM/2
}
CRgn rgn;
rgn.CreatePolygonRgn(m_ptBorder,BORDER_NUM,WINDING);
SetWindowRgn(rgn,1);
ASSERT(m_arCaption.GetSize()==8);
m_sCaption=m_arCaption[0];
GetClientRect(rect);
CRect rLeftRect,rRightRect,rUpRect,rDownRect,rLeftDownRect,rRightDownRect,rCenterRect;
nTmp=BORDER_NUM/16;
//
rUpRect.right=m_ptBorder[3*nTmp-1].x-9;
rUpRect.left=rUpRect.right-22;
rUpRect.top=rect.top+5;
rUpRect.bottom=rUpRect.top+22;
//
rDownRect.right=m_ptBorder[13*nTmp+1].x-9;
rDownRect.left=rDownRect.right-22;
rDownRect.bottom=rect.bottom-5;
rDownRect.top=rDownRect.bottom-22;
//
rLeftRect.left=rect.left+9;
rLeftRect.right=rLeftRect.left+22;
rLeftRect.top=m_ptBorder[7*nTmp-12].y+8;
rLeftRect.bottom=rLeftRect.top+22;
//
rRightRect.right=rect.right-9;
rRightRect.left=rRightRect.right-22;
rRightRect.top=m_ptBorder[nTmp+12].y+8;
rRightRect.bottom=rRightRect.top+22;
//
rLeftDownRect.left=rect.left+9;
rLeftDownRect.right=rLeftDownRect.left+22;
rLeftDownRect.top=m_ptBorder[7*nTmp+12].y+8;
rLeftDownRect.bottom=rLeftDownRect.top+22;
//
rRightDownRect.right=rect.right-9;
rRightDownRect.left=rRightDownRect.right-22;
rRightDownRect.top=m_ptBorder[nTmp-12].y+8;
rRightDownRect.bottom=rRightDownRect.top+22;
//
rCenterRect.left=rect.CenterPoint().x-17;
rCenterRect.right=rect.CenterPoint().x+17;
rCenterRect.top=rect.CenterPoint().y-17;
rCenterRect.bottom=rect.CenterPoint().y+17;
//
m_wndUp.Create(m_arCaption[1],_UP_BUTTON,rUpRect,this,2003);
m_wndDown.Create(m_arCaption[2],_DOWN_BUTTON,rDownRect,this,2004);
m_wndLeft.Create(m_arCaption[3],_LEFT_BUTTON,rLeftRect,this,2005);
m_wndRight.Create(m_arCaption[5],_RIGHT_BUTTON,rRightRect,this,2006);
m_wndLeftDown.Create(m_arCaption[4],_LEFT_DOWN_BUTTON,rLeftDownRect,this,2007);
m_wndRightDown.Create(m_arCaption[6],_RIGHT_DOWN_BUTTON,rRightDownRect,this,2008);
m_wndCenter.Create(m_arCaption[7],rCenterRect,this,2009);
CreateTooltips();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateButton::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(rect);
/* CPen *pPenBorder,*pOldPen;
pPenBorder=new CPen(PS_SOLID,2,RGB(0,0,0));
pOldPen=dc.SelectObject(pPenBorder);
for(int i=0;i<BORDER_NUM-1;i++)
{
dc.MoveTo(m_ptBorder[i].x,m_ptBorder[i].y);
dc.LineTo(m_ptBorder[i+1].x,m_ptBorder[i+1].y);
}
dc.SelectObject(pOldPen);
delete pPenBorder;*/
}
//////////////////////////////////////
//
/////////////////////////////////////
void CPlateButton::CreateTooltips()
{
if (m_pToolTip == NULL)
{
CRect rect;
GetClientRect(rect);
m_pToolTip = new CToolTipCtrl;
if(!m_pToolTip)
{
MessageBox(_T("Unable to allocate memory for ToolTips!"));
}
else
{
if( !m_pToolTip->Create(this, TTS_ALWAYSTIP) )
{
MessageBox(_T("Unable to Create ToolTips for Grid!"));
}
else
{
m_pToolTip->AddTool(this, LPSTR_TEXTCALLBACK, rect, 1);
m_pToolTip->Activate(TRUE);
m_pToolTip->SendMessage(TTM_SETDELAYTIME,TTDT_AUTOPOP,30000);
EnableToolTips(TRUE);
}
}
}
}
////////////////////////////////////////
//
///////////////////////////////////////
BOOL CPlateButton::OnToolTipNotify(UINT id,NMHDR *pNMH, LRESULT *pResult)
{
LPTOOLTIPTEXT lpttt;
lpttt = (LPTOOLTIPTEXT)pNMH;
lpttt->szText[0] = '\0';
POINT ptCurrentPos;
GetCursorPos(&ptCurrentPos);
ScreenToClient(&ptCurrentPos);
m_rectSearch.SetRect(ptCurrentPos.x - 3,ptCurrentPos.y - 3,ptCurrentPos.x + 3,ptCurrentPos.y + 3);
strcpy(lpttt->szText,m_sCaption);
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -