#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_bIsPressed = FALSE;
m_bIsFocused = FALSE;
m_bIsDisabled = FALSE;
m_bMouseOnButton = FALSE;
FreeResources(FALSE);
// 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, for "flat" button, don't draw the focus rect
m_bDrawFlatFocus = FALSE;
// By default the button is not the default button
m_bIsDefault = FALSE;
// By default the button is not a checkbox
m_bIsCheckBox = FALSE;
m_nCheck = 0;
// Set default colors
SetDefaultColors(FALSE);
// No tooltip created
m_ToolTip.m_hWnd = NULL;
// Do not draw as a transparent button
m_bDrawTransparent = FALSE;
m_pbmpOldBk = NULL;
// No URL defined
::ZeroMemory(&m_szURL, sizeof(m_szURL));
// No cursor defined
m_hCursor = NULL; // Fix by kawasaki@us.dnttm.ro
// No autorepeat
m_bAutoRepeat = FALSE;
m_hWndAutoRepeat = NULL;
m_nMsgAutoRepeat = WM_APP;
m_dwPeriodAutoRepeat = 100;
} // End of CButtonST
CButtonST::~CButtonST()
{
// Restore old bitmap (if any)
if (m_dcBk.m_hDC != NULL && m_pbmpOldBk != NULL)
{
m_dcBk.SelectObject(m_pbmpOldBk);
}
FreeResources();
// 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()
ON_WM_SYSCOLORCHANGE()
ON_CONTROL_REFLECT_EX(BN_CLICKED, OnClicked)
ON_WM_ACTIVATE()
ON_WM_ENABLE()
ON_WM_CANCELMODE()
ON_WM_CTLCOLOR_REFLECT()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
DWORD CButtonST::SetIcon(int nIconInId, int nIconOutId)
{
HICON hIconIn;
HICON hIconOut;
HINSTANCE hInstResource;
// Find correct resource handle
hInstResource = AfxFindResourceHandle(MAKEINTRESOURCE(nIconInId), RT_GROUP_ICON);
// Set icon when the mouse is IN the button
hIconIn = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconInId), IMAGE_ICON, 0, 0, 0);
// Set icon when the mouse is OUT the button
hIconOut = (HICON)::LoadImage(hInstResource, MAKEINTRESOURCE(nIconOutId), IMAGE_ICON, 0, 0, 0);
return SetIcon(hIconIn, hIconOut);
} // End of SetIcon
DWORD CButtonST::SetIcon(HICON hIconIn, HICON hIconOut)
{
BOOL bRetValue;
ICONINFO ii;
// Free any loaded resource
FreeResources();
if (hIconIn != NULL)
{
m_csIcons[0].hIcon = hIconIn;
// Get icon dimension
ZeroMemory(&ii, sizeof(ICONINFO));
bRetValue = ::GetIconInfo(hIconIn, &ii);
if (bRetValue == FALSE)
{
FreeResources();
return BTNST_INVALIDRESOURCE;
} // if
m_csIcons[0].dwWidth = (DWORD)(ii.xHotspot * 2);
m_csIcons[0].dwHeight = (DWORD)(ii.yHotspot * 2);
::DeleteObject(ii.hbmMask);
::DeleteObject(ii.hbmColor);
if (hIconOut != NULL)
{
m_csIcons[1].hIcon = hIconOut;
// Get icon dimension
ZeroMemory(&ii, sizeof(ICONINFO));
bRetValue = ::GetIconInfo(hIconOut, &ii);
if (bRetValue == FALSE)
{
FreeResources();
return BTNST_INVALIDRESOURCE;
} // if
m_csIcons[1].dwWidth = (DWORD)(ii.xHotspot * 2);
m_csIcons[1].dwHeight = (DWORD)(ii.yHotspot * 2);
::DeleteObject(ii.hbmMask);
::DeleteObject(ii.hbmColor);
} // if
} // if
RedrawWindow();
return BTNST_OK;
} // 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 != NULL)
{
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:
case ST_ALIGN_HORIZ_RIGHT:
case ST_ALIGN_VERT:
m_nAlign = nAlign;
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
void CButtonST::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd* pWnd; // Active window
CWnd* pParent; // Window that owns the button
CButton::OnMouseMove(nFlags, point);
// If the mouse enter the button with the left button pressed then do nothing
if (nFlags & MK_LBUTTON && m_bMouseOnButton == 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_bMouseOnButton = TRUE;
//SetFocus(); // Thanks Ralph!
SetCapture();
Invalidate();
} // if
else
{
/*
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(point))
{
*/
POINT p2 = point;
ClientToScreen(&p2);
CWnd* wndUnderMouse = WindowFromPoint(p2);
// if (wndUnderMouse != this)
if (wndUnderMouse && wndUnderMouse->m_hWnd != this->m_hWnd)
{
// Redraw only if mouse goes out
if (m_bMouseOnButton == TRUE)
{
m_bMouseOnButton = FALSE;
Invalidate();
} // if
// If user is NOT pressing left button then release capture!
if (!(nFlags & MK_LBUTTON)) ReleaseCapture();
} // if
} // else
} // End of OnMouseMove
void CButtonST::OnKillFocus(CWnd * pNewWnd)
{
CButton::OnKillFocus(pNewWnd);
CancelHover();
} // End of OnKillFocus
void CButtonST::OnLButtonDown(UINT nFlags, CPoint point)
{
CButton::OnLButtonDown(nFlags, point);
if (m_bAutoRepeat == TRUE)
{
MSG csMsg;
int nButtonID;
HWND hWndParent;
BOOL bInitialState = TRUE;
nButtonID = GetDlgCtrlID();
hWndParent = GetParent()->GetSafeHwnd();
SetCapture();
while (PeekMessage(&csMsg, m_hWnd, WM_LBUTTONUP, WM_LBUTTONUP, PM_REMOVE) == FALSE)
{
::SendMessage(hWndParent, WM_COMMAND, MAKEWPARAM((WORD)nButtonID, BN_CLICKED), (LPARAM)m_hWnd);
::Sleep(m_dwPeriodAutoRepeat);
bInitialState = !bInitialState;
} // while
if (!bInitialState)
{
::SendMessage(hWndParent, WM_COMMAND, MAKEWPARAM((WORD)nButtonID, BN_CLICKED), (LPARAM)m_hWnd);
} // if
ReleaseCapture();
SendMessage(WM_LBUTTONUP);
CPoint ptCursor;
GetCursorPos(&ptCursor);
ScreenToClient(&ptCursor);
SendMessage(WM_MOUSEMOVE, 0, MAKELPARAM(ptCursor.x, ptCursor.y));
} // if
} // End of OnLButtonDown
void CButtonST::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CButton::OnActivate(nState, pWndOther, bMinimized);
if (nState == WA_INACTIVE) CancelHover();
} // End of OnActivate
void CButtonST::OnEnable(BOOL bEnable)
{
CButton::OnEnable(bEnable);
if (bEnable == FALSE) CancelHover();
} // End of OnEnable
void CButtonST::OnCancelMode()
{
CButton::OnCancelMode();
CancelHover();
} // End of OnCancelMode
void CButtonST::OnCaptureChanged(CWnd *pWnd)
{
if (m_bMouseOnButton == TRUE)
{
ReleaseCapture();
Invalidate();
} // if
CButton::OnCaptureChanged(pWnd);
} // End of OnCaptureChanged
void
没有合适的资源?快使用搜索试试~ 我知道了~
ButtonST.zip_BMPbutton PUDN
共84个文件
ico:37个
h:16个
cpp:15个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2022-09-21
19:47:08
上传
评论
收藏 430KB ZIP 举报
温馨提示
带特效的Button控件,可以添加图片、URL、根据事件动态改变显示
资源推荐
资源详情
资源评论
收起资源包目录
ButtonST.zip (84个子文件)
ButtonST
HyperLink.h 4KB
BackgroundUtil.h 512B
Release
DlgAdvanced.cpp 3KB
CButtonST_Demo.ncb 97KB
DlgTransparent.cpp 3KB
res
Winzip1.ico 2KB
Help2_32x32x256.ico 2KB
Left2_32x32x16.ico 766B
Ok1_32x32x16.ico 2KB
Search2.ico 2KB
Ok4_32x32x2.ico 2KB
Winzip2.ico 2KB
Tools4.ico 2KB
Cancel1_32x32x16.ico 2KB
Workgroup.ico 7KB
Open.ico 2KB
EOapp.ico 2KB
Sky.bmp 176KB
CDRom.ico 2KB
LedOff.ico 318B
Razor_32x32x256.ico 2KB
Hand.cur 326B
Help.ico 2KB
Explorer.ico 2KB
About.ico 2KB
Cancel3_32x32x256.ico 2KB
Run.ico 2KB
JPEG Image.ico 7KB
Eagle.bmp 36KB
Face.bmp 20KB
Palette.bmp 28KB
Baloon.ico 2KB
Lamp1.ico 2KB
Lamp2.ico 2KB
Ok3_32x32x256.ico 2KB
Sound.ico 2KB
Cannibal.bmp 8KB
CButtonST_Demo.ico 1KB
Halloween1.ico 2KB
CButtonST_Demo.rc2 406B
STLogo_Small.bmp 12KB
BmpBack.bmp 5KB
IEDocument_48x48x256.ico 4KB
Right2_32x32x16.ico 766B
Key manager.ico 4KB
Web2.ico 2KB
LogOff.ico 4KB
Halloween2.ico 2KB
Cancel4_32x32x2.ico 2KB
Search1.ico 2KB
LedOn.ico 318B
DlgAbout.cpp 1KB
MyTabCtrl.h 1KB
CButtonST_Demo.clw 5KB
DlgShadeButtonST.cpp 3KB
MyTabCtrl.cpp 3KB
DlgBasic.h 1KB
CButtonST_Demo.aps 424KB
DlgAbout.h 895B
ShadeButtonST.h 749B
DlgTransparent.h 1KB
xDib.h 2KB
BtnST.cpp 31KB
CButtonST_DemoDlg.h 1KB
HyperLink.cpp 14KB
CButtonST_Demo.rc 12KB
CButtonST_Demo.dsw 551B
StdAfx.cpp 216B
resource.h 4KB
DlgShadeButtonST.h 964B
CButtonST_Demo.opt 51KB
StdAfx.h 999B
CButtonST_Demo.h 933B
DlgAdvanced.h 1KB
CButtonST_Demo.cpp 974B
BkDialog.cpp 1KB
BackgroundUtil.cpp 3KB
DlgBasic.cpp 3KB
BtnST.h 6KB
ShadeButtonST.cpp 7KB
CButtonST_DemoDlg.cpp 2KB
xDib.cpp 15KB
CButtonST_Demo.dsp 11KB
BkDialog.h 1KB
共 84 条
- 1
资源评论
局外狗
- 粉丝: 69
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功