peekmessage()点一次鼠标会执行多次

0

用的dev cpp,简化代码如下
我鼠标点一次右键,printf会被执行很多次,想请教大佬们有什么解决方法或更好的写法。

#include <stdio.h>
#include <graphics.h>
int main()
{
	ExMessage msg;
	while(1)
	{
		peekmessage(&msg);
		if(msg.message == WM_RBUTOONDOWN)
			printf("1");
	}
}
ava
国泰民安

2023-6-4

2

把直肠子函数换成卡脖子函数 getmessage(EX_MOUSE);
把代码改成这样:

#include <stdio.h>
#include <graphics.h>
int main()
{	
	initgraph(200, 200, 1);
	ExMessage msg;
	while (1)	
	{		
		msg = getmessage(EX_MOUSE);
		if (msg.message == WM_LBUTTONUP)	
			printf("1");	
	}	
	closegraph();
}
ava
随波逐流

2023-6-5

谢谢大佬 -  国泰民安  2023-6-5
技术讨论社区