📄 mouse.c
字号:
/* MOUSE - Module of mouse functions. To use it, include the MOUSE.H file
*
*
* MouseInit -初始化鼠标
* GetMouseEvent -得到最近的老鼠事件的信息
* SetPtrVis -设置指针的可见性隐蔽或显示出
* SetPtrPos - 指针的集合位置
* SetPtrShape --指针的集合形状在图形模式,或*在文章模式的特性和颜色*
* GetPtrPos - 得到指针位置和按钮地位**下列结构被定义
*
*/
#include <graph.h>
#include "mouse.h"
struct MOUINFO ////各种各样的鼠标使用了的内部的信息工作
{
int fExist, fInit, fGraph;
short xVirtual, yVirtual;
short xActual, yActual;
short xLast, yLast;
unsigned fsBtnLast, cBtn;
} static mi =
{
1, 0, 0,
0, 0,
0, 0,
0, 0,
0, 0
};
#pragma optimize( "lge", off ) //与汇编程序
int MouseInit() //-初始化鼠标
{
struct videoconfig vc;
char __far *pMode = (char __far *)0x00000449L; /* Address for mode */
_getvideoconfig( &vc );//测试系统
if( vc.mode == _HERCMONO )
{
_setvideomode( _TEXTMONO );
*pMode = 6;
}
mi.fInit = 1;
__asm
{
sub ax, ax ; Mouse function 0, reset mouse
mov mi.cBtn, ax ; Assume no mouse buttons
int 33h
mov mi.fExist, ax ; Set existence flag for future calls
or ax, ax ; If AX = 0, there is no mouse
jz nomouse
mov mi.cBtn, bx ; Save number of mouse buttons for return
nomouse:
}
if( !mi.fExist )
return 0;
/* 设置图形标志 */
if( vc.numxpixels )
{
mi.fGraph = 1;
mi.yActual = vc.numypixels - 1;
mi.xActual = vc.numxpixels - 1;
}
else
mi.fGraph = 0;
/*鼠标在 640 的一幅虚拟的屏幕上工作 x 象素由( 8 * textrows )*垂直的象素。
由缺省,它假定 640 x 200 为25线模式。
*你必须叫功能 8 为另外的屏幕大小调整。*/
mi.xVirtual = 639;
if( mi.fGraph )
mi.yVirtual = vc.numypixels - 1;
else
mi.yVirtual = (vc.numtextrows << 3) - 1;
/* Reset Hercules graphics mode and reset the height. */
if( vc.mode == _HERCMONO )
{
_setvideomode( _HERCMONO );
mi.xVirtual = 719;
}
__asm
{
mov ax, 8 ; Set minimum and maximum vertical
sub cx, cx ; Minimum is 0
mov dx, mi.yVirtual ; Maximum is 8 * rows (or rows SHL 3)
int 33h ; Adjust for 25, 30, 43, 50, or 60 lines
mov ax, 1 ; Turn on mouse pointer
int 33h
mov ax, 3 ; Get initial position and button status
int 33h
mov mi.xLast, cx ; Save internally
mov mi.yLast, dx
mov mi.fsBtnLast, bx
}
return mi.cBtn; /* Return the number of mouse buttons */
}
/* GetMouseEvent -检查看是否有一个老鼠事件。
如果事件*发生,更改事件结构。
-到事件结构的指针**回来: 1 如果事件, 0 如果没有事件*/
int GetMouseEvent( EVENT __far *pEvent )
{
int rtn;
/* 确定鼠标是否安装成功 */
if( !mi.fInit )
MouseInit();
if( !mi.fExist )
return 0;
__asm
{
mov ax, 3 ; Get Mouse position and button status
int 33h
sub ax, ax ; Assume no event
cmp cx, mi.xLast ; Has column changed?
jne event
cmp dx, mi.yLast ; Has row changed?
jne event
cmp bx, mi.fsBtnLast ; Has button changed?
je noevent
event:
mov ax, 1 ; If something changed, event occurred
mov mi.xLast, cx ; Update internal variables
mov mi.yLast, dx
mov mi.fsBtnLast, bx
noevent:
mov rtn, ax ; Set return value
}
if( rtn )
{
/*如果图形模式,以调整虚拟的老鼠位置实际*屏蔽坐标。*/
if( mi.fGraph )
{
pEvent->x = (short)((long)mi.xLast * mi.xActual) / mi.xVirtual;
pEvent->y = (short)((long)mi.yLast * mi.yActual) / mi.yVirtual;
}
/*如果文章模式,以1底调整虚拟的老鼠位置X,Y*/
else
{
pEvent->x = (mi.xLast >> 3) + 1;
pEvent->y = (mi.yLast >> 3) + 1;
}
pEvent->fsBtn = mi.fsBtnLast;
}
return rtn;
}
/*-得到不考虑的老鼠指针位置和按钮地位*是否有一个事件。
pEvent -到事件结构的指针**回来: 0 如果没有老鼠,不那样 */
int GetPtrPos( EVENT __far *pEvent )
{
/* 确定鼠标是否安装成功 */
if( !mi.fInit )
MouseInit();
if( !mi.fExist )
return 0;
__asm
{
mov ax, 3 ; Get Mouse position and button status
int 33h
les di, pEvent
mov es:pEvent[di].x, cx
mov es:pEvent[di].y, dx
mov es:pEvent[di].fsBtn, bx
}
/*如果图形模式,以调整虚拟的鼠标位置实际坐标位置。*/
if( mi.fGraph )
{
pEvent->x = (short)((long)pEvent->x * mi.xActual) / mi.xVirtual;
pEvent->y = (short)((long)pEvent->y * mi.yActual) / mi.yVirtual;
}
/*如果文章模式,以1底调整虚拟的老鼠位置X,Y*/
else
{
pEvent->x >>= 3;
pEvent->y >>= 3;
pEvent->x++;
pEvent->y++;
}
return 1;
}
/*集合指针可见性。
状态-显示出或隐蔽**回来: 0 如果没有老鼠,不那样 1 */
int SetPtrVis( PTRVIS pv )
{
/* 确定鼠标是否安装成功 */
if( !mi.fInit )
MouseInit();
if( !mi.fExist )
return 0;
__asm
{
mov ax, pv ; Show or hide mouse pointer
int 33h
}
}
/* SetPtrPos -设定鼠标指针位置
* Return: 0 if no mouse, otherwise 1
*/
int SetPtrPos( short x, short y )
{
/* 确定鼠标是否安装成功 */
if( !mi.fInit )
MouseInit();
if( !mi.fExist )
return 0;
/*如果图形模式,以调整虚拟的鼠标位置实际坐标位置。 */
if( mi.fGraph )
{
x = (short)((long)x * mi.xActual) / mi.xVirtual;
y = (short)((long)y * mi.yActual) / mi.yVirtual;
}
/*如果文章模式,以1底调整虚拟的老鼠位置X,Y*/
else
{
x--;
y--;
x <<= 3;
y <<= 3;
}
__asm
{
mov ax, 4 ; Set mouse position
mov cx, x
mov dx, y
int 33h
}
return 1;
}
int SetPtrShape( PTRSHAPE __far *ps ) //得到指针位置和按钮地位
{
/* 确定鼠标是否安装成功 */
if( !mi.fInit )
MouseInit();
if( !mi.fExist )
return 0;
/*如果图形模式,以调整虚拟的老鼠位置实际*屏蔽坐标。*/
if( mi.fGraph )
{
__asm
{
les di, ps
mov bx, es:[di].g.xHot ; Load hot spot offsets
mov cx, es:[di].g.yHot
mov dx, di
add dx, 4
mov ax, 9 ; Set graphics pointer
int 33h
}
}
else /*如果文章模式,以1底调整虚拟的老鼠位置X,Y*/
{
__asm
{
les di, ps
mov bx, 0 ; Use software cursor
mov cl, es:[di].t.chScreen
mov ch, es:[di].t.atScreen
mov dl, es:[di].t.chCursor
mov dh, es:[di].t.atCursor
mov ax, 10 ; Set text pointer
int 33h
}
}
return 1;
}
#pragma optimize( "", on )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -