VC++按钮控件

  • G2_531979
    了解作者
  • 79.4KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-06 08:54
    上传日期
按钮控件按钮控件按钮控件
按钮控件.rar
  • 按钮控件
  • CButtonST_demo
  • RES
  • 32x32x16_Cancel.ico
    2.2KB
  • 32x32x16_CancelBor.ico
    2.2KB
  • 32x32x256_Cancel.ico
    2.2KB
  • 32x32x16_About.ico
    766B
  • 32x32x16_Info.ico
    2.2KB
  • 32x32x16_Question.ico
    766B
  • 32x32x256_Hand.ico
    2.2KB
  • 32x32x256_Lamp.ico
    2.2KB
  • 32x32x16_Text.ico
    766B
  • CButtonST_demo.ico
    1.1KB
  • 32x32x256_CDGold.ico
    2.2KB
  • 32x32x256_Zip.ico
    2.2KB
  • 32x32x2_CancelBor.ico
    2.2KB
  • 32x32x16_OkBor.ico
    2.2KB
  • 32x32x256_Ok.ico
    2.2KB
  • 32x32x16_Right.ico
    766B
  • 32x32x2_Lamp.ico
    2.2KB
  • HAND.CUR
    326B
  • CButtonST_demo.rc2
    406B
  • 32x32x256_Baloon.ico
    2.2KB
  • 32x32x16_Explore.ico
    766B
  • 32x32x16_View.ico
    766B
  • 32x32x16_Left.ico
    766B
  • 32x32x16_Screw.ico
    766B
  • 32x32x16_Ok.ico
    2.2KB
  • 32x32x16_Exit.ico
    766B
  • 32x32x256_ZipSmall.ico
    2.2KB
  • 32x32x2_OkBor.ico
    2.2KB
  • BtnST.h
    5.5KB
  • CButtonST_demo.sln
    917B
  • CButtonST_demo.vcproj
    9.3KB
  • CButtonST_Dlg.h
    1.9KB
  • CButtonST_demo.aps
    84.8KB
  • CButtonST_demo.cpp
    1.8KB
  • CButtonST_demo.plg
    1.2KB
  • CButtonST_demo.rc
    7.6KB
  • RESOURCE.H
    2.8KB
  • FILE_ID.DIZ
    212B
  • AboutDlg.h
    1.5KB
  • Globals.h
    338B
  • CButtonST_demo.ncb
    59KB
  • CButtonST_Dlg.cpp
    5KB
  • StdAfx.cpp
    214B
  • BtnST.cpp
    17.3KB
  • HyperLink.h
    2.7KB
  • CButtonST_demo.h
    1.3KB
  • CButtonST_demo.dsw
    553B
  • CButtonST_demo.suo
    8KB
  • CButtonST_demo.opt
    56.5KB
  • CButtonST_demo.clw
    2.3KB
  • StdAfx.h
    952B
  • AboutDlg.cpp
    3.4KB
  • CButtonST_demo.dsp
    6.8KB
  • HyperLink.cpp
    8.9KB
内容介绍
// BtnST.cpp : implementation file #include "stdafx.h" #include "BtnST.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; } // End of CButtonST CButtonST::~CButtonST() { // 恢复原来的位图 if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL) { m_dcBk.SelectObject(m_pbmpOldBk); } } // End of ~CButtonST 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() void CButtonST::SetIcon(int nIconInId, int nIconOutId) { 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; } // End of GetFlat 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(); } // End of SetAlign int CButtonST::GetAlign() { return m_nAlign; } // End of GetAlign 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; // Divide by 10 to get actual version } // 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) { CWnd* pWnd; // Finestra attiva CWnd* pParent; // Finestra che contiene il bottone CButton::OnMouseMove(nFlags, point); // If the mouse enter the button with the left button pressed // then do nothing if (nFlags & MK_LBUTTON && m_MouseOnButton == FALSE) return; // If our button is not flat then do nothing if (m_bIsFlat == FALSE) return; pWnd = GetActiveWindow(); pParent = GetOwner(); if ((GetCapture() != this) && ( #ifndef ST_LIKEIE pWnd != NULL && #endif pParent != NULL)) { m_MouseOnButton = TRUE; //SetFocus(); SetCapture(); Invalidate(); } else { /* CRect rc; GetClientRect(&rc); if (!rc.PtInRect(point)) { */ 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(); } } } // End of OnMouseMove void CButtonST::OnKillFocus(CWnd * pNewWnd) { CButton::OnKillFocus(pNewWnd); // 若按钮不为平面按钮,则返回 if (m_bIsFlat == FALSE) return; if (m_MouseOnButton == TRUE) { m_MouseOnButton = FALSE; Invalidate(); } } // End of OnKillFocus void CButtonST::OnCaptureChanged(CWnd *pWnd) { if (m_MouseOnButton == TRUE) { ReleaseCapture(); Invalidate(); } // 调用基类消息处理函数 CButton::OnCaptureChanged(pWnd); } // End of OnCaptureChanged 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 || (GetDefault() == TRUE)) { CBrush br(RGB(0,0,0)); pDC->FrameRect(&itemRect, &br); itemRect.DeflateRect(1, 1); } } // 用背景颜色绘制按钮 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); } //绘制处于“按下”状态的按钮 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 // 暗灰线 pOldPen = pDC->SelectObject(&penBtnShadow); pDC->MoveTo(itemRect.left, itemRect.bottom-1); pDC->LineTo(itemRect.left, itemRect.top); pDC->LineTo(itemRect.right, itemRect.top); // 白线 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 // 不绘制处于“按下”状态的按钮 { 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) { // 白线 pOldPen = pDC->SelectObject(&penBtnHiLight); pDC->MoveTo(itemRect.left, itemRect.bo
评论
    相关推荐
    • C++ Primer
      C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。 对C++基本概念和技术全面而且权威的阐述,对...
    • c++课件
      c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件
    • C++ PRrimer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • C++
      C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
    • C++ primer
      本文档具有C++ primer 以及 C++ primer 标准答案各一份,内容清晰充实!希望与热爱C++的学友们一起同舟共济,努力学习!
    • C++ primer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • c++yuyanbiancheng
      这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!
    • effective C++
      有关C++编程方面的检验性介绍,对由C转向C++,和有C++编程基础的程序员有帮助,不过是英文版
    • C++ Primer
      这本处适合各个阶段的C++程序员,这本书可以帮助初学者快速入门,里面有最实用,最容易理解的代码;同时这也是有经验的C++程序员最好的一本参考手册
    • C++ Primer
      本书是久负盛名的C++经典教程引,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++