⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platectrl.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 CPP
字号:
// PlateCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "GtMpegWnd.h"
#include "PlateCtrl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
CPlateCtrl::CPlateCtrl()
{
    WNDCLASS wndcls;
    HINSTANCE hInst = AfxGetResourceHandle();
    if (!(::GetClassInfo(hInst, "PlateCtrl", &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    = "PlateCtrl";
        if (!AfxRegisterClass(&wndcls)) 
            AfxThrowResourceException();
    }
	m_nStates=1;
	m_pToolTip = NULL;
}

CPlateCtrl::~CPlateCtrl()
{
	if (m_pToolTip)
	{
        delete (m_pToolTip);
        m_pToolTip = NULL;
    }
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CPlateCtrl, CWnd)
	//{{AFX_MSG_MAP(CPlateCtrl)
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	ON_WM_CREATE()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateCtrl::Create(CString sCaption,int nButtonType,CRect rect, CWnd* pParentWnd, UINT nID) 
{
	m_nButtonType=nButtonType;
	m_sCaption=sCaption;
	return CWnd::Create("PlateCtrl",NULL,WS_VISIBLE|WS_CHILD, rect, pParentWnd, nID);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPlateCtrl::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);
}
void CPlateCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
	if(MK_LBUTTON)
	{
	   CRect rect;
	   GetClientRect(rect);
	   if(!rect.PtInRect(point))
	   {
			if(m_nStates==-1)
			{
				ReleaseCapture();
				m_nStates=1;
				Invalidate();
				NMHDR Msg;
				Msg.hwndFrom=m_hWnd;
				switch(m_nButtonType)
				{
				   case _UP_BUTTON:
								  Msg.code=_PLATE_UP_STOP;
								  break;
				   case _LEFT_BUTTON:
								  Msg.code=_PLATE_LEFT_STOP;
								  break;
				   case _RIGHT_BUTTON:
								  Msg.code=_PLATE_RIGHT_STOP;
								  break;
				   case _DOWN_BUTTON:
								  Msg.code=_PLATE_DOWN_STOP;
								  break;
				   case _LEFT_DOWN_BUTTON:
								  Msg.code=_PLATE_LEFT_DOWN_STOP;
								  break;
				   case _RIGHT_DOWN_BUTTON:
								  Msg.code=_PLATE_RIGHT_DOWN_STOP;
								  break;
				}
				GetParent()->SendMessage(WM_NOTIFY,_CTRL_INFO,(LPARAM)&Msg);
			}
	   }
	}
	CWnd::OnMouseMove(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if(m_nStates==-1)
	{
        ReleaseCapture();
		m_nStates=1;
	    Invalidate();
		NMHDR Msg;
	    Msg.hwndFrom=m_hWnd;
		switch(m_nButtonType)
		{
		   case _UP_BUTTON:
                          Msg.code=_PLATE_UP_STOP;
						  break;
		   case _LEFT_BUTTON:
                          Msg.code=_PLATE_LEFT_STOP;
						  break;
		   case _RIGHT_BUTTON:
                          Msg.code=_PLATE_RIGHT_STOP;
						  break;
		   case _DOWN_BUTTON:
                          Msg.code=_PLATE_DOWN_STOP;
						  break;
           case _LEFT_DOWN_BUTTON:
                          Msg.code=_PLATE_LEFT_DOWN_STOP;
			              break;
		   case _RIGHT_DOWN_BUTTON:
                          Msg.code=_PLATE_RIGHT_DOWN_STOP;
			              break;
		}
        GetParent()->SendMessage(WM_NOTIFY,_CTRL_INFO,(LPARAM)&Msg);
	}
	CWnd::OnLButtonUp(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
	if(m_nStates==1)
	{
        SetCapture();
		m_nStates=-1;
	    Invalidate();
		NMHDR Msg;
	    Msg.hwndFrom=m_hWnd;
		switch(m_nButtonType)
		{
		   case _UP_BUTTON:
                          Msg.code=_PLATE_UP_START;
						  break;
		   case _LEFT_BUTTON:
                          Msg.code=_PLATE_LEFT_START;
						  break;
		   case _RIGHT_BUTTON:
                          Msg.code=_PLATE_RIGHT_START;
						  break;
		   case _DOWN_BUTTON:
                          Msg.code=_PLATE_DOWN_START;
						  break;
           case _LEFT_DOWN_BUTTON:
                          Msg.code=_PLATE_LEFT_DOWN_START;
			              break;
		   case _RIGHT_DOWN_BUTTON:
                          Msg.code=_PLATE_RIGHT_DOWN_START;
			              break;
		}
        GetParent()->SendMessage(WM_NOTIFY,_CTRL_INFO,(LPARAM)&Msg);
	}	
	CWnd::OnLButtonDown(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPlateCtrl::OnPaint() 
{
	CPaintDC dc(this);
	CRect rect;
	GetClientRect(rect);
	if(m_nStates==1)
	   dc.Draw3dRect(rect,RGB(255,255,255),RGB(0,0,0));
	else
	   dc.Draw3dRect(rect,RGB(0,0,0),RGB(255,255,255));
	CBitmap Bitmap;
	switch(m_nButtonType)
	{
	   case _LEFT_BUTTON:
		                     Bitmap.LoadBitmap(IDB_ZOON_IN);
							 break;
	   case _LEFT_DOWN_BUTTON:
		                     Bitmap.LoadBitmap(IDB_ZOON_OUT);
							 break;
       case _RIGHT_BUTTON:
		                     Bitmap.LoadBitmap(IDB_FOCUS_IN);
							 break;
       case _RIGHT_DOWN_BUTTON:
		                     Bitmap.LoadBitmap(IDB_FOCUS_OUT);
							 break;
       case _UP_BUTTON:
		                     Bitmap.LoadBitmap(IDB_IRIS_IN);
							 break;
       case _DOWN_BUTTON:
		                     Bitmap.LoadBitmap(IDB_IRIS_OUT);
							 break;
	}
	rect.DeflateRect(1,1); 
    APutImage(&dc,rect.left,rect.top,&Bitmap,RGB(255,255,255));
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CPlateCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	CRect rect;
	GetClientRect(rect);
	CreateTooltips();
	return 0;
}
//////////////////////////////////////
//
/////////////////////////////////////
void CPlateCtrl::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 CPlateCtrl::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 + -