ترددت كثيرا قبل ان ابدا في هذا الموضوع خصوصا ان انا ببأي بعيد عن جهازي وانا في المنتدي عشان معندناش تليفون (هنادم عليه اريب)
المهم انا اساسا تعبان اوي مع c++ عشان نفسي اوصل لابعد مدي ممكن وتطوير بيئة العمل عشان تكون بتستخدم الماوس وال true color وكمان اللغه العربيه اللي للاسف المنتدي مش لالها حل ..ما علينا
Theory:- To initiate the mouse and other stuff, we make interrupts to the processor using interrupt no 33H. 33H interrupt is dedicated to mouse handling. Depending on the value in the AH register, different operations on the mouse is performed. If dont have any idea what is interrupt and registers, is okay, but knowing them certainly helps you understand the theory better. The Various Interrupt Services:- All the following Services are under 33H Interrupt. To Inititate Mouse:- AX = 0 Return:- AX= FFFFH if mouse support is available AX= 0 if mouse support is unavailable To Show Mouse on the screen:- AX = 1 Return :- Nothing To Hide Mouse:- AX = 2 Return :- Nothing To Get Mouse Coordinates and Button Status:- AX =3 Return:- BX = mouse button status (Bit encoded) Bit Significance:- 0 - left button is pressed 1 - right button is pressed 2 - center button is pressed CX = x coordinate DX = y coordiante To Set Mouse Position AX = 4 CX = x coordinate DX = y coordinate Return :- Nothing To Set horizontal limits for pointer:- AX = 7 CX = minimum x coordinate DX = maximum x coordinate Return :- Nothing To Set vertical limits for pointer:- AX = 8 CX = minimum y coordinate DX = maximum y coordiante Return :- Nothing To generate interrupt the function used is 'geninterrupt()' To see how the above information is used to put in practice, refer the tutorial1.cpp file. Note:- When the mouse in used in dos without graphics i.e. text mode, it appears as a rectangular block. When it is used in graphics mode, it appears as the normal arrow pointer you see in windows.
وده مثال علي الكلام اللي اتقال فوق
//The Compiler used is Turbo C, I dont know if it will compile in others also.
//Didn't Compile in Microsoft C Compiler. Make the respective change then.
//The function geninterrupt() generates interrupts, it is defined in dos.h
//_AX,_BX,_CX,_DX are defined in dos.h & correspond to ax,bx,cx,dx registers respectively.
//Make a header file out of this one and use it in your programs.
#include<dos.h>//this header file is necessary
#include<stdio.h>//only for displaying messages
#include<conio.h>//for other stuff like getch() etc.
unsigned initmouse()
{
_AX=0;
geninterrupt(0x33); //Generate Inpterrupt
return _AX;
}
void showmouse()
{
_AX=1;
geninterrupt(0x33);
}
void hidemouse()
{
_AX=2;
geninterrupt(0x33);
}
void restrictmouse(int x1,int y1,int x2,int y2)
{
_AX=7;
_CX=x1;
_DX=x2;
geninterrupt(0x33);
_AX=8;
_CX=y1;
_DX=y2;
geninterrupt(0x33);
}
void getmouse(int *button,int *x,int *y)
{
_AX=3;
geninterrupt(0x33);
*button=_BX;
*x=_CX;
*y=_DX;
}
void setmouse(int x,int y)
{
_AX=4;
_CX=x;
_DX=y;
geninterrupt(0x33);
}
void main()
{
int x,y,button;
clrscr();
gotoxy(29,18);
textbackground(GREEN);
cprintf("EXIT");
gotoxy(1,1);
if(initmouse()==0)
{
printf("Mouse support unavailable");
return;
}
printf("\n\nPress any key to Show Mouse");
getch();
showmouse();
printf("\nPress any key to Hide Mouse");
getch();
hidemouse();
printf("\nPress any key to Show Mouse again");
getch();
restrictmouse(208,80,416,160);
showmouse();
printf("\nMouse has been restricted");
printf("\nPress on Exit button to quit the Program");
while(1)
{
getmouse(&button,&x,&y);
gotoxy(35,1);
printf("Coordinates:-(%d,%d) ",x,y);
gotoxy(35,2);
if(button&1)//<- Here '&' means ANDing, remember bitwise operators of C/C++
printf("Left button pressed ");
else if(button&2)
printf("Right button pressed ");
else if(button&4)
printf("Center button pressed");
else
printf("No button Pressed ");
if(x>=224&&x<=248&&y==136&&button==1)//checks if exit button is pressed or not
break;
}
}اما هنا بقي بنغير شكل الماوس
Prologue:- Welcome to the second tutorial of Mouse Programming. I hope you have read my first tutorial. In this tutorial we are going to learn how to change the mouse cursors, like the windows does. We can change the shape of the mouse cursor from a arrow to anthing we can imagine. We can't change the size though. Also you cannot the change the shape or size if you are using mouse in text mode. Theory:- Mouse cursor in graphical mode occupies 16 X 16 pixels. By highlighting or de-highlighting the pixels, we can change the mouse pointer. If I ask you how many bits will be required by the mouse, you will say 16 X 16 = 256bits(32 bytes), since each pixel will occupy 1 bit in memory. Good, but instead it requires another 32 bytes, so total of 64 bytes is required by the mouse. The first 32 bytes contain a bitmap which is ANDed with the screen, the second 32 bytes is XORed with the screen. If you dont understand this, dont pull you hair, theories have always been that way. But do try to understand if you can. In the second tutorial, we have made an interrupt to the processor, but in a different way. The reason that I did not use this methord in the first tutorial is that the second methord is realtively tough that the previous one. Any way, you dont need to know much about it expect the following details:- AX = 9 This is the service number BX = 0 CX = 0 DX = offset address of the pointer image ES=DS segment address of pointer You will also notice two statements in the tutorial2.cpp:- unioun REGS i,o; struct SREGS s; These are already defined in dos.h. They contain the registry variables. Thats all you need to know. Use them as they are. Please refer tutorial2.cpp. This file can be compiled to make a program that changes the standard arrow pointer to an hour glass. The function used to generate interrupt is 'int86x()' which is defined in dos.h. One question that may come to you mind as which methord of generating interrupt is better. I will say, use 'geninterrupt()' because it is simple and works everytime. As far as 'int86x()', this is the only place where I have used this function to generate interrupt. So if you ever need to generate interrupt, I am sure 'geninterrupt()' will work. Note:- I have compiled tutorial1.cpp and tutorial2.cpp in Borland Turbo C/C++. Tutorial1.cpp may compile in other compilers since it does not use graphics. Tutorial2.cpp may not compile as many other compilers dont have graphics.h file and other graphics files. So dont blame me. Make the respective changes. Please give me your feed back. See ya.
وده برضه مثال
#include<dos.h>
#include<conio.h>
#include<mouse.h>
#include<graphics.h> //Graphics header file required to start graphics
union REGS i,o;
struct SREGS s;
void changecursor(int *shape)
{
i.x.ax=9; //Service number
i.x.bx=0;
i.x.cx=0;
i.x.dx=(unsigned)shape;//Offset address of cursor
segread(&s); //Stores the segment register values in structure SREGS s
s.es=s.ds; //segment address of pointer
int86x(0x33,&i,&o,&s); //Generate Interrupt
}
/*BITMAP IMAGE OF AN HOUR GLASS
Binary representation Hexadecimal reprentation
1111111111111111 0xffff
1111111111111111 0xffff
1111111111111111 0xffff
1111111111111111 0xffff
0111111111111110 0x7ffe
0011111111111100 0x3ffc
0000111111110000 0x0ff0
0000001111000000 0x03c0
0000001111000000 0x03c0
0000111111110000 0x0ff0
0011111111111100 0x3ffc
0111111111111110 0x7ffe
1111111111111111 0xffff
1111111111111111 0xffff
1111111111111111 0xffff
1111111111111111 0xffff
*/ // '~' is the complement operator in C/C++
int cursor[32]={ ~0xffff,~0xffff,~0xffff,~0xffff,//hour glass screen mask ( in hex)
~0x7ffe,~0x3ffc,~0x0ff0,~0x03c0,
~0x03c0,~0x0ff0,~0x3ffc,~0x7ffe,
~0xffff,~0xffff,~0xffff,~0xffff,
0xffff,0xffff,0xffff,0xffff, //hour glass bitmap (in hex)
0x7ffe,0x3ffc,0x0ff0,0x03c0,
0x03c0,0x0ff0,0x3ffc,0x7ffe,
0xffff,0xffff,0xffff,0xffff };
void main()
{
int gd=DETECT,gm; //DETECT = autodetects available graphics mode
initgraph(&gd,&gm,""); //start graphics mode
initmouse(); //initiate mouse
changecursor(cursor); //change cursor
showmouse(); //display mouse
getch();
closegraph(); //shut down graphics and return to text mode
}انا هنا باي عاوز اعرف ايه العلاقه بين
clrscr();
gotoxy(29,18);
textbackground(GREEN);
cprintf("EXIT");و ده
if(x>=224&&x<=248&&y==136&&button==1)//checks if exit button is pressed or not break;
لو انا عاوز اغير الكان اذاي اخدد المكان اللي هيضغط عليه الماوس ..انا جربت كتير ملقتش اي حل .
الموضوع ده كله جاي من
