// 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;
// Default type is "flat" button
m_bIsFlat = TRUE;
// By default draw border in "flat" button
m_bDrawBorder = TRUE;
// By default icon is aligned horizontally
m_nAlign = ST_ALIGN_HORIZ;
// By default show the text button
m_bShowText = TRUE;
// By default, for "flat" button, don't draw the focus rect
m_bDrawFlatFocus = FALSE;
SetDefaultInactiveBgColor();
SetDefaultInactiveFgColor();
SetDefaultActiveBgColor();
SetDefaultActiveFgColor();
} // End of CButtonST
CButtonST::~CButtonST()
{
// Destroy the icons (if any)
if (m_hIconIn != NULL) ::DeleteObject(m_hIconIn);
if (m_hIconOut != NULL) ::DeleteObject(m_hIconOut);
// Destroy the cursor (if any)
if (m_hCursor != NULL) ::DestroyCursor(m_hCursor);
} // 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, BYTE cx, BYTE cy)
{
HINSTANCE hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId),
RT_GROUP_ICON);
// Set icon when the mouse is IN the button
m_hIconIn = (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0);
// Set icon when the mouse is OUT the button
m_hIconOut = (nIconOutId == NULL) ? m_hIconIn : (HICON)::LoadImage(hInstResource/*AfxGetApp()->m_hInstance*/, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);
m_cxIcon = cx;
m_cyIcon = cy;
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.3";
} // End of GetVersionC
const short CButtonST::GetVersionI()
{
return 23; // 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(); // Thanks Ralph!
SetCapture();
Invalidate();
}
else
{
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(point))
{
// 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 our button is not flat then do nothing
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();
}
// Call base message handler
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)
{
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);
pDC->FillRect(&itemRect, &br);
// Disegno lo sfondo del bottone
//CBrush br(GetSysColor(COLOR_BTNFACE));
//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)
{
// Disegno i bordi a sinist
没有合适的资源?快使用搜索试试~ 我知道了~
CButtonST_demo.zip_DEMO_Davide Calabro_SoftechSoftware_softechso
共54个文件
ico:25个
h:8个
cpp:6个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 180 浏览量
2022-09-22
17:55:28
上传
评论
收藏 133KB ZIP 举报
温馨提示
MFC class for flat buttons. SoftechSoftware Davide Calabro davide_calabro@yahoo.com http://members.tripod.com/~SoftechSoftware/index.html
资源详情
资源评论
资源推荐
收起资源包目录
CButtonST_demo.zip (54个子文件)
AboutDlg.h 2KB
Globals.h 338B
CButtonST_demo.dsw 553B
HyperLink.h 3KB
Release
CButtonST_demo.exe 184KB
AboutDlg.cpp 3KB
CButtonST_demo.001 7KB
res
32x32x2_CancelBor.ico 2KB
32x32x16_Explore.ico 766B
32x32x16_Question.ico 766B
32x32x16_OkBor.ico 2KB
CButtonST_demo.ico 1KB
32x32x256_Hand.ico 2KB
32x32x16_CancelBor.ico 2KB
32x32x16_Right.ico 766B
32x32x256_Zip.ico 2KB
32x32x16_About.ico 766B
32x32x16_Left.ico 766B
32x32x256_Lamp.ico 2KB
32x32x16_Text.ico 766B
32x32x16_Exit.ico 766B
32x32x16_Cancel.ico 2KB
hand.cur 326B
32x32x256_Ok.ico 2KB
32x32x16_Info.ico 2KB
32x32x16_View.ico 766B
32x32x256_ZipSmall.ico 2KB
32x32x256_Cancel.ico 2KB
CButtonST_demo.rc2 406B
32x32x256_CDGold.ico 2KB
32x32x16_Ok.ico 2KB
32x32x2_Lamp.ico 2KB
32x32x16_Screw.ico 766B
32x32x2_OkBor.ico 2KB
CButtonST_Dlg.cpp 5KB
FILE_ID.DIZ 209B
CButtonST_demo.plg 2KB
CButtonST_demo.rc 8KB
CButtonST20_demo.clw 2KB
CButtonST_demo.clw 2KB
CButtonST_demo.ncb 57KB
BtnST.cpp 16KB
HyperLink.cpp 9KB
CButtonST.html 17KB
www.pudn.com.txt 218B
CButtonST_demo.opt 53KB
StdAfx.cpp 214B
resource.h 3KB
StdAfx.h 952B
CButtonST_demo.h 1KB
CButtonST_demo.dsp 7KB
CButtonST_demo.cpp 2KB
BtnST.h 6KB
CButtonST_Dlg.h 2KB
共 54 条
- 1
JaniceLu
- 粉丝: 98
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1