天天看點

easyx.h中的各種函數

文章轉載自​​@鷹之唳​​

#pragma once
 
#ifndef WINVER
#define WINVER 0x0400 // Specifies that the minimum required platform is Windows 95 and Windows NT 4.0.
#endif
 
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500 // Specifies that the minimum required platform is Windows 2000.
#endif
 
#ifndef _WIN32_WINDOWS
#define _WIN32_WINDOWS 0x0410 // Specifies that the minimum required platform is Windows 98.
#endif
 
#if defined(UNICODE) && (_MSC_VER > 1200)
#pragma comment(lib,"easyxw.lib")
#elif !defined(UNICODE) && (_MSC_VER > 1200)
#pragma comment(lib,"easyx.lib")
#elif defined(UNICODE)
#pragma comment(lib,"easyxw6.lib")
#elif !defined(UNICODE)
#pragma comment(lib,"easyx6.lib")
#endif
 
 
#ifndef __cplusplus
#error EasyX is only for C++
#endif
 
#include
#include
 
// 繪圖視窗初始化參數
#define SHOWCONSOLE 1 // 建立圖形視窗時,保留控制台的顯示
#define NOCLOSE 2 // 沒有關閉功能
#define NOMINIMIZE 4 // 沒有最小化功能
 
// 顔色
#define BLACK 0
#define BLUE 0xAA0000
#define GREEN 0x00AA00
#define CYAN 0xAAAA00
#define RED 0x0000AA
#define MAGENTA 0xAA00AA
#define BROWN 0x0055AA
#define LIGHTGRAY 0xAAAAAA
#define DARKGRAY 0x555555
#define LIGHTBLUE 0xFF5555
#define LIGHTGREEN 0x55FF55
#define LIGHTCYAN 0xFFFF55
#define LIGHTRED 0x5555FF
#define LIGHTMAGENTA 0xFF55FF
#define YELLOW 0x55FFFF
#define WHITE 0xFFFFFF
 
// 定義顔色轉換宏
#define BGR(color) ( (((color) & 0xFF) << 16) | ((color) & 0xFF00FF00) | (((color) & 0xFF0000) >> 16) )
 
 
class IMAGE;
 
// 定義線的樣式
class LINESTYLE
{
public:
LINESTYLE();
LINESTYLE(const LINESTYLE &style);
LINESTYLE& operator = (const LINESTYLE &style); // 指派運算符重載函數
virtual ~LINESTYLE();
 
DWORD style;
DWORD thickness;
DWORD *puserstyle;
DWORD userstylecount;
};
 
class FILLSTYLE
{
public:
FILLSTYLE();
FILLSTYLE(const FILLSTYLE &style);
FILLSTYLE& operator = (const FILLSTYLE &style); // 指派運算符重載函數
virtual ~FILLSTYLE();
 
int style; // 填充形式
long hatch; // 填充圖案樣式
IMAGE* ppattern; // 填充圖像
};
 
// 定義圖像對象
class IMAGE
{
public:
int getwidth() const; // 擷取對象的寬度
int getheight() const; // 擷取對象的高度
 
private:
int width, height; // 對象的寬高
HBITMAP m_hBmp;
HDC m_hMemDC;
int m_MemCurX; // 目前點X坐标
int m_MemCurY; // 目前點Y坐标
float m_data[6];
COLORREF m_LineColor; // 目前線條顔色
COLORREF m_FillColor; // 目前填充顔色
COLORREF m_TextColor; // 目前文字顔色
COLORREF m_BkColor; // 目前背景顔色
DWORD* m_pBuffer; // 繪圖區的記憶體
 
LINESTYLE m_LineStyle; // 畫線樣式
FILLSTYLE m_FillStyle; // 填充樣式
 
virtual void SetDefault(); // 設定為預設狀态
 
public:
IMAGE(int _width = 0, int _height = 0); // 建立圖像
IMAGE(const IMAGE &img); // 拷貝構造函數
IMAGE& operator = (const IMAGE &img); // 指派運算符重載函數
virtual ~IMAGE();
virtual void Resize(int _width, int _height); // 調整尺寸
};      
// 繪圖模式相關函數
 
