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

📄 pushbutton.cpp

📁 一个完整的数字硬盘录像机系统软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PushButton.cpp : implementation file
//

#include "stdafx.h"
#include "GtMpeg.h"
#include "PushButton.h"
#include "ImageObject.h"
#include "IconButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////
// CPushButton
////////////////////////////////////
CPushButton::CPushButton()
{
  m_hIcon = NULL;
  m_pBKObject=NULL;
  m_pToolTip = NULL;
  m_MouseOnButton = FALSE;
  m_pToolTip = NULL;
  m_cxIcon = 0;
  m_cyIcon = 0;
  m_hCursor = NULL;
  m_bDrawBorder = TRUE; 
  m_nAlign = ST_ALIGN_HORIZ; 
  m_bDrawFlatFocus = FALSE;
  SetDefaultInactiveBgColor();
  SetDefaultInactiveFgColor();
  SetDefaultActiveBgColor();
  SetDefaultActiveFgColor();
}

CPushButton::~CPushButton()
{
	if (m_hIcon != NULL) ::DeleteObject(m_hIcon);
	if(m_pBKObject!=NULL)
		delete m_pBKObject;
	if (m_pToolTip)
	{
        delete (m_pToolTip);
        m_pToolTip = NULL;
    }
}
///////////////////////////////////////////////
//
///////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CPushButton, CButton)
	//{{AFX_MSG_MAP(CPushButton)
	ON_WM_ERASEBKGND()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::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 CPushButton::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;

}
//////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
void CPushButton::SetIcon(CString sCaption,int nIconID,CString sBKName)
{
   CreateTooltips();
   m_sCaption=sCaption;
   ASSERT(m_sCaption!="");
   if(nIconID!=0)
   {
	HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconID),RT_GROUP_ICON);
	m_hIcon = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconID), IMAGE_ICON, 0, 0, 0);
	m_cxIcon = 32;
	m_cyIcon = 32;
   }
   CFileFind Find;
   if(Find.FindFile(sBKName)!=0)
   {
     m_pBKObject=new CImageObject(sBKName);
   }
   RedrawWindow();
}
//////////////////////////////////////////////////
//
//////////////////////////////////////////////////
BOOL CPushButton::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 CButton::PreTranslateMessage(pMsg);
}
//////////////////////////////////////////////////
//
//////////////////////////////////////////////////
void CPushButton::OnLButtonDown(UINT nFlags, CPoint point) 
{
    NMHDR Msg;
	Msg.hwndFrom=m_hWnd;
	Msg.code=_CONTROL_START;
    GetParent()->SendMessage(WM_NOTIFY,GetDlgCtrlID(),(LPARAM)&Msg);
	CButton::OnLButtonDown(nFlags, point);
}
//////////////////////////////////////////////////
//
//////////////////////////////////////////////////
void CPushButton::OnLButtonUp(UINT nFlags, CPoint point) 
{
    NMHDR Msg;
	Msg.hwndFrom=m_hWnd;
	Msg.code=_CONTROL_STOP;
    GetParent()->SendMessage(WM_NOTIFY,GetDlgCtrlID(),(LPARAM)&Msg);
	CButton::OnLButtonUp(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CPushButton::SetBtnCursor(int nCursorId)
{
	HINSTANCE hInstResource;
	if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
	m_hCursor = NULL;
	if (nCursorId != -1)
	{
		hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId),RT_GROUP_CURSOR);
		m_hCursor = (HCURSOR)::LoadImage(hInstResource, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);
		if (m_hCursor == NULL) return FALSE;
	}
	return TRUE;
} // End of SetBtnCursor
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::SetAlign(int nAlign)
{
  switch (nAlign)
  {    
    case ST_ALIGN_HORIZ:
         m_nAlign = ST_ALIGN_HORIZ;
         break;
    case ST_ALIGN_VERT:
         m_nAlign = ST_ALIGN_VERT;
         break;
  }
  Invalidate();
} // End of SetAlign
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CPushButton::GetAlign()
{
  return m_nAlign;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::DrawBorder(BOOL bEnable)
{
  m_bDrawBorder = bEnable;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CPushButton::OnMouseMove(UINT nFlags, CPoint point)
{
  CWnd* pWnd;
  CWnd* pParent;
  CButton::OnMouseMove(nFlags, point);
  if (nFlags & MK_LBUTTON && m_MouseOnButton == FALSE) 
	  return;
  pWnd = GetActiveWindow();
  pParent = GetOwner();
  if ((GetCapture() != this) && 
		(
#ifndef ST_LIKEIE
		pWnd != NULL && 
#endif
		pParent != NULL)) 
  {
		m_MouseOnButton = TRUE;
		SetCapture();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -