精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>DOS编程>>Re: turbo c 为什么不能使鼠标?

主题:Re: turbo c 为什么不能使鼠标?
发信人: riffle()
整理人: wenbobo(2002-08-13 10:47:41), 站内信件
【 在 xinzi (新子) 的大作中提到: 】

  以下为我的一个模块 MOUSE.CPP,可以参考一下,看是否有帮助。


#include <STDIO.H>
#include <DOS.H>
#include <STDLIB.H>

#include "MOUSE.H"

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#define MOUSE_INT 0x33               //鼠标驱动中断号

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

static BOOL Mouse_Checked = FALSE;   // 是否已经检查过鼠标的存在
static BOOL Mouse_Installed = FALSE; // 鼠标驱动器是否已经安装

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

// 设置光标最大列范围
static void Set_Cursor_X_Range( int Min_X, int Max_X );
// 设置光标最大行范围
static void Set_Cursor_Y_Range( int Min_Y, int Max_Y );

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/*****************************************************************/
/*-- 设置鼠标水平运动范围 程序开始 ------------------------------*/
static void Set_Cursor_X_Range( int Min_X, int Max_X )
{
  if ( HaveMouse() )
    {
      union REGS inregs;
      union REGS outregs;

      inregs.x.ax = 0x0007;
      inregs.x.cx = Min_X;
      inregs.x.dx = Max_X;

      int86( MOUSE_INT, &inregs, &outregs );
    }
}
/*-- 设置鼠标水平运动范围 程序结束 ------------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 设置鼠标垂直运动范围 程序开始 ------------------------------*/
static void Set_Cursor_Y_Range( int Min_Y, int Max_Y )
{
  if ( HaveMouse() )
    {
      union REGS inregs;
      union REGS outregs;

      inregs.x.ax = 0x0008;
      inregs.x.cx = Min_Y;
      inregs.x.dx = Max_Y;

      int86( MOUSE_INT, &inregs, &outregs );
    }
}
/*-- 设置鼠标垂直运动范围 程序结束 ------------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 显示光标 程序开始 ------------------------------------------*/
void ShowCursor( void )
{
  if ( HaveMouse() )
    {
      union REGS regs;
      regs.x.ax = 0x0001;
      int86( MOUSE_INT, &regs, &regs );
    }
}
/*-- 显示光标 程序结束 ------------------------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 隐藏光标 程序开始 ------------------------------------------*/
void HideCursor( void )
{
  if ( HaveMouse() )
    {
      union REGS regs;
      regs.x.ax = 0x0002;
      int86( MOUSE_INT, &regs, &regs );
    }
}
/*-- 隐藏光标 程序结束 ------------------------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 设置鼠标中断速率 程序开始 ----------------------------------*/
void SetMouseIntRate( unsigned int Rate )
{
  if ( HaveMouse() )
    {
      if ( Rate > 4 )
Rate = 0;

      union REGS regs;

      regs.x.ax = 0x001C;
      regs.x.bx = Rate;

      int86( MOUSE_INT, &regs, &regs );
    }
}
/*-- 设置鼠标中断速率 程序结束 ----------------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 设置光标运动范围 程序开始 ----------------------------------*/
void SetCursorRange( int Min_X, int Max_X, int Min_Y, int Max_Y )
{
  Set_Cursor_X_Range( Min_X, Max_X );
  Set_Cursor_Y_Range( Min_Y, Max_Y );
}
/*-- 设置光标运动范围 程序结束 ----------------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 设置光标位图及热点 程序开始 --------------------------------*/
void Set_Cursor_BitMap( int Hot_X, int Hot_Y,
unsigned int *BitMap )
{
  if ( HaveMouse() )
    {
      union REGS inregs;
      union REGS outregs;
      struct SREGS segregs;

      inregs.x.ax = 0x0009;
      inregs.x.bx = Hot_X;
      inregs.x.cx = Hot_Y;

      inregs.x.dx = FP_OFF( BitMap );
      segregs.es = FP_SEG( BitMap );

      int86x( MOUSE_INT, &inregs, &outregs, &segregs );
    }
}
/*-- 设置光标位图及热点 程序结束 ----------------------------------*/