HWND initgraph(int width, int height, int flag = NULL); // 初始化圖形環境
void closegraph(); // 關閉圖形環境
 
// 繪圖環境設定
 
void cleardevice(); // 清屏
void setcliprgn(HRGN hrgn); // 設定目前繪圖裝置的裁剪區
void clearcliprgn(); // 清除裁剪區的螢幕内容
 
void getlinestyle(LINESTYLE* pstyle); // 擷取目前畫線樣式
void setlinestyle(const LINESTYLE* pstyle); // 設定目前畫線樣式
void setlinestyle(int style, int thickness = 1, const DWORD *puserstyle = NULL, DWORD userstylecount = 0); // 設定目前畫線樣式
void getfillstyle(FILLSTYLE* pstyle); // 擷取目前填充樣式
void setfillstyle(const FILLSTYLE* pstyle); // 設定目前填充樣式
void setfillstyle(int style, long hatch = NULL, IMAGE* ppattern = NULL); // 設定目前填充樣式
void setfillstyle(BYTE* ppattern8x8); // 設定目前填充樣式
 
void setorigin(int x, int y); // 設定坐标原點
void getaspectratio(float *pxasp, float *pyasp); // 擷取目前縮放因子
void setaspectratio(float xasp, float yasp); // 設定目前縮放因子
 
int  getrop2(); // 擷取前景的二進制光栅操作模式
void setrop2(int mode); // 設定前景的二進制光栅操作模式
int  getpolyfillmode(); // 擷取多邊形填充模式
void setpolyfillmode(int mode); // 設定多邊形填充模式
 
void graphdefaults(); // 重置所有繪圖設定為預設值
 
COLORREF getlinecolor(); // 擷取目前線條顔色
void setlinecolor(COLORREF color); // 設定目前線條顔色
COLORREF gettextcolor(); // 擷取目前文字顔色
void settextcolor(COLORREF color); // 設定目前文字顔色
COLORREF getfillcolor(); // 擷取目前填充顔色
void setfillcolor(COLORREF color); // 設定目前填充顔色
COLORREF getbkcolor(); // 擷取目前繪圖背景色
void setbkcolor(COLORREF color); // 設定目前繪圖背景色
int  getbkmode(); // 擷取背景混合模式
void setbkmode(int mode); // 設定背景混合模式
 
// 顔色模型轉換函數
COLORREF RGBtoGRAY(COLORREF rgb);
void RGBtoHSL(COLORREF rgb, float *H, float *S, float *L);
void RGBtoHSV(COLORREF rgb, float *H, float *S, float *V);
COLORREF HSLtoRGB(float H, float S, float L);
COLORREF HSVtoRGB(float H, float S, float V);      
// 繪圖函數
 
COLORREF getpixel(int x, int y); // 擷取點的顔色
void putpixel(int x, int y, COLORREF color); // 畫點
 
void moveto(int x, int y); // 移動目前點(絕對坐标)
void moverel(int dx, int dy); // 移動目前點(相對坐标)
 
void line(int x1, int y1, int x2, int y2); // 畫線
void linerel(int dx, int dy); // 畫線(至相對坐标)
void lineto(int x, int y); // 畫線(至絕對坐标)
 
void rectangle   (int left, int top, int right, int bottom); // 畫矩形
void fillrectangle (int left, int top, int right, int bottom); // 畫填充矩形(有邊框)
void solidrectangle(int left, int top, int right, int bottom); // 畫填充矩形(無邊框)
void clearrectangle(int left, int top, int right, int bottom); // 清空矩形區域
 
void circle (int x, int y, int radius); // 畫圓
void fillcircle (int x, int y, int radius); // 畫填充圓(有邊框)
void solidcircle(int x, int y, int radius); // 畫填充圓(無邊框)
void clearcircle(int x, int y, int radius); // 清空圓形區域
 
void ellipse (int left, int top, int right, int bottom); // 畫橢圓
void fillellipse (int left, int top, int right, int bottom); // 畫填充橢圓(有邊框)
void solidellipse(int left, int top, int right, int bottom); // 畫填充橢圓(無邊框)
void clearellipse(int left, int top, int right, int bottom); // 清空橢圓形區域
 
