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

📄 iconbutton.cpp

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

#include "stdafx.h"
#include "GtMpeg.h"
#include "IconButton.h"
#include "ImageObject.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
CIconButton::CIconButton()
{
  m_MouseOnButton = FALSE;
  m_pToolTip = NULL;
  m_hIcon = 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();
  m_pBKObject=NULL;
} // End of CIconButton

CIconButton::~CIconButton()
{
	if (m_hIcon != NULL) ::DeleteObject(m_hIcon);
	if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
    if(m_pBKObject!=NULL)
	   delete m_pBKObject;
	if (m_pToolTip)
	{
        delete (m_pToolTip);
        m_pToolTip = NULL;
    }
} // End of ~CIconButton
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CIconButton, CButton)
    //{{AFX_MSG_MAP(CIconButton)
	ON_WM_CAPTURECHANGED()
	ON_WM_SETCURSOR()
	ON_WM_KILLFOCUS()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CIconButton::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 CIconButton::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 CIconButton::SetIcon(CString sCaption,CString sBKName,int nIconId)
{
   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();
} // End of SetIcon
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CIconButton::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 CIconButton::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 CIconButton::GetAlign()
{
  return m_nAlign;
} // End of GetAlign
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CIconButton::DrawBorder(BOOL bEnable)
{
  m_bDrawBorder = bEnable;
} // End of DrawBorder
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CIconButton::OnMouseMove(UINT nFlags, CPoint point)
{
  CWnd* pWnd;  // Finestra attiva
  CWnd* pParent; // Finestra che contiene il bottone

  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();
		Invalidate();
  }
  else
  {
    CRect rc;
    GetClientRect(&rc);
    if (!rc.PtInRect(point))
    {
      if (m_MouseOnButton == TRUE)
      {
        m_MouseOnButton = FALSE;
        Invalidate();
      }
      if (!(nFlags & MK_LBUTTON)) 
		  ReleaseCapture();
    }
  }*/
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CIconButton::OnKillFocus(CWnd * pNewWnd)
{
  CButton::OnKillFocus(pNewWnd);
  if (m_MouseOnButton == TRUE)
  {
    m_MouseOnButton = FALSE;
    Invalidate();
  }
} // End of OnKillFocus
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CIconButton::OnCaptureChanged(CWnd *pWnd) 
{
	if (m_MouseOnButton == TRUE)
	{
		ReleaseCapture();
		Invalidate();
	}
	CButton::OnCaptureChanged(pWnd);
} // End of OnCaptureChanged
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CIconButton::DrawItem(LPDRAWITEMSTRUCT lpDIS)

⌨️ 快捷键说明

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