📄 keyboard.h
字号:
#if !defined(AFX_KEYBOARD_H__INCLUDED_)
#define AFX_KEYBOARD_H__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// KeyBoard.h : header file
//
/////////////////////////////////////////////////////////////////////////////
#include <afxtempl.h>
#include <math.h>
//按键类型
#define KEY_RECTANGLE 0 //矩形按键 ,颜色为线性梯度变化
#define KEY_ROUNDRECT 1 //圆角矩形按键,颜色为线性梯度变化
#define KEY_SPHERE 2 //球面按键 ,颜色为球面梯度变化
#define KEY_CIRCLE 3 //倒边圆形按键,颜色为线性梯度变化
#define KEY_3DRECTANGLE 4 //3D矩形按键 ,颜色为线性梯度变化
#define KEY_CUSTOM 100 //自定义按键 ,
//按键按下时的类型
#define KDF_DEFAULT 0 //平面 ,颜色无梯度变化
#define KDF_OFFSET 1 //键下移 ,边界亮度变黑
#define KDF_LIGHTDARK 2 //边有梯度内为底亮度
#define KDF_SHALLOW 3 //键洼陷 ,颜色梯度反向变化
#define KDF_HATCHBRUSH 0x10000 //格式刷 ,带网格(按键颜色)
#define KDM_WM_KEYDOWN 0x1 //键按下
#define KDM_WM_KEYUP 0x2 //键抬起
#define KDM_WM_CHAR 0x4 //字符
#define KDM_WM_NULL 0x0 //
#define KDM_CB_KEYDOWN 0x10000 //键按下
#define KDM_CB_KEYUP 0x20000 //键抬起
#define KDM_CB_CHAR 0x40000 //字符
union NumericType // Declare a union that can hold the following:
{
long lV; // int value
float fV; // float value
};
typedef struct tagKEYINFO {
CRect m_rectRegion; //1, store rect of region 存放按键区域矩形
char m_char; //2, key value 键值
COLORREF m_KeyColor; //3, key color 键颜色
// Key Text Property
// 按键文字属性
CString m_KeyName; //4, key text 按键文本
COLORREF m_TextColor; //5, text color 文本颜色
int m_TextSize; //6, text size , auto calculate for 0
// 文本尺寸 ,尺寸为0,自动计算
BOOL m_bSingleRow; //7, true for single line 单行文本
UINT m_nFormat; //8, aligns text 对齐方式
// key type; 按键类型
int m_KeyMode; //9, key type
// 0-矩形,1-圆角矩形,2--球面,3--圆形
// Sphere 球面
int m_iSphereRadius; //10, Sphere Radius 球面键的球面半径
// 当按键类型3d Rect(Round rect) 时, 0 为边界为单色 ,>0 边界为梯度颜色
int m_iKeyDownRadius; //11 Sphere Radius for key down 键按下时球面半径
// round rectangle & rectangle
// 圆角和矩形按键
int m_iKeyChamferWidth; //12 gradient width 倒角宽度
float m_fLightReduceRate; //13 luminance reduce Rate 亮度衰减率
float m_fKeyDownReduceRate; //14 when key down, luminance reduce Rate
// 键按下时亮度衰减率
// round rectangle
// 圆角按键
int m_iRoundRadius; //15 Round Radius
// 圆角矩形圆角半径
//key status 按键状态属性
DWORD m_dwMessage; //16 低字为传递消息用 0 无消息,1-KEYDOWN,2-KEYUP,4-CHAR
// 高字节回调函数用 0 无消息,1-KEYDOWN,2-KEYUP,4-CHAR
BOOL m_bKeyDown; //17 TRUE for key down ,FAULSE for key up 按键状态
BOOL m_bLockedKey; //18 TRUE for locked key,FAULSE for unloced key 锁定按键
DWORD m_iKeyDownType; //19 key down type 0--颜色梯度变,1-平面(按纽颜色),2-格式刷,4-外框有颜色
COLORREF m_LKDownBorderColor; //20 borderline color when key down 按键按下时边界颜色,=0 时无边框
tagKEYINFO()
{
m_rectRegion=CRect(0,0,1,1);
m_char='\0';
m_KeyColor=0xff;
// Key Text Property
m_KeyName="";
m_TextColor=0xFFFFFF;
m_TextSize=0;
m_bSingleRow=true;
m_nFormat=DT_VCENTER ;
// key type
m_KeyMode=0;
// Sphere
m_iSphereRadius=10;
m_iKeyDownRadius=9;
// round rectangle & rectangle
m_iKeyChamferWidth=3;
m_fLightReduceRate=float(0.8);
m_fKeyDownReduceRate=float(0.6);
// round rectangle
m_iRoundRadius=3;
//key status
m_bKeyDown=false;
m_bLockedKey=false;
m_iKeyDownType=KDF_DEFAULT;
m_LKDownBorderColor=RGB(255,0,0);
m_dwMessage=KDM_WM_NULL;
}
}KEYINFO,*LPKEYINFO;
class CKeyInfo
{
public:
void GetKeyInfo(LPKEYINFO lpKeyInfo);
void SetKeyInfo(LPKEYINFO lpKeyInfo);
CKeyInfo(LPKEYINFO lpKeyInfo);
CKeyInfo();
virtual ~CKeyInfo();
// --------------------------------
// Attributes
// --------------------------------
KEYINFO m_KeyInfo;
};
typedef CArray<CKeyInfo, CKeyInfo> arrKeyInfo; // A Collection of Key Infos
/////////////////////////////////////////////////////////////////////////////
// CKeyBoard window
const int FONT_SIZE_DEC=2;
//typedef void (*funcptr)();
typedef void ( CALLBACK * lpProgram )(HWND hWnd, UINT nMessage,WPARAM wParam , LPARAM lParam = 0);
typedef void ( CALLBACK * lpOnPaint)(HWND hWnd,CDC *pDC,CRect & rect , DWORD dwData = 0);
typedef void ( CALLBACK * lpDrawItem)(HWND hWnd,CDC *pDC,CRect & rect,UINT nItem, BOOL bKeyDown,DWORD itemData = 0);
class AFX_EXT_CLASS CKeyBoard : public CStatic
{
// Construction
public:
CKeyBoard();
// Attributes
private:
CSize m_Size;
CBitmap * m_pBitmap; //内存位图
CBitmap *m_pOldBitmap;
CDC * m_pMemDC; //内存CDC
BOOL bReDraw; //重画标志
int m_min;
HCURSOR m_hHandCur;
BOOL m_bMouseIn; //鼠标进入按键标志
CWnd * m_pPostWnd;//接受消息的窗口类指针
arrKeyInfo m_arrKeyInfo;//键属性数组
lpProgram lProgram;
DWORD m_lParam; //保存处理回调函数的窗口指针
lpOnPaint pOnPaint;
lpDrawItem pDrawItem;
DWORD m_dwData ; //保存处理自画函数的窗口指针
LOGFONT logfont; //内部使用
LOGBRUSH logBrush;
public:
//底板属性
int m_BaseBoardChamferWidth; //底板倒角宽度
COLORREF m_BaseBoardChamferColor;//底板倒角颜色
COLORREF m_BaseBoardColor;//底板颜色
BOOL m_bHaveBaseBoard;
BOOL m_b3DText;
BOOL m_bCustomDraw;
//键名文字属性
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CKeyBoard)
public:
protected:
//}}AFX_VIRTUAL
// Implementation
public:
void DrawKeyDownEllipse(CDC *pDC, CRect &rect, COLORREF color1, COLORREF color2, int width, DWORD dwKeyDownMode);
void SetCustomDrawCallBack(void * pPaint, void *pDItem, DWORD dwData);
void SetKeyDown(char chr,BOOL bValue);
void SetKeyBoardSize(CSize &size);
void RemoveAllKeyInfo();
void AddKeyInfo(LPKEYINFO pKeyInfo);
void SetCallBack(void * lPrg, DWORD lParam);
static short GetVersionI() {return 10;}
static LPCTSTR GetVersionC() {return (LPCTSTR)_T("1.0");}
void SetRedraw();
void SetReceiveMessageWnd(CWnd *pWnd);
virtual ~CKeyBoard();
private:
//
void DrawKeyboard();
void DrawAllKey();
void DrawText();
void DrawEnterPic(CDC *pDC,CRect &rect,COLORREF cr);
void DrawRoundRect(CDC *pDC,CRect &rect,int radius,COLORREF color1,COLORREF color2,int width,BOOL bLocked=false);
void DrawKeyDownRoundRect(CDC *pDC, CRect &rect, int radius, COLORREF color1, COLORREF color2, int width, DWORD dwKeyDownMode);
void DrawSphere(CDC*pDC,CRect rect,COLORREF color,int light_radius);
void DrawDownSphere(CDC *pDC, CRect rect, COLORREF color, int light_radius,DWORD dwKeyDownMode);
void DrawColorEllipse(CDC *pDC,CRect &rect,COLORREF color1,COLORREF color2,int width);
void DrawButton();
void Draw3dRect(CDC *pDC, CRect rect, COLORREF LTColor,COLORREF MColor, COLORREF RBColor,int iWidth, int iGradient ,DWORD dwKeyDownMode,BOOL bDrawKeydown=false);
void DrawColorRect(CDC *pDC, CRect &rect, COLORREF color,int width ,float light_dec);
void DrawColorRect(CDC *pDC, CRect &rect, COLORREF color1, COLORREF color2,int width);
void DrawKeyDownRect(CDC *pDC, CRect &rect, COLORREF color1, COLORREF color2, int width, DWORD dwKeyDownMode);
// Generated message map functions
protected:
//{{AFX_MSG(CKeyBoard)
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_KEYBOARD_H__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -