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

📄 buttonst.cpp

📁 系统将动态实时的住宿登记、客房调整、销售报表、追加押金等有机地联系在一起
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ButtonST.cpp : implementation file
//

#include "stdafx.h"
#include "Myhotel.h"
#include "ButtonST.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CButtonST

CButtonST::CButtonST()
{
	 m_MouseOnButton = FALSE;

  m_hIconIn = NULL;
  m_hIconOut = NULL;
  m_cxIcon = 0;
  m_cyIcon = 0;
  m_hCursor = NULL;
  
  
  m_bIsFlat = TRUE; 
  
  
  m_bDrawBorder = TRUE; 
  
 
  m_nAlign = ST_ALIGN_HORIZ; 
  
 
  m_bShowText = TRUE; 
  
  
  m_bDrawFlatFocus = FALSE;

    m_bIsDefault = FALSE;
	
  SetDefaultInactiveBgColor();
  SetDefaultInactiveFgColor();
  SetDefaultActiveBgColor();
  SetDefaultActiveFgColor();


  m_ToolTip.m_hWnd=NULL;
  m_bDrawTransparent=FALSE;
  m_pbmpOldBK=NULL;


}

CButtonST::~CButtonST()
{
	
	if (m_dcBK.m_hDC!= NULL&&m_pbmpOldBK!=NULL) 
	{ m_dcBK.SelectObject(m_pbmpOldBK);}





	if (m_hIconIn != NULL) ::DeleteObject(m_hIconIn);
	if (m_hIconOut != NULL) ::DeleteObject(m_hIconOut);
	
	if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
}


BEGIN_MESSAGE_MAP(CButtonST, CButton)
	//{{AFX_MSG_MAP(CButtonST)
	ON_WM_CAPTURECHANGED()
	ON_WM_SETCURSOR()
	ON_WM_KILLFOCUS()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CButtonST message handlers
void CButtonST::SetIcon(int nIconInId, int nIconOutId, BYTE cx, BYTE cy)
{
	HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId),
													RT_GROUP_ICON);
	
	m_hIconIn = (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0);
  
	
	m_hIconOut = (nIconOutId == NULL) ? m_hIconIn : (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);
  

	ICONINFO ii;
	ZeroMemory(&ii,sizeof(ICONINFO));
	::GetIconInfo(m_hIconIn,&ii);
	m_cxIcon = (BYTE)(ii.xHotspot *2);
	m_cyIcon = (BYTE)(ii.yHotspot *2);
	RedrawWindow();
} // End of SetIcon


BOOL CButtonST::SetBtnCursor(int nCursorId)
{
	HINSTANCE hInstResource;
	// Destroy any previous cursor
	if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
	m_hCursor = NULL;

	// If we want a cursor
	if (nCursorId != -1)
	{
		hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId),
											RT_GROUP_CURSOR);
		// Load icon resource
		m_hCursor = (HCURSOR)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR, 0, 0, 0);
		// If something wrong then return FALSE
		if (m_hCursor == NULL) return FALSE;
	}

	return TRUE;
} // End of SetBtnCursor


void CButtonST::SetFlat(BOOL bState)
{
  m_bIsFlat = bState;
  Invalidate();
} // End of SetFlat


BOOL CButtonST::GetFlat()
{
  return m_bIsFlat;
} 


void CButtonST::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();
} 


int CButtonST::GetAlign()
{
  return m_nAlign;
} 


void CButtonST::DrawBorder(BOOL bEnable)
{
  m_bDrawBorder = bEnable;
} // End of DrawBorder


const char* CButtonST::GetVersionC()
{
  return "2.5";
} // End of GetVersionC


const short CButtonST::GetVersionI()
{
  return 25; 
} // End of GetVersionI


void CButtonST::SetShowText(BOOL bShow)
{
  m_bShowText = bShow;
  Invalidate();
} // End of SetShowText

BOOL CButtonST::GetShowText()
{
  return m_bShowText;
} // End of GetShowText

