[C / C ] Click in Dev-C – Mouse event in Dev-C
In this article I will walk on some of the functions and event click mode Dev-C graphics.
void getmouseclick( int kind, int& x, int& and );
-> obtain the coordinates x,and ( in pixels) where can click
bool ismouseclick( int kind );
-> returns true if there is a click
int mousex( ); -> mouse coordinates in the x
int mousey( ); -> mouse coordinates y-axis
WM_MOUSEMOVE : catch event when moving the mouse in the graphic display
WM_LBUTTONDBLCLK : catch event when double-clicking the left mouse
WM_LBUTTONDOWN : catch event when clicking the left mouse
WM_LBUTTONUP : catch event when released after pressing the left mouse
Similar between mice and rats have
WM_MBUTTONDBLCLK
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_RBUTTONDBLCLK
WM_RBUTTONDOWN
WM_RBUTTONUP
There are many other functions you see here: http://www.cs.colorado.edu/~main/bgi/doc/
A code snippet illustrates capture mouse events left, right.
#include <winbgim.h> #include <stdio.h> #include <string.h> int main(){ setbkcolor(1); int x, y; initwindow(800,500); setbkcolor(15); cleardevice(); while (1){ delay(0.0001); if (ismouseclick(WM_LBUTTONDOWN)){ getmouseclick(WM_LBUTTONDOWN, x, y); printf("left click : (%d,%d)n", x, y); } if (ismouseclick(WM_LBUTTONUP)){ getmouseclick(WM_LBUTTONUP, x, y); printf("left up click : (%d,%d)n", x, y); } if (ismouseclick(WM_LBUTTONDBLCLK)){ getmouseclick(WM_LBUTTONDBLCLK, x, y); printf("left double click : (%d,%d)n", x, y); } if (ismouseclick(WM_RBUTTONDOWN)){ getmouseclick(WM_RBUTTONDOWN, x, y); printf("right click : (%d,%d)n", x, y); } if (ismouseclick(WM_RBUTTONUP)){ getmouseclick(WM_RBUTTONUP, x, y); printf("right up click : (%d,%d)n", x, y); } if (ismouseclick(WM_RBUTTONDBLCLK)){ getmouseclick(WM_RBUTTONDBLCLK, x, y); printf("right double click : (%d,%d)n", x, y); } if (ismouseclick(WM_MOUSEMOVE)){ getmouseclick(WM_MOUSEMOVE, x, y); printf("move : (%d,%d)n", x, y); } } system("pause"); closegraph(); }
Results to click and move the mouse in the graphic display:
A video I come straight line drawn with the mouse but still not ready for errors:
Refer: Graphics in Dev-C
have a special clock that
Cảm ơn bạn 😀
cái đoạn code phía trên mình copy paste vào bản dev c++ 5.11 nó báo lỗi như vầy là sao thế:
C:\Users\hiep\Desktop\eventmouse.o eventmouse.cpp:(.text+0x0): multiple definition of `main’
C:\Users\hiep\Desktop\main.o main.cpp:(.text+0x0): first defined here
C:\Program Files\Dev-Cpp\collect2.exe [Error] ld returned 1 exit status
25 C:\Program Files\Dev-Cpp\Makefile.win recipe for target ‘MyProject.exe’ failed
mong bạn giải thích và chỉ mình cách khắc phục. thank nhiều
Cái lỗi này mình cũng chưa gặp. You try searching google and see if there is a fix, you please comment to let people know offline.
just his game review. lm which finished its body created 2 files ending in .cpp and .dev. his run in the .cpp it fails on. .dev is also ok. in advance or at the time his new / new source, it only creates each .cpp so I know k. you have the code of the middle mouse k yourself with, section writing about his new mouse, ask yourself what that little delay(0.0001); it has nothing in here that function. because I saw it only deleting try out DC frame windows and was not responding.
It is used to stop the program in 1 ms.
Anh ơi lệnh getimage sao em dùg nó báo lỗi vậy a
English instructions how to save the picture e variable is not a