Mouse event in Graphics Mode (can't catch Left Click)

This is a discussion on Mouse event in Graphics Mode (can't catch Left Click) within the C++ Programming forums, part of the General Programming Boards category; I have a MOUSE2.h file and MOUSE.CPP At MOUSE.CPP, MOUSE2.h is included at header. I want catch event Left Mouse ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    6

    Mouse event in Graphics Mode (can't catch Left Click)

    I have a MOUSE2.h file and MOUSE.CPP
    At MOUSE.CPP, MOUSE2.h is included at header. I want catch event Left Mouse click! But not occured, i don't know why? let me know...

    Here code MOUSE2.h
    Code:
    #include <dos.h>
    #include <stdio.h>
    #include <graphics.h>
    
    
      union REGS regs;
      struct SREGS sregs;
    
      int MouseInit(void)
      /* Ham khoi tao chuot */
    	{
    	  regs.x.ax=0x00;
    	  int86(0x33,&regs,&regs);
    	  return regs.x.ax;
    	}
    
      int CursorList[28][34]= /* Array includes 28 mask mouse */
    	{
    	  // 0 : Mui ten chuan nen trang
    	  0x9FFF,0x8FFF,0x87FF,0x83FF,0x81FF,0x80FF,0x807F,0x803F,
    	  0x801F,0x800F,0x80FF,0x887F,0x987F,0xFC3F,0xFC3F,0xFE3F,
    	  0x0000,0x2000,0x3000,0x3800,0x3C00,0x3E00,0x3F00,0x3F80,
    	  0x3FC0,0x3E00,0x3600,0x2300,0x0300,0x0180,0x0180,0x0000,
    	  0,0,
    	  // 1 : Finger
    	  0xF3FF,0xE1FF,0xE1FF,0xE1FF,0xE1FF,0xE049,0xE000,0x8000,
    	  0x0000,0x0000,0x07FC,0x07F8,0x9FF9,0x8FF1,0xC003,0xE007,
    	  0x0C00,0x1200,0x1200,0x1200,0x1200,0x13B6,0x1249,0x7249,
    	  0x9249,0x9001,0x9001,0x8001,0x4002,0x4002,0x2004,0x1FF8,
    	  0,0,
              //............
    	  // 27 
    
    
    	};
    
      void SetMouseType(int MType)
      /* Dat kieu con tro chuot theo cac mang ve chuot tren */
    	{
    	   regs.x.ax = 0x09;
    	   regs.x.bx = CursorList[MType][32]; // Diem nong theo truc x
    	   regs.x.cx = CursorList[MType][33]; // Diem nong theo truc y
    	   sregs.es  = FP_SEG(CursorList[MType]);
    	   regs.x.dx = FP_OFF(CursorList[MType]);
    	   int86x(0x33,&regs,&regs,&sregs);
    	}
    
      void SetMouseShowIn(int L,int T,int R,int B)
      /* Dat toa do di chuyen chuot chi trong vung */
    	{
    	  if((B<=T)||(R<=L)) return;
    	  regs.x.ax = 0x07;
    	  regs.x.cx = L;
    	  regs.x.dx = R;
    	  int86(0x33,&regs,&regs);
    	  regs.x.ax = 0x08;
    	  regs.x.cx = T;
    	  regs.x.dx = B;
    	  int86(0x33,&regs,&regs);
    	}
    
      void SetMouseNotShowIn(int L,int T,int R,int B)
    	/* Ham nay dat vung gioi han ma trong vung do con chuot do hoa duoc  */
    	/* an di. Vung nay bi huy khi goi lai ham voi toa do x hoac y sau nho*/
    	/* hon hoac bang x,y truoc. 					 */
    	{
    	  if((B<=T)||(R<=L)) return;
    	  regs.x.ax=0x10;
    	  regs.x.cx=L;
    	  regs.x.dx=T;
    	  regs.x.si=R;
    	  regs.x.di=B;
    	  int86(0x33,&regs,&regs);
    	}
    
      void MouseShow(void)
      /* Hien con tro chuot */
    	{
    	  regs.x.ax=0x01;
    	  int86(0x33,&regs,&regs);
    	}
    
      void MouseHide(void)
      /* An con tro chuot */
    	{
    	  regs.x.ax=0x02;
    	  int86(0x33,&regs,&regs);
    	}
    
      void GetMouse(int *Button,int *MouseX, int *MouseY)
      /* Lay vi tri con tro chuot che do GRAPH */
    	{
    	  regs.x.ax=0x03;
    	  int86(0x33,&regs,&regs);
    	  *Button=regs.x.bx; *MouseX=regs.x.cx; *MouseY=regs.x.dx;
    	}
    
      int  MouseLPressed(void)
      /* Test if Left Mouse clicked, return value not 0 (1) */
    	{
    	  regs.x.ax=0x03;
    	  int86(0x33,&regs,&regs);
    	  return regs.x.bx&1;
    	}
    
      int  MouseRPressed(void)
      /* Kiem tra neu phim phai chuot bam ham tra lai gia tri khac 0 (2); */
    	{
    	  regs.x.ax=0x03;
    	  int86(0x33,&regs,&regs);
    	  return regs.x.bx&2;
    	}
    
      int  MouseReleased(void)
      /* Kiem tra neu phim chuot da bam duoc tha ra   */
      /* ham tra lai gia tri khac 1                   */
    	{
    	  regs.x.ax=0x03;
    	  int86(0x33,&regs,&regs);
    	  if ((regs.x.bx&1)||(regs.x.bx&2)) return(0); else return(1);
    	}

    Here MOUSE.CPP code


    Code:
    #include <stdio.h>
    #include <graphics.h>
    #include <dos.h>
    #include <conio.h>
    #include "MOUSE2.h"
    
    void main()
    {
    	int gd,gm;
    	//int b;
    	gd=gm=0;
    	initgraph(&gd,&gm,"..\\BGI");
    	MouseInit();
    	MouseShow();
    	setcolor(1);
    	if (MouseLPressed()==1) //if LeftMouse clicked, draw line...
    	{
    		line(100,100,500,500);
    	}
    	
    	getch();
    }
    I only see mouse show, then I clicked left mouse, nothing occure, why?

    help me...

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Maybe you should program for the operating system you're actually using. And btw, if you're actually using DOS, it's time to upgrade.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I suspect you can't capture left buttons in DOS-mode, as they have are intercepted by Windows as "paste".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    6
    oh, no! I saw my teacher use mouse to click on button...

  5. #5
    The larch
    Join Date
    May 2006
    Posts
    3,573
    The program probably doesn't stop before getch. If you press the mouse button then, it will be too late - the program has already checked for mouse-press and won't do it again.

    You might need to put mouse input detection in some sort of loop.

    Also, it seems that the mouse functions return rather arbitrary values (from users point of view) when true, so you'd better just check for non-zero:
    Code:
    if (MouseLPressed())
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #6
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,584
    I've had problems with sub function 03h in mouse code before. Try function 05h to retrieve the press.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a function pointer from a button click event?
    By dxfoo in forum Windows Programming
    Replies: 20
    Last Post: 01-29-2008, 02:35 AM
  2. How to do a mouse over event on a button?
    By GUIPenguin in forum C# Programming
    Replies: 1
    Last Post: 07-06-2006, 10:34 AM
  3. Replies: 2
    Last Post: 03-23-2006, 06:08 AM
  4. How I can Show the pointer of mouse int 800*600 256 color mode in Turbo C++?
    By hadizadeh in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-12-2001, 06:17 AM
  5. Mouse in 800x600 24Bit Mode?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 11-11-2001, 12:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21