void CButtonST::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	 CWnd* pWnd;  // Finestra attiva
  CWnd* pParent; 

  CButton::OnMouseMove(nFlags, point);

 
   if (nFlags & MK_LBUTTON && m_MouseOnButton == FALSE) return;

 
   if (m_bIsFlat == FALSE) return;

  pWnd = GetActiveWindow();
  pParent = GetOwner();

	if ((GetCapture() != this) && 
		(
#ifndef ST_LIKEIE
		pWnd != NULL && 
#endif
		pParent != NULL)) 
	{
		m_MouseOnButton = TRUE;
		//SetFocus();	// Thanks Ralph!
		SetCapture();
		Invalidate();
	}
	else
  {
		POINT p2=point;
   
   ClientToScreen(&p2);
   CWnd *wndUnderMouse=WindowFromPoint(p2);
    if (wndUnderMouse!=this)
    {
      // Redraw only if mouse goes out
      if (m_MouseOnButton == TRUE)
      {
        m_MouseOnButton = FALSE;
        Invalidate();
      }
      // If user is NOT pressing left button then release capture!
      if (!(nFlags & MK_LBUTTON)) ReleaseCapture();
    }
  }
//	CButton::OnMouseMove(nFlags, point);
}

void CButtonST::OnKillFocus(CWnd* pNewWnd) 
{
	CButton::OnKillFocus(pNewWnd);
	 

  // If our button is not flat then do nothing
  
  if (m_bIsFlat == FALSE) return;

  if (m_MouseOnButton == TRUE)
  {
    m_MouseOnButton = FALSE;
    Invalidate();
  }
	// TODO: Add your message handler code here
	
}
void CButtonST::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
		if (m_MouseOnButton == TRUE)
	{
		ReleaseCapture();
		Invalidate();
	}

	// Call base message handler

	CButton::OnCaptureChanged(pWnd);
}

void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
#ifdef ST_USE_MEMDC
  CDC  *pdrawDC = CDC::FromHandle(lpDIS->hDC);
  CMemDC memDC(pdrawDC);
  CDC  *pDC = &memDC;
#else	
  CDC* pDC = CDC::FromHandle(lpDIS->hDC);
#endif

  CPen *pOldPen;
  BOOL bIsPressed  = (lpDIS->itemState & ODS_SELECTED);
  BOOL bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
  BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

  CRect itemRect = lpDIS->rcItem;

  if (m_bIsFlat == FALSE)
  {
    if (bIsFocused)
    {
      CBrush br(RGB(0,0,0));  
      pDC->FrameRect(&itemRect, &br);
      itemRect.DeflateRect(1, 1);
    }
  }

  // Prepare draw... paint button's area with background color
  COLORREF bgColor;
  if ((m_MouseOnButton == TRUE) || (bIsPressed))
    bgColor = GetActiveBgColor();
  else
    bgColor = GetInactiveBgColor();

  CBrush br(bgColor);
  if(m_bDrawTransparent==TRUE)
  {PaintBK(pDC);}
  else
  {
  pDC->FillRect(&itemRect, &br);
  }



  // Draw pressed button
  if (bIsPressed)
  {
    if (m_bIsFlat == TRUE)
    {
      if (m_bDrawBorder == TRUE)
      {
	    CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // Bianco
        CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Grigio scuro

        // Disegno i bordi a sinistra e in alto
        // Dark gray line
        pOldPen = pDC->SelectObject(&penBtnShadow);
        pDC->MoveTo(itemRect.left, itemRect.bottom-1);
        pDC->LineTo(itemRect.left, itemRect.top);
        pDC->LineTo(itemRect.right, itemRect.top);
        // Disegno i bordi a destra e in basso
        // White line
        pDC->SelectObject(penBtnHiLight);
        pDC->MoveTo(itemRect.left, itemRect.bottom-1);
        pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
        pDC->LineTo(itemRect.right-1, itemRect.top-1);
        //
        pDC->SelectObject(pOldPen);
      }
    }
    else    
    {
      CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
      pDC->FrameRect(&itemRect, &brBtnShadow);
    }
  }
  else // ...else draw non pressed button
  {
    CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
    CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT));       // Light gray
    CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Dark gray
    CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black

    if (m_bIsFlat == TRUE)
    {
      if (m_MouseOnButton == TRUE && m_bDrawBorder == TRUE)
      {
  	    

⌨️ 快捷键说明

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