📄 platecenterctrl.cpp
字号:
// PlateCenterCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "GtMpegWnd.h"
#include "PlateCenterCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
CPlateCenterCtrl::CPlateCenterCtrl()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetResourceHandle();
if (!(::GetClassInfo(hInst, "PlateCenterCtrl", &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 = "PlateCenterCtrl";
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();
}
m_nStates=1;
m_pToolTip = NULL;
}
CPlateCenterCtrl::~CPlateCenterCtrl()
{
if (m_pToolTip)
{
delete (m_pToolTip);
m_pToolTip = NULL;
}
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CPlateCenterCtrl, CWnd)
//{{AFX_MSG_MAP(CPlateCenterCtrl)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateCenterCtrl::Create(CString sCaption,CRect rect, CWnd* pParentWnd, UINT nID)
{
m_sCaption=sCaption;
return CWnd::Create("PlateCenterCtrl",NULL,WS_VISIBLE|WS_CHILD, rect, pParentWnd, nID);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateCenterCtrl::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);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CPlateCenterCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CreateTooltips();
return 0;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateCenterCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
if(m_nStates==1)
{
m_nStates=-1;
Invalidate();
NMHDR Msg;
Msg.hwndFrom=m_hWnd;
Msg.code=_PLATE_START;
GetParent()->SendMessage(WM_NOTIFY,_CTRL_INFO,(LPARAM)&Msg);
}
CWnd::OnLButtonDown(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateCenterCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_nStates==-1)
{
m_nStates=1;
Invalidate();
NMHDR Msg;
Msg.hwndFrom=m_hWnd;
Msg.code=_PLATE_STOP;
GetParent()->SendMessage(WM_NOTIFY,_CTRL_INFO,(LPARAM)&Msg);
}
CWnd::OnLButtonUp(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateCenterCtrl::OnPaint()
{
CPaintDC dc(this);
CRect Rect;
GetClientRect(Rect);
Rect.DeflateRect(1,1);
CBitmap Bitmap;
if(m_nStates==1)
Bitmap.LoadBitmap(IDB_PLATE_1);
else
Bitmap.LoadBitmap(IDB_PLATE_2);
APutImage(&dc,Rect.left,Rect.top,&Bitmap,RGB(255,0,0));
}
//////////////////////////////////////
//
/////////////////////////////////////
void CPlateCenterCtrl::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 CPlateCenterCtrl::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 + -