/*******************************************************************/


/*******************************************************************/

/*-- 设置文本光标 程序开始 ----------------------------------------*/

void Set_Text_Cursor( unsigned int Begin_Scan_Line,
      unsigned int End_Scan_Line )
{
  if ( HaveMouse() )
    {
      union REGS regs;
      regs.x.ax = 0x000A;
      regs.x.bx = 0x0001;
      regs.x.cx = Begin_Scan_Line;
      regs.x.dx = End_Scan_Line;

      int86( MOUSE_INT, &regs, &regs );
    }
}
/*-- 设置文本光标 程序结束 ----------------------------------------*/

/*******************************************************************/


/*******************************************************************/

/*-- 检查是否安装了鼠标驱动器 程序开始 ----------------------------*/

BOOL HaveMouse( void )
{
  if ( !Mouse_Checked )
    {
      void interrupt ( *Mouse_Handler )( __CPPARGS );

      Mouse_Handler = getvect( MOUSE_INT );

      if ( Mouse_Handler != NULL )
{
  union REGS inregs;
  union REGS outregs;

  inregs.x.ax = 0;

  int86( MOUSE_INT, &inregs, &outregs );

  if ( outregs.x.ax == 0xFFFF )
    Mouse_Installed = TRUE;
}

      Mouse_Checked = TRUE;
    }

  return Mouse_Installed;
}
/*-- 检查是否安装了鼠标驱动器 程序结束 --------------------------*/
/*****************************************************************/

/*****************************************************************/
/*-- 取鼠标按钮事件 程序开始 ------------------------------------*/
// 其中Cursor_X,Cursor_Y表示发生鼠标事件的 x坐标和y坐标
// Mouse_Status 的意义见《PC中断大全》
BOOL GetMouseClick( int &Mouse_Status,
    int &Cursor_X,
    int &Cursor_Y )
{
  if ( HaveMouse() )
    {
      union REGS inregs;
      union REGS outregs;

      inregs.x.ax = 3;

      int86( MOUSE_INT, &inregs, &outregs );

      if ( outregs.x.bx & 0x07 )
{
  Mouse_Status = outregs.x.bx & 7;
  Cursor_X = outregs.x.cx;
  Cursor_Y = outregs.x.dx;
  return TRUE;
}
      else
return FALSE;
    }
  else
    return FALSE;
}
/*-- 取鼠标按钮事件 程序结束 ------------------------------------*/
/*****************************************************************/

/*****************************************************************/
BOOL Mouse_Moved( void )
{
  if ( HaveMouse() )
    {
      union REGS regs;
      union REGS outregs;

      regs.x.ax = 0x000B;
      int86( MOUSE_INT, &regs, &outregs );
      if ( ( outregs.x.cx != 0 ) || ( outregs.x.dx != 0 ) )
return TRUE;
      else
return FALSE;
    }
  else
    return FALSE;
}
/*****************************************************************/

/*****************************************************************/
BOOL GetMouseIRQ( unsigned char &MouseIRQ )
{
  if ( HaveMouse() )
    {
      union REGS regs;
      union REGS outregs;

      regs.x.ax = 0x0024;
      int86( MOUSE_INT, &regs, &outregs );
      MouseIRQ = outregs.h.cl;
      return TRUE;
    }
  else
    return FALSE;
}
/*****************************************************************/

/*****************************************************************/
/*-- 全部函数结束 -----------------------------------------------*/
/*****************************************************************/

这样定义BOOL: enum BOOL { FALSE, TRUE };
在 MOUSE.H中声明所有非静态函数;需要使用鼠标的模块包
括MOUSE.H就可以了

--
※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.104.37.102]

[关闭][返回]