void roundrect   (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 畫圓角矩形
void fillroundrect (int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 畫填充圓角矩形(有邊框)
void solidroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 畫填充圓角矩形(無邊框)
void clearroundrect(int left, int top, int right, int bottom, int ellipsewidth, int ellipseheight); // 清空圓角矩形區域
 
void arc (int left, int top, int right, int bottom, double stangle, double endangle); // 畫橢圓弧(起始角度和終止角度為弧度制)
void pie (int left, int top, int right, int bottom, double stangle, double endangle); // 畫橢圓扇形(起始角度和終止角度為弧度制)
void fillpie (int left, int top, int right, int bottom, double stangle, double endangle); // 畫填充橢圓扇形(有邊框)
void solidpie(int left, int top, int right, int bottom, double stangle, double endangle); // 畫填充橢圓扇形(無邊框)
void clearpie(int left, int top, int right, int bottom, double stangle, double endangle); // 清空橢圓扇形區域
 
void polyline (const POINT *points, int num); // 畫多條連續的線
void polygon (const POINT *points, int num); // 畫多邊形
void fillpolygon (const POINT *points, int num); // 畫填充的多邊形(有邊框)
void solidpolygon(const POINT *points, int num); // 畫填充的多邊形(無邊框)
void clearpolygon(const POINT *points, int num); // 清空多邊形區域
 
void floodfill(int x, int y, int border); // 填充區域      
// 文字相關函數
 
void outtext(LPCTSTR str); // 在目前位置輸出字元串
void outtext(TCHAR c); // 在目前位置輸出字元
void outtextxy(int x, int y, LPCTSTR str); // 在指定位置輸出字元串
void outtextxy(int x, int y, TCHAR c); // 在指定位置輸出字元
int textwidth(LPCTSTR str); // 擷取字元串占用的像素寬
int textwidth(TCHAR c); // 擷取字元占用的像素寬
int textheight(LPCTSTR str); // 擷取字元串占用的像素高
int textheight(TCHAR c); // 擷取字元占用的像素高
int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat); // 在指定區域内以指定格式輸出字元串
int drawtext(TCHAR c, RECT* pRect, UINT uFormat); // 在指定區域内以指定格式輸出字元      
// 設定目前字型樣式(詳見幫助)
// nHeight: 字元的平均高度;
// nWidth: 字元的平均寬度(0 表示自适應);
// lpszFace: 字型名稱;
// nEscapement: 字元串的書寫角度(機關 0.1 度);
// nOrientation: 每個字元的書寫角度(機關 0.1 度);
// nWeight: 字元的筆畫粗細(0 表示預設粗細);
// bItalic: 是否斜體;
// bUnderline: 是否下劃線;
// bStrikeOut: 是否删除線;
// fbCharSet: 指定字元集;
// fbOutPrecision: 指定文字的輸出精度;
// fbClipPrecision: 指定文字的剪輯精度;
// fbQuality: 指定文字的輸出品質;
// fbPitchAndFamily: 指定以正常方式描述字型的字型系列。
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut);
void settextstyle(int nHeight, int nWidth, LPCTSTR lpszFace, int nEscapement, int nOrientation, int nWeight, bool bItalic, bool bUnderline, bool bStrikeOut, BYTE fbCharSet, BYTE fbOutPrecision, BYTE fbClipPrecision, BYTE fbQuality, BYTE fbPitchAndFamily);
void settextstyle(const LOGFONT *font); // 設定目前字型樣式
void gettextstyle(LOGFONT *font); // 擷取目前字型樣式      
// 圖像處理函數
void loadimage(IMAGE *pDstImg, LPCTSTR pImgFile, int nWidth = 0, int nHeight = 0, bool bResize = false); // 從圖檔檔案擷取圖像(bmp/jpg/gif/emf/wmf)
void loadimage(IMAGE *pDstImg, LPCTSTR pResType, LPCTSTR pResName, int nWidth = 0, int nHeight = 0, bool bResize = false); // 從資源檔案擷取圖像(bmp/jpg/gif/emf/wmf)
void saveimage(LPCTSTR pImgFile, IMAGE* pImg = NULL); // 儲存圖像
void getimage(IMAGE *pDstImg, int srcX, int srcY, int srcWidth, int srcHeight); // 從目前繪圖裝置擷取圖像
void putimage(int dstX, int dstY, const IMAGE *pSrcImg, DWORD dwRop = SRCCOPY); // 繪制圖像到螢幕
void putimage(int dstX, int dstY, int dstWidth, int dstHeight, const IMAGE *pSrcImg, int srcX, int srcY, DWORD dwRop = SRCCOPY); // 繪制圖像到螢幕(指定寬高)
void rotateimage(IMAGE *dstimg, IMAGE *srcimg, double radian, COLORREF bkcolor = BLACK, bool autosize = false, bool highquality = true);// 旋轉圖像
void Resize(IMAGE* pImg, int width, int height); // 調整繪圖裝置的大小
DWORD* GetImageBuffer(IMAGE* pImg = NULL); // 擷取繪圖裝置的顯存指針
IMAGE* GetWorkingImage(); // 擷取目前繪圖裝置
void SetWorkingImage(IMAGE* pImg = NULL); // 設定目前繪圖裝置
HDC GetImageHDC(IMAGE* pImg = NULL); // 擷取繪圖裝置句柄(HDC)      
// 其它函數
 
