Anh phải chạy thử cho bọn em biết chứ.
Hình như phải có tệp mouse.ini mới chạy được.
Sưu tầm - Em chưa có chạy thửPHP Code:struct MOUSE
{
int mouse_trang_thai;
int mouse_x;
int mouse_y;
};
int mouse_reset();
void Khoi_dong_mouse();
void Thoat_mouse();
void Trang_thai_mouse(MOUSE &mouse);
void mouse_horizontal_range(int xmin, int xmax);
void mouse_vertical_range(int ymin, int ymax);
void Gioi_han_mouse(int xmin,int xmax,int ymin,int ymax);
/*----------------------------------------------------------------------*/
int mouse_reset()
{
int bientam;
asm{
xor ax,ax
mov ax,00
mov bientam,ax
int 0x33
}
return(bientam);
}
/*----------------------------------------------------------------------*/
void Khoi_dong_mouse()
{
asm{
xor ax,ax
mov ax,01
int 0x33
}
}
/*----------------------------------------------------------------------*/
void Thoat_mouse()
{
asm{
xor ax,ax
mov ax,02
int 0x33
}
}
/*----------------------------------------------------------------------*/
void Trang_thai_mouse(MOUSE &mouse)
{
int a,b,c;
asm{
xor ax,ax
xor bx,bx
xor cx,cx
xor dx,dx
mov ax,03
int 0x33
mov a,bx
mov b,cx
mov c,dx
}
mouse.mouse_trang_thai=a;
mouse.mouse_x=b;
mouse.mouse_y=c;
} /* Trang_thai_mouse */
/*----------------------------------------------------------------------*/
void Chieu_ngang_mouse(int xmin, int xmax)
{
asm{
xor ax,ax
xor cx,cx
xor dx,dx
mov ax,07
mov cx,xmin
mov dx,xmax
int 0x33
}
}
/*----------------------------------------------------------------------*/
void Chieu_doc_mouse(int ymin, int ymax)
{
asm{
xor ax,ax
xor cx,cx
xor dx,dx
mov ax,08
mov cx,ymin
mov dx,ymax
int 0x33
}
}
void Gioi_han_mouse(int xmin,int xmax,int ymin,int ymax)
{ Chieu_ngang_mouse(xmin,xmax);
Chieu_doc_mouse(ymin,ymax);
}
Anh phải chạy thử cho bọn em biết chứ.
Hình như phải có tệp mouse.ini mới chạy được.
Mình có file mouse này của thằng bạn mình viết,xài cũng good lắm
Code:#include <dos.h> #include <graphics.h> #include <stdio.h> #include <conio.h> #ifndef _MOUSE_CPP #define _MOUSE_CPP #define INT_MOUSE 0x33 //Ngat chuot #define MOUSE_INIT 0x00 //Chuc nang 0 --> khoi tao chuot #define MOUSE_SHOW 0x01 //Chuc nang 1 --> hien chuot #define MOUSE_HIDE 0x02 //Chuc nang 2 --> an chuot #define MOUSE_POS 0x03 //Chuc nang 3 --> lay toa do chuot #define MOUSE_MOVE 0x04 //Chuc nang 4 --> di chuyen chuot #define MOUSE_DOWN 0x05 //Chuc nang 5 --> so lan an chuot #define MOUSE_UP 0x06 //Chuc nang 6 --> so lan tha chuot #define MOUSE_LIMY 0x07 //Chuc nang 7 --> xac dinh toa do gioi han y #define MOUSE_LIMX 0x08 //Chuc nang 8 --> xac dinh toa do gioi han x #define LEFT 0 #define RIGHT 1 #define MIDDLE 2 #define TEXT 0 #define GRAPHIC 1 typedef struct{ int click; int n; int x; int y; }mouse_status; //=====================prototype============================ void init_mouse(); void show_mouse(); void hide_mouse(); void getmouse_pos(int *x,int *y,int mode); void move_mouse(int x,int y,int mode); void mouse_even(int even,int mouse,mouse_status *m,int mode); void mouse_limit(int x1,int y1,int x2,int y2,int mode); //========================================================== void init_mouse(){ int status; _AX=MOUSE_INIT; geninterrupt(INT_MOUSE); status = _AX; if(status==0) printf("chua cai dat chuot"); } void show_mouse(){ _AX=MOUSE_SHOW; geninterrupt(INT_MOUSE); } void hide_mouse(){ _AX=MOUSE_HIDE; geninterrupt(INT_MOUSE); } void getmouse_pos(int *x,int *y,int mode){ _AX=MOUSE_POS; geninterrupt(INT_MOUSE); *x=_CX; *y=_DX; if(mode==TEXT){ *x=*x/8+1; *y=*y/8+1; } } void move_mouse(int x,int y,int mode){ if(mode==TEXT){ x=x/8+1; y=y/8+1; } } _CX=x; _DX=y; _AX=MOUSE_MOVE; geninterrupt(INT_MOUSE); } void mouse_even(int even,int mouse,mouse_status *m,int mode){ _BX=mouse; _AX=even; geninterrupt(INT_MOUSE); m->click = _AX; m->n = _BX; m->x = _CX; m->y = _DX; if (mode==TEXT){ m->x=m->x/8+1; m->y=m->y/8+1; } } void mouse_limit(int x1,int y1, int x2, int y2,int mode){ if (mode==TEXT){ x1 = (x1-1)*8; y1 = (y1-1)*8; x2 = (x2-1)*8; y2 = (y2-1)*8; } _CX = x1; _DX = x2; _AX = MOUSE_LIMX; geninterrupt(INT_MOUSE); _CX = y1; _DX = y2; _AX = MOUSE_LIMY; geninterrupt(INT_MOUSE); } #endif
Ngoài cách viết theo hàm "geninterrupt(...);" như trên còn có cách viết bằng hàm int86(0x33,&in,&out) nữa. Trong đó in là tham số vào, out là tham số thu dc. Theo mình thì cách này có vẽ gọn hơn đấy (*.^), hổng biết mấy bạn thấy sao, keke
Vd:
void clickMouse(int &s,int &x,int &y)
{
union REGS v;
v.x.ax=0x05; // Sử dụng ngắt số 5, lấy giá trị khi nhấp chuột
int86(0x33,&v,&v); // biến v vừa là tham số vào, vừa là tham số ra
s=v.x.bx; // v.x.bx=1 khi nhấp chuột
x=v.x.cx; // v.x.cx chứa tọa độ x
y=v.x.dx; // v.x.dx chứa tọa độ y
}
Mình thấy có một điều cần lưu ý khi viết chương trình với chuột là khi bạn muốn sau khi nhấp chuột sẽ in ra một ký tự tại điểm vừa nhấp thì trước tiên, bạn phải ẩn chuột -> in ký tự -> hiện lại chuột. Nếu không làm như vậy thì ký tự của bạn sẽ bị "ăn bớt" đấy. Thử xem nào !!!
I know... nothing
![]()
Ý tưởng của bạn rất hay. Mình sẽ thử xem. Mình thấy chạy như bài 2 cũng ổn rồi. Tuy nhiên, cái này chỉ để viết mấy cái đĩa khởi động trông cho nó vui mắt với con chuột thôi. Thầy Giáo đang cho bài tập viết OSLoader, có lẽ nên tham khảo bài này để đưa con chuột vào cho nó Prồ. HIhi