232 lines
7.2 KiB
C++
232 lines
7.2 KiB
C++
#if !defined(AFX_LUBUTTON_H__FACBC3B8_6B84_11D4_ABB9_5254AB103C4E__INCLUDED_)
|
|
#define AFX_LUBUTTON_H__FACBC3B8_6B84_11D4_ABB9_5254AB103C4E__INCLUDED_
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
// LuButton.h : header file
|
|
//
|
|
|
|
|
|
#include <gdiplus.h>
|
|
using namespace Gdiplus;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// LuButton window
|
|
#pragma comment(lib, "winmm.lib") //加入播放声音用到的lib
|
|
|
|
#define LUBUTTON_FLASHTIME 500 //定义按扭闪动的时间
|
|
|
|
class LuButton : public CButton
|
|
{
|
|
// Construction
|
|
public:
|
|
LuButton();
|
|
|
|
// Attributes
|
|
public:
|
|
|
|
// Operations
|
|
public:
|
|
|
|
// Overrides
|
|
// ClassWizard generated virtual function overrides
|
|
//{{AFX_VIRTUAL(LuButton)
|
|
public:
|
|
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
|
|
virtual BOOL PreTranslateMessage(MSG* pMsg);
|
|
protected:
|
|
virtual void PreSubclassWindow();
|
|
//}}AFX_VIRTUAL
|
|
|
|
// Implementation
|
|
public:
|
|
void SetHandBmp( BOOL bTrue );
|
|
void SetHandBmp( HBITMAP hBmp);
|
|
BOOL SetWindowRgnFromBmp(UINT uiBmp, COLORREF cTransparentColor = 0 , COLORREF cTolerance = 0x101010);
|
|
void SetMainWin(CWnd * pWnd);
|
|
void PaintBk(CDC * pDC);
|
|
BOOL SetWindowRgnFromBmp(HBITMAP hBmp, COLORREF cTransparentColor = 0 , COLORREF cTolerance = 0x101010);
|
|
long SetDHTime( long lDHTime );
|
|
long SetTransBKColor( COLORREF rgbColor );
|
|
BOOL SetTransBK(BOOL bTransBk = true);
|
|
void DrawBitmap(CDC* pDC, int x, int y, int width, int height, CBitmap* pBmp);
|
|
void DrawTransparentBitmap(CDC * pDC,int x,int y,CBitmap * pBmp,COLORREF crColor);
|
|
BOOL SetFlash(long lFlashTimer , long lFlashCount, BOOL bFlash = true);
|
|
BOOL SetClickBmp(UINT nIDResource );
|
|
BOOL SetClickBmp(LPCTSTR lpszResourceName );
|
|
BOOL SetFlatBmp(UINT nIDResource );
|
|
BOOL SetFlatBmp(LPCTSTR lpszResourceName );
|
|
BOOL SetDisableBmp(UINT nIDResource);
|
|
BOOL SetDisableBmp(LPCTSTR lpszResourceName );
|
|
BOOL SetSoundFileName( TCHAR * szFile );
|
|
BOOL SetSound( bool bSound );
|
|
BOOL GetFlat();
|
|
BOOL SetFlat( BOOL bFlat = true );
|
|
BOOL SetUnSelBmp(UINT nIDResource);
|
|
BOOL SetUnSelBmp(LPCTSTR lpszResourceName );
|
|
long AddButtonBmp( UINT nIDResource );
|
|
long AddButtonBmp( LPCTSTR lpszResourceName );
|
|
BOOL GetButtonSel( );
|
|
BOOL SetButtonSel( BOOL bSelect );
|
|
BOOL SetUnSelToolTip( TCHAR * szText );
|
|
BOOL ActiveToolTip( bool bActive );
|
|
BOOL SetSelTooltip( TCHAR * szText );
|
|
virtual ~LuButton();
|
|
void LuButton::FreeBitmapData();
|
|
// Generated message map functions
|
|
protected:
|
|
//{{AFX_MSG(LuButton)
|
|
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
|
afx_msg void OnTimer(UINT_PTR nIDEvent);
|
|
afx_msg void OnKillFocus(CWnd* pNewWnd);
|
|
afx_msg void OnCaptureChanged(CWnd *pWnd);
|
|
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
|
//}}AFX_MSG
|
|
|
|
DECLARE_MESSAGE_MAP()
|
|
private:
|
|
BOOL m_bSelect; //用于此按扭是否被选中
|
|
BOOL m_bFlat; //此按扭是否是浮动的
|
|
BOOL m_bFlash; //此按扭是否在闪动
|
|
|
|
long m_lBmpCount; //所加入图片的总数
|
|
long m_lNowBmp; //如果是被选中,现在显示的图片
|
|
long m_lMaxBmp; //最大能加入的图片数,跟据以下m_bmpX决定
|
|
long m_lFlashCount; //窗口闪动计数
|
|
long m_lMaxFlashCount;//最大的窗口计数,当其为0时代码不计数
|
|
long m_lFlashTime; //闪动的间隔时间
|
|
long m_lDHTime; //动画闪动的间隔时间
|
|
|
|
CBitmap m_bmp1; //这此是用于显示动画的
|
|
CBitmap m_bmp2;
|
|
CBitmap m_bmp3;
|
|
CBitmap m_bmp4;
|
|
CBitmap m_bmp5;
|
|
CBitmap m_unBmp; //没有初始被选中的bmp
|
|
BOOL m_bUnBmp; //是否已设了unBmp
|
|
CBitmap m_FlatBmp; //当鼠标在扭按上时显示的bmp
|
|
BOOL m_bFlatBmp;
|
|
CBitmap m_DisBmp; //扭按被Disabled时显示的bmp
|
|
BOOL m_bDisBmp;
|
|
CBitmap m_ClickBmp; //鼠标按下时显示的bmp
|
|
BOOL m_bClickBmp;
|
|
BOOL m_bMouseOnButton;//鼠标是否在按扭之上
|
|
BOOL m_bTransBk; //是否显示透明位图
|
|
long m_RGBTrans; //画透明位图时需要去掉的背景色
|
|
|
|
CToolTipCtrl m_ToolTip; //用于显示按扭的提示信息
|
|
TCHAR m_szSelTip[ 256];//选中时显示的提示
|
|
TCHAR m_szUnSelTip[256];//不被选中时显示的提示
|
|
|
|
BOOL m_bSound; //鼠标移动上面时是否响声音
|
|
TCHAR m_szSoundFile[256];//声音文件名.wav
|
|
|
|
CDC m_dcBk; //为画背景而作
|
|
CBitmap m_bmpBk;
|
|
CBitmap* m_pbmpOldBk;
|
|
CWnd * m_pMainWnd;
|
|
|
|
|
|
BOOL m_bHandBmp; //直接从HBITMAP中绘制
|
|
BOOL m_bHandBmp2;
|
|
HBITMAP m_hHandBmp;
|
|
|
|
ULONG_PTR m_gdiplusToken;
|
|
Bitmap* m_pBitmap;
|
|
|
|
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
//{{AFX_INSERT_LOCATION}}
|
|
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
|
|
|
//modify by lujiang
|
|
#ifndef _MEMDC_H_
|
|
#define _MEMDC_H_
|
|
|
|
//////////////////////////////////////////////////
|
|
// CMemDC - memory DC
|
|
//
|
|
// Author: Keith Rule
|
|
// Email: keithr@europa.com
|
|
// Copyright 1996-1997, Keith Rule
|
|
//
|
|
// You may freely use or modify this code provided this
|
|
// Copyright is included in all derived versions.
|
|
//
|
|
// History - 10/3/97 Fixed scrolling bug.
|
|
// Added print support.
|
|
// 25 feb 98 - fixed minor assertion bug
|
|
//
|
|
// This class implements a memory Device Context
|
|
|
|
class CMemDC2 : public CDC
|
|
{
|
|
public:
|
|
|
|
// constructor sets up the memory DC
|
|
CMemDC2(CDC* pDC) : CDC()
|
|
{
|
|
ASSERT(pDC != NULL);
|
|
|
|
m_pDC = pDC;
|
|
m_pOldBitmap = NULL;
|
|
m_bMemDC = !pDC->IsPrinting();
|
|
|
|
if (m_bMemDC) // Create a Memory DC
|
|
{
|
|
pDC->GetClipBox(&m_rect);
|
|
CreateCompatibleDC(pDC);
|
|
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
|
|
m_pOldBitmap = SelectObject(&m_bitmap);
|
|
SetWindowOrg(m_rect.left, m_rect.top);
|
|
}
|
|
else // Make a copy of the relevent parts of the current DC for printing
|
|
{
|
|
m_bPrinting = pDC->m_bPrinting;
|
|
m_hDC = pDC->m_hDC;
|
|
m_hAttribDC = pDC->m_hAttribDC;
|
|
}
|
|
}
|
|
|
|
// Destructor copies the contents of the mem DC to the original DC
|
|
~CMemDC2()
|
|
{
|
|
if (m_bMemDC)
|
|
{
|
|
// Copy the offscreen bitmap onto the screen.
|
|
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
|
|
this, m_rect.left, m_rect.top, SRCCOPY);
|
|
|
|
//Swap back the original bitmap.
|
|
SelectObject(m_pOldBitmap);
|
|
} else {
|
|
// All we need to do is replace the DC with an illegal value,
|
|
// this keeps us from accidently deleting the handles associated with
|
|
// the CDC that was passed to the constructor.
|
|
m_hDC = m_hAttribDC = NULL;
|
|
}
|
|
}
|
|
|
|
// Allow usage as a pointer
|
|
CMemDC2* operator->() {return this;}
|
|
|
|
// Allow usage as a pointer
|
|
operator CMemDC2*() {return this;}
|
|
|
|
private:
|
|
CBitmap m_bitmap; // Offscreen bitmap
|
|
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
|
|
CDC* m_pDC; // Saves CDC passed in constructor
|
|
CRect m_rect; // Rectangle of drawing area.
|
|
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
|
|
};
|
|
|
|
#endif //add by lujiang
|
|
|
|
|
|
#endif // !defined(AFX_LUBUTTON_H__FACBC3B8_6B84_11D4_ABB9_5254AB103C4E__INCLUDED_)
|