int getwidth(); // 擷取繪圖區寬度
int getheight(); // 擷取繪圖區高度
int getx(); // 擷取目前 x 坐标
int gety(); // 擷取目前 y 坐标
 
void BeginBatchDraw(); // 開始批量繪制
void FlushBatchDraw(); // 執行未完成的繪制任務
void FlushBatchDraw(int left, int top, int right, int bottom); // 執行指定區域内未完成的繪制任務
void EndBatchDraw(); // 結束批量繪制,并執行未完成的繪制任務
void EndBatchDraw(int left, int top, int right, int bottom); // 結束批量繪制,并執行指定區域内未完成的繪制任務
 
HWND GetHWnd(); // 擷取繪圖視窗句柄(HWND)
TCHAR* GetEasyXVer(); // 擷取 EasyX 目前版本
 
// 擷取使用者輸入
bool InputBox(LPTSTR pString, int nMaxCount, LPCTSTR pPrompt = NULL, LPCTSTR pTitle = NULL, LPCTSTR pDefault = NULL, int width = 0, int height = 0, bool bOnlyOK = true);      
// 滑鼠消息
// 支援如下消息:
// WM_MOUSEMOVE 滑鼠移動
// WM_MOUSEWHEEL 滑鼠滾輪撥動
// WM_LBUTTONDOWN 左鍵按下
// WM_LBUTTONUP 左鍵彈起
// WM_LBUTTONDBLCLK 左鍵輕按兩下
// WM_MBUTTONDOWN 中鍵按下
// WM_MBUTTONUP 中鍵彈起
// WM_MBUTTONDBLCLK 中鍵輕按兩下
// WM_RBUTTONDOWN 右鍵按下
// WM_RBUTTONUP 右鍵彈起
// WM_RBUTTONDBLCLK 右鍵輕按兩下
struct MOUSEMSG
{
UINT uMsg; // 目前滑鼠消息
bool mkCtrl; // Ctrl 鍵是否按下
bool mkShift; // Shift 鍵是否按下
bool mkLButton; // 滑鼠左鍵是否按下
bool mkMButton; // 滑鼠中鍵是否按下
bool mkRButton; // 滑鼠右鍵是否按下
short x; // 目前滑鼠 x 坐标
short y; // 目前滑鼠 y 坐标
short wheel; // 滑鼠滾輪滾動值 (120 的倍數)
};      
bool MouseHit(); // 檢查是否存在滑鼠消息
MOUSEMSG GetMouseMsg(); // 擷取一個滑鼠消息。如果沒有,就等待
void FlushMouseMsgBuffer(); // 清空滑鼠消息緩沖區