-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
96ec595
commit eb7fdb0
Showing
2 changed files
with
117 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,11 @@ | |
// 基于 EasyX 图形库的 Win32 拓展库 | ||
// | ||
// 作 者:huidong <[email protected]> | ||
// 版 本:Ver 3.1.0 | ||
// 版 本:Ver 3.1.1 | ||
// 编译环境:VisualStudio 2022 | EasyX_20220610 | Windows 10 | ||
// 项目地址:https://github.com/zouhuidong/EasyWin32 | ||
// 创建日期:2020.12.06 | ||
// 最后修改:2022.07.15 | ||
// 最后修改:2022.07.16 | ||
// | ||
|
||
#pragma once | ||
|
@@ -66,6 +66,65 @@ struct EasyWindow | |
int nSkipPixels; // 绘制时跳过的像素点数量(降质性速绘) | ||
}; | ||
|
||
// 鼠标拖动消息 | ||
// 调用方法: | ||
// 需要在鼠标消息循环中每次都调用 UpdateMessage 更新鼠标消息 | ||
// 调用 isLeftDrag,isMiddleDrag,isRightDrag 函数判断正在拖动的鼠标按键 | ||
// 调用 GetDragX,GetDragY 获取鼠标拖动时鼠标坐标的变化量 | ||
class MouseDrag | ||
{ | ||
private: | ||
ExMessage old, msg; | ||
int dx, dy; | ||
bool lbtn = false, mbtn = false, rbtn = false; | ||
bool newmsg = false; | ||
|
||
bool UpdateDragInfo(bool& btn, int msgid_down, int msgid_up) | ||
{ | ||
if (newmsg) | ||
{ | ||
if (btn) | ||
{ | ||
dx = msg.x - old.x; | ||
dy = msg.y - old.y; | ||
old = msg; | ||
if (msg.message == msgid_up) btn = false; | ||
if (dx != 0 || dy != 0) return true; | ||
else return false; | ||
} | ||
else | ||
{ | ||
if (msg.message == msgid_down) | ||
{ | ||
btn = true; | ||
old = msg; | ||
} | ||
return false; | ||
} | ||
newmsg = false; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
public: | ||
|
||
void UpdateMessage(ExMessage m) | ||
{ | ||
msg = m; | ||
newmsg = true; | ||
} | ||
|
||
bool isLeftDrag() { return UpdateDragInfo(lbtn, WM_LBUTTONDOWN, WM_LBUTTONUP); } | ||
bool isMiddleDrag() { return UpdateDragInfo(mbtn, WM_MBUTTONDOWN, WM_MBUTTONUP); } | ||
bool isRightDrag() { return UpdateDragInfo(rbtn, WM_RBUTTONDOWN, WM_RBUTTONUP); } | ||
|
||
int GetDragX() { return dx; } | ||
int GetDragY() { return dy; } | ||
}; | ||
|
||
////////////****** 窗体相关函数 ******//////////// | ||
|
||
// 创建支持 win32 的绘图窗口(默认支持窗口双击消息) | ||
|
@@ -241,6 +300,18 @@ MOUSEMSG To_MouseMsg(ExMessage msgEx); | |
UINT GetExMessageType(ExMessage msg); | ||
|
||
|
||
////////////****** 图像处理相关函数 ******//////////// | ||
|
||
// 得到 IMAGE 对象的 HBITMAP | ||
HBITMAP Image2Bitmap(IMAGE* img); | ||
|
||
// HBITMAP 转 HICON | ||
HICON Bitmap2Icon(HBITMAP hBmp); | ||
|
||
// 在屏幕指定位置输出格式化文本 | ||
void outtextxy_format(int x, int y, int _Size, LPCTSTR lpFormat, ...); | ||
|
||
|
||
EASY_WIN32_END | ||
|
||
////////////****** 任务指令宏定义 ******//////////// | ||
|
@@ -321,20 +392,10 @@ EASY_WIN32_END | |
|
||
////////////****** 其他函数 ******//////////// | ||
|
||
|
||
// 精确延时函数(可以精确到 1ms,精度 ±1ms) | ||
// by yangw80<[email protected]>, 2011-5-4 | ||
void HpSleep(int ms); | ||
|
||
// 在屏幕指定位置输出格式化文本 | ||
void outtextxy_format(int x, int y, int _Size, LPCTSTR lpFormat, ...); | ||
|
||
// 得到 IMAGE 对象的 HBITMAP | ||
HBITMAP GetImageHBitmap(IMAGE* img); | ||
|
||
// HBITMAP 转 HICON | ||
HICON HICONFromHBitmap(HBITMAP hBmp); | ||
|
||
// 常用色彩扩展 | ||
enum COLORS { | ||
DARKBLUE = RGB(0x00, 0x00, 0x8B), | ||
|