📄 zgtools.h
字号:
///////////////////////////////////////////////////////////////////////////////
//
// Tools.h : header file
//
///////////////////////////////////////////////////////////////////////////////
#ifndef ZGTOOLS_H
#define ZGTOOLS_H
//////////////////////////////////////////////////////////////////////////
#define BUTTON_NORMAL 0
#define BUTTON_CHECKBOX 1
#define BUTTON_RADIOBOX 2
#define BUTTON_GROUPBOX 3
#define BUTTON_3STATE 4
///////////////////////////////////////////////////////////////////////////////
// Usefull macros
typedef DWORD HLSCOLOR;
#define HLS(h,l,s) ((HLSCOLOR)(((BYTE)(h)|((WORD)((BYTE)(l))<<8))|(((DWORD)(BYTE)(s))<<16)))
///////////////////////////////////////////////////////////////////////////////
#define HLS_H(hls) ((BYTE)(hls))
#define HLS_L(hls) ((BYTE)(((WORD)(hls)) >> 8))
#define HLS_S(hls) ((BYTE)((hls)>>16))
///////////////////////////////////////////////////////////////////////////////
HLSCOLOR RGB2HLS (COLORREF rgb);
COLORREF HLS2RGB (HLSCOLOR hls);
///////////////////////////////////////////////////////////////////////////////
// Performs some modifications on the specified color : luminance and saturation
COLORREF HLS_TRANSFORM (COLORREF rgb, int percent_L, int percent_S);
#ifndef lengthof
#define lengthof(a) (sizeof(a)/sizeof(a[0]))
#endif
/////////////////////////////////////////////////////////////////////////////
// Constants for detecting OS-Type
enum WinVer
{
wvUndefined,
wvWin32s,
wvWin95,
wvWin98,
wvWinME,
wvWinNT3,
wvWinNT4,
wvWin2000,
wvWinXP,
};
///////////////////////////////////////////////////////////////////////////////
// Return the current OS-Type
//
WinVer WINAPI GetWinVersion ();
void DrawShadow (HDC hDCIn, HDC hDCOut, RECT& rc);
void GradientFillRect(HDC hDC, CRect &rcFill, ULONG nMode, COLORREF crLeftTop, COLORREF crRightBottom);
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgClientRect : public CRect
{
public:
CZgClientRect (HWND hWnd)
{
::GetClientRect (hWnd, this);
};
CZgClientRect (const CWnd* pWnd)
{
::GetClientRect (pWnd->GetSafeHwnd(), this);
};
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgWindowRect : public CRect
{
public:
CZgWindowRect (HWND hWnd)
{
::GetWindowRect (hWnd, this);
};
CZgWindowRect (const CWnd* pWnd)
{
::GetWindowRect (pWnd->GetSafeHwnd(), this);
};
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgWindowText : public CString
{
public:
CZgWindowText (HWND hWnd)
{
CWnd::FromHandle (hWnd)->GetWindowText (*this);
};
CZgWindowText (const CWnd* pWnd)
{
pWnd->GetWindowText (*this);
};
};
//////////////////////////////////////////////////////////////////////////
class CZgMemDC : public CDC {
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_oldBitmap; // 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.
public:
CZgMemDC(CDC* pDC, const CRect* pRect = NULL) : CDC()
{
ASSERT(pDC != NULL);
// Some initialization
m_pDC = pDC;
m_oldBitmap = NULL;
m_bMemDC = !pDC->IsPrinting();
// Get the rectangle to draw
if (pRect == NULL) {
pDC->GetClipBox(&m_rect);
} else {
m_rect = *pRect;
}
if (m_bMemDC) {
// Create a Memory DC
CreateCompatibleDC(pDC);
pDC->LPtoDP(&m_rect);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_oldBitmap = SelectObject(&m_bitmap);
SetMapMode(pDC->GetMapMode());
SetWindowExt(pDC->GetWindowExt());
SetViewportExt(pDC->GetViewportExt());
pDC->DPtoLP(&m_rect);
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;
}
// Fill background
FillSolidRect(m_rect, pDC->GetBkColor());
}
~CZgMemDC()
{
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_oldBitmap);
m_bitmap.DeleteObject();
} 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
CZgMemDC* operator->()
{
return this;
}
// Allow usage as a pointer
operator CZgMemDC*()
{
return this;
}
};
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
class CZgBitmap : public CBitmap
{
public:
CZgBitmap();
virtual ~CZgBitmap();
BOOL LoadImage(LPCTSTR szImagePath, COLORREF crBack = 0);
BOOL LoadImage(UINT uIDRes, LPCTSTR szResourceType, HMODULE hInst = NULL, COLORREF crBack = 0);
BOOL LoadBitmap (UINT nIDResource)
{
return CBitmap::LoadBitmap(nIDResource);
}
// helpers
static BOOL GetResource(LPCTSTR lpName, LPCTSTR lpType, HMODULE hInst, void* pResource, int& nBufSize);
static IPicture* LoadFromBuffer(BYTE* pBuff, int nSize);
BOOL Draw( CDC *pDC, LPRECT r);
//draw sub bmp to special point
BOOL Draw( CDC *pDC, int x, int y, LPRECT sr );
BOOL Draw( CDC *pDC, int x, int y, LPRECT sr, COLORREF colTrans, BOOL bTrans );
BOOL StretchDraw(CDC *pDC, LPRECT tr, LPRECT sr );
BOOL StretchDraw(CDC *pDC, LPRECT r);
int Width() { return GetWidth(); }
int Height(){ return GetHeight();}
int GetWidth()
{
if (!GetSafeHandle())
return 0;
BITMAP bm;
memset( &bm, 0, sizeof(bm) );
GetBitmap(&bm);
return bm.bmWidth;
}
int GetHeight()
{
if (!GetSafeHandle())
return 0;
BITMAP bm;
memset( &bm, 0, sizeof(bm) );
GetBitmap(&bm);
return bm.bmHeight;
}
BOOL Attach(HBITMAP hbmp) { return CBitmap::Attach( hbmp );}
BOOL LoadBitmap(LPCTSTR szFilename)
{
ASSERT(szFilename);
DeleteObject();
return LoadImage( szFilename );
}
BOOL DrawTransparent(CDC * pDC, int x, int y, COLORREF crColour);
HRGN CreateRgnFromFile( COLORREF color );
static void ZgTransparentBlt( HDC hdcDest, int nXDest, int nYDest, int nWidth,
int nHeight, HBITMAP hBitmap, int nXSrc, int nYSrc,
COLORREF colorTransparent, HPALETTE hPal );
protected:
BOOL Attach(IPicture* pPicture, COLORREF crBack);
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgPenDC
{
protected:
CPen m_pen;
HDC m_hDC;
HPEN m_hOldPen;
public:
CZgPenDC (CDC *pDC, COLORREF crColor = CLR_NONE);
~CZgPenDC ();
void Color (COLORREF crColor);
COLORREF Color () const;
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgBrushDC
{
protected:
CBrush m_brush;
HDC m_hDC;
HBRUSH m_hOldBrush;
public:
CZgBrushDC (CDC *pDC, COLORREF crColor = CLR_NONE);
~CZgBrushDC ();
void Color (COLORREF crColor);
COLORREF Color () const;
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgFontDC
{
protected:
HFONT m_hFont;
HDC m_hDC;
HFONT m_hDefFont;
COLORREF m_crTextOld;
public:
CZgFontDC (CDC *pDC, LPCTSTR sFaceName, COLORREF crText = CLR_DEFAULT);
CZgFontDC (CDC *pDC, BYTE nStockFont, COLORREF crText = CLR_DEFAULT);
CZgFontDC (CDC *pDC, HFONT hFont, COLORREF crText = CLR_DEFAULT);
~CZgFontDC ();
const CZgFontDC& operator = (LPCTSTR sFaceName);
const CZgFontDC& operator = (BYTE nStockFont);
const CZgFontDC& operator = (HFONT hFont);
const CZgFontDC& operator = (COLORREF crText);
};
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
class CZgBoldDC
{
protected:
CFont m_fontBold;
HDC m_hDC;
HFONT m_hDefFont;
public:
CZgBoldDC (CDC *pDC, bool bBold);
~CZgBoldDC ();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -