?? 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 + -