//***************************************************************************
// Filename: Btn.cpp
// Description:
//
// Copyright: Copyright (C) 2002 by negerns
//***************************************************************************
// Date: 4 Aug 2002 18:02
// Author: negerns
//***************************************************************************
// DISCLAIMER
// This software and the accompanying files are distributed "as is" and
// without any warranties whether expressed or implied. No responsibilities
// for possible damages or even functionality can be taken. The user must
// assume the entire risk of using this source code.
//***************************************************************************
#include "VISUALPBNI.H"
//#include "stdafx.h"
#include "Btn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//***************************************************************************
// CBtn Construction/Destruction
CBtn::CBtn()
{
m_hIcon = NULL;
m_dwIconWidth = 0;
m_dwIconHeight = 0;
m_clrBtnPressed = m_clrBtnUnpressed = ::GetSysColor(COLOR_BTNFACE);
m_clrTextPressed = m_clrTextUnpressed = ::GetSysColor(COLOR_BTNTEXT);
m_bIsPressed = FALSE;
m_bIsHovering = FALSE;
m_bHasDD = FALSE;
m_bHasBorder = TRUE;
/*
// Create the CFont = Arial 8pt Bold
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 14;
lf.lfWeight = FW_NORMAL; //FW_BOLD;
strcpy(lf.lfFaceName, "Arial");
m_cfFont.CreateFontIndirect(&lf);
*/
}
CBtn::~CBtn()
{
// Destroy icon
if (m_hIcon) ::DestroyIcon(m_hIcon);
::ZeroMemory(&m_hIcon, sizeof(m_hIcon));
m_cfFont.DeleteObject();
::ZeroMemory(&m_cfFont, sizeof(m_cfFont));
}
BEGIN_MESSAGE_MAP(CBtn, CButton)
//{{AFX_MSG_MAP(CBtn)
ON_WM_MOUSEMOVE()
ON_WM_NCDESTROY()
ON_WM_SYSCOLORCHANGE()
ON_WM_LBUTTONUP()
ON_WM_KEYUP()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
END_MESSAGE_MAP()
//***************************************************************************
// CBtn message handlers
void CBtn::SetPBSession(IPB_Session* session, pbobject pbobj)
{
m_pIPB_Session = session;
m_pbobj = pbobj;
}
void CBtn::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT csTME;
CButton::OnMouseMove(nFlags, point);
ClientToScreen(&point);
CRect rc;
GetWindowRect(rc);
if (rc.PtInRect(point))
// Check if the mouse is currently over our control
//if(WindowFromPoint(point)->m_hWnd == m_hWnd)
{
// We need only set the hovering flag if it is not yet set
if (!m_bIsHovering)
{
// Set our hovering flag then redraw
m_bIsHovering = TRUE;
Invalidate();
// Post a WM_MOUSELEAVE message
csTME.cbSize = sizeof(csTME);
csTME.dwFlags = TME_LEAVE;
csTME.hwndTrack = m_hWnd;
::_TrackMouseEvent(&csTME);
}
}
else
{
m_bIsHovering = FALSE;
Invalidate();
}
}
LRESULT CBtn::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
// When the mouse leaves our control, set the flag and redraw
m_bIsHovering = FALSE;
Invalidate();
return 0;
}
void CBtn::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CRect rc = lpDIS->rcItem;
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);
m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);
m_bHasFocus = (lpDIS->itemState & ODS_FOCUS);
// Draw the control
OnDrawBorder(pDC, rc);
// If there's an icon, draw it
if (m_hIcon != NULL) OnDrawIcon(pDC, rc);
OnDrawText(pDC, rc);
// Draw the focus rect
if (m_bHasFocus) {
rc.DeflateRect(3, 3);
if (m_bHasDD) rc.right -= DDBTNWIDTH;
pDC->DrawFocusRect(rc);
}
}
void CBtn::PreSubclassWindow()
{
// Set initial control type
m_nStyle = GetButtonStyle() & BS_PUSHBUTTON;
// WARNING: Do not set the OwnerDraw before PreSubclassWindow().
// Do not use the resource editor's OwnerDraw or ModifyStyle(0, BS_OWNERDRAW)
ASSERT(m_nStyle != BS_OWNERDRAW);
ModifyStyle(0, BS_OWNERDRAW, SWP_FRAMECHANGED);
CButton::PreSubclassWindow();
// Set the text font
// Create the font
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
// Arial ht = 14
// Tahoma ht = 13
lf.lfHeight = 14;
lf.lfWeight = FW_NORMAL;
strcpy(lf.lfFaceName, "Arial");
m_cfFont.CreateFontIndirect(&lf);
SetFont(&m_cfFont);
}
LRESULT CBtn::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// Double click = 2 single clicks
if (message == WM_LBUTTONDBLCLK) message = WM_LBUTTONDOWN;
return CButton::DefWindowProc(message, wParam, lParam);
}
DWORD CBtn::OnDrawBorder(CDC* pDC, CRect rc)
//***************************************************************************
// Description: Draw the control border according to the current state.
// Parameter: CDC* pDC - Drawing context.
// CRect rc - Coordinates to draw the border.
// Return Value:
// Author: negerns
// Created: 27 Jul 2002 23:57
//***************************************************************************
{
// What color is the background color?
// This is the code for highlighting the button.
// TODO: Do this?
/*
if (m_bIsHovering) {
const double factor = 0.8;
COLORREF col = ::GetSysColor(COLOR_BTNFACE);
if (factor > 0.0 && factor <= 1.0) {
BYTE red,green,blue,lightred,lightgreen,lightblue;
red = GetRValue(col);
green = GetGValue(col);
blue = GetBValue(col);
lightred = (BYTE)((factor*(255-red)) + red);
lightgreen = (BYTE)((factor*(255-green)) + green);
lightblue = (BYTE)((factor*(255-blue)) + blue);
col = RGB(lightred,lightgreen,lightblue);
}
pDC->FillSolidRect(rc, (m_bIsPressed ? col : col));
}
else
pDC->FillSolidRect(rc, (m_bIsPressed ? m_clrBtnPressed : m_clrBtnUnpressed));
*/
pDC->FillSolidRect(rc, (m_bIsPressed ? m_clrBtnPressed : m_clrBtnUnpressed));
if (m_bIsPressed)
pDC->DrawEdge(rc, EDGE_SUNKEN, BF_RECT);
else
pDC->DrawEdge(rc, (m_bIsHovering ? EDGE_RAISED : EDGE_ETCHED), BF_RECT);
// Draw the split
if (m_bHasDD) {
CRect rectSplit(rc);
rectSplit.DeflateRect(2, 2);
rectSplit.right -= DDBTNWIDTH; // left offset for the splitter
CPen brShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
pDC->SelectObject(&brShadow);
pDC->MoveTo(rectSplit.right, rectSplit.top);
pDC->LineTo(rectSplit.right, rectSplit.bottom);
CPen brHiLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
pDC->SelectObject(&brHiLight);
pDC->MoveTo(rectSplit.right + 1, rectSplit.top);
pDC->LineTo(rectSplit.right + 1, rectSplit.bottom);
rectSplit.left = rectSplit.right;
rectSplit.right += DDBTNWIDTH;
CPoint pt(rectSplit.CenterPoint());
pt += CPoint(0, 1);
CPen brTextColor(PS_SOLID, 1, m_bIsDisabled ?
GetSysColor(COLOR_GRAYTEXT) : GetSysColor(COLOR_WINDOWTEXT));
pDC->SelectObject(&brTextColor);
DrawArrow(pDC, pt);
}
return 0;
}
DWORD CBtn::OnDrawIcon(CDC* pDC, CRect rc)
//***************************************************************************
// Description: Draw the control icon according to the current state.
// Parameter: CDC* pDC - Drawing context.
// CRect rc - Coordinates to draw the icon.
// Return Value:
// Author: negerns
// Created: 27 Jul 2002 23:57
//***************************************************************************
{
// Move the icon a bit to the right and center it vertically
rc.left = 5;
rc.top += ((rc.Height() - m_dwIconHeight) / 2);
if (m_bIsPressed) rc.OffsetRect(1, 1);
pDC->DrawState(rc.TopLeft(), rc.Size(), m_hIcon, (m_bIsDisabled ? DSS_DISABLED : DSS_NORMAL), (CBrush*)NULL);
return 0;
}
DWORD CBtn::OnDrawText(CDC* pDC, CRect rc)
//***************************************************************************
// Description: Draw the control text according to the current state.
// Parameter: CDC* pDC - Drawing context.
// CRect rc - Coordinates to draw the text.
// Retu
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
VisualPBNI Src.rar (36个子文件)
VisualPBNI Src
VisualPBNI.dsw 545B
VisualPBNI.aps 17KB
VisualPBNI.opt 48KB
VisualPBNI.rc 3KB
VisualPBNI.dsp 5KB
VisualPBNI.clw 568B
PBNIButton.H 3KB
visualpbni.pbd 8KB
VISUALPBNI.pbx 1.25MB
VISUALPBNI.H 1KB
VISUALPBNI.CPP 3KB
StdAfx.cpp 212B
resource.h 414B
PBNIButton.CPP 5KB
StdAfx.h 1KB
Dist
visualpbni.pbd 8KB
VISUALPBNI.pbx 1.25MB
Btn.h 3KB
VisualPBNI.ncb 89KB
Btn.cpp 14KB
Debug
StdAfx.obj 10KB
PBNIButton.sbr 1.07MB
VISUALPBNI.exp 757B
Btn.obj 44KB
vc60.idb 153KB
VISUALPBNI.obj 23KB
VISUALPBNI.ilk 1.65MB
VISUALPBNI.dll 1.28MB
StdAfx.sbr 1007KB
VISUALPBNI.lib 2KB
PBNIButton.obj 31KB
vc60.pdb 100KB
VisualPBNI.res 884B
Btn.sbr 1.07MB
VISUALPBNI.sbr 1.07MB
VisualPBNI.plg 2KB
共 36 条
- 1
资源评论
- Methodor2014-07-10过于简单单调了点,随便看看即可
- ahcorelax2014-05-24其实我想找的如何在程序中访问其他程序,这里还是没有找到相关启示。
C++实习生
- 粉丝: 1935
- 资源: 863
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功