当前位置:网站首页>The third lesson of EasyX learning

The third lesson of EasyX learning

2022-07-05 17:05:00 Blue whale not blue 369

Mouse messages need to use MOUSEMSG type , such as MOUSEMSG msg;
And then use MouthHit() Function to determine whether there is a mouse message ( left-click , Right click , middle , Move )
If there is a mouse message, you can receive the mouse message
msg=GetMouseMsg();

Main members of mouse message :

  • uMsg // Current mouse message
  • x // The current mouse x coordinate
  • y // The current mouse y coordinate

uMsg It can be used to judge what the current mouse message is :

  • WM_LBUTTONDOWN Left mouse button message
  • WM_RBUTTONDOWN Right mouse button message

For the new version of Easyx New content added
You need to use library functions **<easyx.h>**
Use ExMessage type , such as ExMessage msg;
And then use **peekmessage()** The function selects the identified content
For example, set a button

void test1(int x, int y, int w, int h) {
    
	setbkmode(TRANSPARENT);
	setfillcolor(BROWN);
	fillroundrect(x, y, x + w, y + h, 10, 10);
	char arr[] = "button";
	settextstyle(30, 0, " In black ");
	int width = x + (w - textwidth(arr)) / 2;
	int height = y + (h-textheight(arr)) / 2;
	outtextxy(width,height , "button");
	ExMessage msg;
	while (1) {
    
		if (peekmessage(&msg, EM_MOUSE)) {
    
			switch (msg.message) {
    
			case WM_LBUTTONDOWN:
				if (msg.x >= 50 && msg.x <= 50 + 150 && msg.y >= 50 && msg.y <= 50 + 150) {
    
					cout << " I'm the button , I got clicked " << endl; break;
				}
			}
		}
	}
}
原网站

版权声明
本文为[Blue whale not blue 369]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140511269218.html