Simple Description: This program is to modify a mouse program in C-only advanced programming. The original program cannot display the mouse in the XP system. I implemented the system-implemented mouseon and mouseoff functions by myself, and added a mousestatus. This function is used to determine the mouse State. Therefore, it is best to use a completed mousestatus function to determine the mouse state. The main principle of the program is to use the program to realize the difference or. */ # Include <graphics. h> # Include <stdlib. h> # Include <dos. h> # Include <conio. h> /* Macro definition of mouse information */ # Define waiting 0xff00 # Define leftpress 0xff01 # Define leftclick 0xff10 # Define leftdrag 0xff19 # Define rightpress 0xff02 # Define rightclick 0xff20 # Define rightdrag 0xff2a # Define middlepress 0xff04 # Define middleclick 0xff40 # Define middledrag 0xff4c # Define mousemove 0xff08 Int keystate; Int mouseexist; Int mousebutton; Int mousex; Int Mousey; Int up [16] [16], down [16] [16], mouse_draw [16] [16], pixel_save [16] [16]; Void mousemath ()/* calculate the mouse's appearance */ {Int I, j, JJ, K; Long upnum [16] = { 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff, 0x00ff, 0x007f, 0x003f, 0x00ff, 0x01ff, 0x10ff, 0x30ff, 0xf87f, 0xf87f, 0xfc3f }; Long downnum [16] = { 0x0000, 0x7c00, 0x6000,0x7000, 0x7800, 0x7c00, 0x7e00, 0x7f00, 0x7f80, 0x7e00, 0x7c00, 0x4600, 0x0600,0x0300,0x0300,0x0180 }; For (I = 0; I <16; I ++) { J = JJ = 15; While (upnum [I]! = 0) { Up [I] [J] = upnum [I] % 2; J --; Upnum [I]/= 2; } While (downnum [I]! = 0) { Down [I] [JJ --] = downnum [I] % 2; Downnum [I]/= 2; } For (k = J; k> = 0; k --) Up [I] [k] = 0; For (k = JJ; k> = 0; k --) Down [I] [k] = 0; For (k = 0; k <16; k ++)/* Four combination methods */ { If (up [I] [k] = 0 & down [I] [k] = 0) Mouse_draw [I] [k] = 1; Else if (up [I] [k] = 0 & down [I] [k] = 1) Mouse_draw [I] [k] = 2; Else if (up [I] [k] = 1 & down [I] [k] = 0) Mouse_draw [I] [k] = 3; Else Mouse_draw [I] [k] = 4; } } Mouse_draw [1] [2] = 4;/* Special Points */ } /* Mouse and Cursor Display */ Void mouseon (int x, int y) { Int I, J; Int color; For (I = 0; I <16; I ++)/* draw the mouse */ { For (j = 0; j <16; j ++) { Pixel_save [I] [J] = getpixel (x + J, Y + I);/* Save the original color */ If (mouse_draw [I] [J] = 1) Putpixel (x + J, Y + I, 0 ); Else if (mouse_draw [I] [J] = 2) Putpixel (x + J, Y + I, 15 ); } } } /* Hide the mouse */ Void mouseoff () { Int I, j, X, Y, color; X = mousex; Y = Mousey; For (I = 0; I <16; I ++)/* original location exclusive or exclusive */ For (j = 0; j <16; j ++) { If (mouse_draw [I] [J] = 3 | mouse_draw [I] [J] = 4) Continue; Color = getpixel (x + J, Y + I ); Putpixel (x + J, Y + I, color ^ color ); Putpixel (x + J, Y + I, pixel_save [I] [J]); } } /* Whether to load the mouse Mouseexist: 1 = Load 0 = Not loaded Mousebutton: Number of mouse buttons */ Void mouseload () { _ AX = 0x00; Geninterrupt (0x33 ); Mouseexist = _ ax; Mousebutton = _ BX; } /* Initialize the mouse status value */ Void mousereset () { _ AX = 0x00; Geninterrupt (0x33 ); } /* Set the left and right mouse borders Lx: Left Border GX: Right Border */ Void mousesetx (INT lx, int RX) { _ Cx = Lx; _ Dx = RX; _ AX = 0x07; Geninterrupt (0x33 ); } /* Set the upper and lower mouse borders Uy: Upper Boundary DY: bottom boundary */ Void mousesety (INT Uy, int Dy) { _ Cx = Uy; _ Dx = Dy; _ AX = 0x08; Geninterrupt (0x33 ); } /* Set the current mouse position X: horizontal coordinates Y: vertical coordinate */ Void mousesetxy (int x, int y) { _ Cx = X; _ Dx = y; _ AX = 0x04; Geninterrupt (0x33 ); } /* Set the mouse speed (default value: vx = 8, Vy = 1) The greater the value, the slower the speed */ Void mousespeed (int vx, int Vy) { _ Cx = VX; _ Dx = Vy; _ AX = 0x0f; Geninterrupt (0x33 ); } /* Obtain the information of the mouse key */ /* Whether to press the left button Return Value: 1 = press 0 = release */ Int leftpress () { _ AX = 0x03; Geninterrupt (0x33 ); Return (_ BX & 1 ); } /* Whether to press the middle key Return Value same as above */ Int middlepress () { _ AX = 0x03; Geninterrupt (0x33 ); Return (_ BX & 4 ); } /* Right-click or not Return Value same as above */ Int rightpress () { _ AX = 0x03; Geninterrupt (0x33 ); Return (_ BX & 2 ); } /* Get the current mouse position */ Void mousegetxy () { _ AX = 0x03; Geninterrupt (0x33 ); Mousex = _ CX; Mousey = _ DX; } Int mousestatus ()/* mouse buttons */ { Int X, Y; Int status; Int press = 0; Int I, j, color; Status = 0;/* No mouse movement by default */ X = mousex; Y = Mousey; While (x = mousex & Y = Mousey & status = 0 & press = 0) { If (leftpress () & rightpress ()) Press = 1; Else if (leftpress ()) Press = 2; Else if (rightpress ()) Press = 3; Mousegetxy (); If (mousex! = X | Mousey! = Y) Status = 1; } If (Status)/* move the cursor to display the mouse again */ { For (I = 0; I <16; I ++)/* original location exclusive or exclusive */ For (j = 0; j <16; j ++) { If (mouse_draw [I] [J] = 3 | mouse_draw [I] [J] = 4) Continue; Color = getpixel (x + J, Y + I ); Putpixel (x + J, Y + I, color ^ color ); Putpixel (x + J, Y + I, pixel_save [I] [J]); } Mouseon (mousex, Mousey);/* New Position display */ } If (Press! = 0)/* with buttons */ Return press; Return 0;/* only move */ } Void main () {Int GD = detect, GM; Initgraph (& GD, & GM, "C: // TC "); Mousemath ();/* calculate the Mouse shape. It must be used at the beginning and no longer needs to be used at the end */ Mousesety (0,479 ); Mousesetx (0,639 ); Mousesetxy (100,100 ); Outtextxy (400,400, "Author: milo_zy "); Outtextxy (370,420, "Welcome to www.8623.com "); Settextstyle (0, 0, 4 ); Outtextxy (100,200, "XP mouse Demo "); Mouseon (mousex, Mousey);/* display the mouse for the first time */ While (! Kbhit ()) { Switch (mousestatus ()) {/* Double bond click to draw a yellow dot */ Case 1: mouseoff (); Putpixel (mousex, Mousey, yellow ); Mousegetxy (); Mouseon (mousex, Mousey); break; /* Click the left button to draw a red dot */ Case 2: Mouseoff (); Putpixel (mousex, Mousey, red ); Mousegetxy (); Mouseon (mousex, Mousey); break; /* Right-click to draw a green dot */ Case 3: Mouseoff (); Putpixel (mousex, Mousey, green ); Mousegetxy (); Mouseon (mousex, Mousey); break; Default: break; } } Closegraph (); } |