📄 painthelper.hpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#pragma once
#ifndef __PAINTHELPER_HPP__
#define __PAINTHELPER_HPP__
#include <windows.h>
#include <auto_xxx.hxx>
class Bitmap_t
{
public:
Bitmap_t();
~Bitmap_t();
bool operator!();
operator HBITMAP();
HRESULT
Attach(
HBITMAP Bitmap
);
HRESULT
LoadBitmap(
HINSTANCE Instance,
UINT ResourceId
);
int
Height(
void
);
int
Width(
void
);
private:
ce::auto_hbitmap m_Bitmap;
int m_Width;
int m_Height;
bool m_IsAttached;
};
class PaintHelper_t
{
public:
PaintHelper_t();
~PaintHelper_t();
PaintHelper_t& operator=(
PaintHelper_t& Source
);
operator HDC();
HRESULT
Attach(
HDC hdc
);
HRESULT
Begin(
HWND hwnd
);
void
End(
void
);
HRESULT
CreateCanvas(
HWND hwnd,
int Width = 0,
int Height = 0
);
HRESULT
DrawText(
const WCHAR* pText,
int TextLength,
__in const RECT* pRect,
DWORD StyleFlags
);
RECT&
Rect(
void
);
HBITMAP
SetBitmap(
HBITMAP bitmap
);
void
SetBkColor(
COLORREF color
);
void
SetBkMode(
int BkMode
);
void
SetBrush(
HBRUSH brush
);
void
SetFont(
HFONT font
);
void
SetPen(
HPEN pen
);
void
SetTextColor(
COLORREF color
);
HRESULT
TileBlt(
__in Bitmap_t* pBitmap3x3Tiles,
__in const RECT* pDestinationRect,
__in_opt const RECT* pSourceRect,
int cxLeft,
int cyTop,
int cxRight,
int cyBottom,
COLORREF TransparentColor
);
static
HRESULT
CalculateTextDimensions(
__in const WCHAR* pText,
int TextLength,
HFONT FontToBeUsed,
__inout RECT* pRectangle,
UINT DrawTextFlags
);
private:
static const DWORD CANVAS_CREATED;
DWORD m_Flags;
ce::auto_hdc m_hdc;
ce::auto_hbitmap m_Bitmap;
int m_OldBkMode;
HBRUSH m_OldBrush;
HFONT m_OldFont;
HPEN m_OldPen;
COLORREF m_OldBkColor;
COLORREF m_OldTextColor;
HBITMAP m_OldBitmap;
PAINTSTRUCT m_PaintStruct;
HWND m_hwnd;
};
#endif // !defined __PAINTHELPER_HPP__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -