中国象棋控件 2.0.15
载入中...
搜索中...
未找到
ChineseChessView.h
1// 作者:康林 <kl222@126.com>
2
3#pragma once
4
5#include "ChineseChess.h"
6
7#ifdef CHINESE_CHESS_USE_PNG
8 #include<atlimage.h>
9#endif
10
11class AFX_EXT_CLASS CChineseChessHandler
12{
13public:
16
31 virtual int OnGoChess(int i, int j, CPiece::ENUM_QiZi chess) = 0;
32};
33
34class AFX_EXT_CLASS CChineseChessView : public CView, public CChineseChess
35{
36 DECLARE_DYNAMIC(CChineseChessView)
37
38public:
40 virtual ~CChineseChessView();
41 void AboutBox();
42
43 int SetQiPangColor(COLORREF col);
44 COLORREF GetQiPangColor();
45 int SetTiShiBoxColor(COLORREF col);
46 COLORREF GetTiShiBoxColor();
47 virtual int SaveChessGame(LPCTSTR pszFile);
48 virtual int LoadChessGame(LPCTSTR pszFile);
49 virtual int SetRedName(LPCTSTR pszName);
50 virtual int SetBlackName(LPCTSTR pszName);
51 virtual int AddGameTag(LPCTSTR pszTag, LPCTSTR szVal);
52 CString GetGameTag(LPCTSTR szTag);
53
54 int SetChineseChessHandler(CChineseChessHandler* handler);
55
56protected:
57 DECLARE_MESSAGE_MAP()
58 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
59 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
60 afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
61 afx_msg void OnSize(UINT nType, int cx, int cy);
62 virtual void OnDraw(CDC* pDC);
63
64protected:
65 virtual int onPromptSound(PROMPT_SOUND sound);
66 virtual int onPromptMessage(CGoRule::ENUM_ReturnValue val);
67
68 virtual int onCleanPrompt(int i, int j);
69 virtual int onDrawPrompt(int i, int j);
70 virtual int onGoChess(int i, int j, CPiece::ENUM_QiZi chess);
71
72private:
73 LONG m_QiPangStartX; //棋盘的开始横坐标
74 LONG m_QiPangStartY; //棋盘的开始横坐标
75 LONG m_QiPangDistance; //棋盘格的距离
76
77 COLORREF m_QiPangColor;
78 COLORREF m_TiShiBoxColor;
79
80
81 //楚河汉界
82 CBitmap m_Chu;
83 CBitmap m_He;
84 CBitmap m_Han;
85 CBitmap m_Jie;
86 CBitmap m_Copyright;
87
88#ifdef CHINESE_CHESS_USE_PNG
89 ATL::CImage m_QiPangPicture; //棋盘背景图片
90
91 //棋子图片
92 ATL::CImage m_RedShuai; //红帅
93 ATL::CImage m_RedShi; //红仕
94 ATL::CImage m_RedXiang; //红相
95 ATL::CImage m_RedMa; //红马
96 ATL::CImage m_RedChe; //红车
97 ATL::CImage m_RedBing; //红兵
98 ATL::CImage m_RedPao; //红炮
99
100 ATL::CImage m_BlackShuai; //黑帅
101 ATL::CImage m_BlackShi; //黑仕
102 ATL::CImage m_BlackXiang; //黑相
103 ATL::CImage m_BlackMa; //黑马
104 ATL::CImage m_BlackChe; //黑车
105 ATL::CImage m_BlackBing; //黑兵
106 ATL::CImage m_BlackPao; //黑炮
107#else
108 CBitmap m_QiPangPicture; //棋盘背景图片
109
110 //棋子图片
111 CBitmap m_RedShuai; //红帅
112 CBitmap m_RedShi; //红仕
113 CBitmap m_RedXiang; //红相
114 CBitmap m_RedMa; //红马
115 CBitmap m_RedChe; //红车
116 CBitmap m_RedBing; //红兵
117 CBitmap m_RedPao; //红炮
118
119 CBitmap m_BlackShuai; //黑帅
120 CBitmap m_BlackShi; //黑仕
121 CBitmap m_BlackXiang; //黑相
122 CBitmap m_BlackMa; //黑马
123 CBitmap m_BlackChe; //黑车
124 CBitmap m_BlackBing; //黑兵
125 CBitmap m_BlackPao; //黑炮
126#endif
127
128#ifdef CHINESE_CHESS_USE_PNG
129 // 从资源中加载图片到 CImage
130 BOOL LoadImageFromResource(ATL::CImage *pImage, UINT ID, LPCTSTR pType = _T("PNG"));
131 BOOL LoadImageFromResource(ATL::CImage *pImage, LPCTSTR pID, LPCTSTR pType = _T("PNG"));
132#endif
133
134 //坐标转换
135 enum ENUM_ConvertCoordinate { XYToIJ, IJToXY };
136 BOOL ConvertCoordinate(long *x, long *y, int *i, int *j, ENUM_ConvertCoordinate eCC = XYToIJ);
137
138 //棋盘星位
139 enum ENUM_XINWEI { XinWei, Left_XinWei, Right_XinWei };
140 void DrawXinWei(CDC *pdc, int i, int j, ENUM_XINWEI xinwei = XinWei);
141 BOOL DrawTiShiBox(CDC *pdc, int i, int j);
142 BOOL DrawQiZi(CDC *pdc, int i, int j, CPiece::ENUM_QiZi eQiZi);
143 void DrawQiPang(CDC *pdc, CRect rcBounds);
144#ifdef CHINESE_CHESS_USE_PNG
145 BOOL DrawPicture(CDC *pdc, int i, int j, ATL::CImage* pImage);
146#endif
147 BOOL DrawPicture(CDC *pdc, int i, int j, CBitmap* pbmp, BOOL CHHJKL = false);
148
149 void InvalidateRectage(int i, int j);
150
151 BOOL SetQiPang(int width, int height);
152 BOOL PromptSound(LPCTSTR ID = NULL);
153
154 CChineseChessHandler* m_pGoChessHandler;
155};
virtual int OnGoChess(int i, int j, CPiece::ENUM_QiZi chess)=0
Executes the go chess action
中国象棋类
PROMPT_SOUND
提示音
enum CPiece::_ENUM_QiZi ENUM_QiZi
棋子枚举值 四个位表示棋子,最左1位表示颜色