文書番号: 402039
最終更新日: 2004/04/27
/* * int86 関数を使用した Microsoft(R) マウスドライバのサンプル * マウスのファンクションはベクタテーブル 33H を介してコールします。 */ #include <dos.h> #include <graph.h> #include <stdio.h> #include <stdlib.h> #include <conio.h> /* 関数のプロトタイプ宣言 */ void main(void); void mouse_style(int centerx,int centery, int far *mask); int mouse_reset(void); void mouse_on(void); void mouse_off(void); void mouse_getpos(int *x,int *y,int *stat); void mouse_setpos(int x,int y); void mouse_area(int xmin,int xmax,int ymin,int ymax); /* マウス範囲の定義 */ #define AREA_XMAX 600 #define AREA_YMAX 350 #define AREA_XMIN 50 #define AREA_YMIN 50 static union REGS inregs,outregs; static struct SREGS segregs; /* マウス形状の定義データ */ static int far cursor_and_mask[32]={ 0xfe3f, /* 1111 1110 0011 1111 */ 0xfc1f, /* 1111 1100 0001 1111 */ 0xf80f, /* 1111 1000 0000 1111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0xf007, /* 1111 0000 0000 0111 */ 0x0080, /* 0000 00001000 0000 */ 0x01c0, /* 0000 00011100 0000 */ 0x03e0, /* 0000 00111110 0000 */ 0x0000, /* 0000 00111110 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0, /* 0000 01111111 0000 */ 0x03e0 /* 0000 01111111 0000 */ }; /* * AREA_XMIN,AREA_XMAX,AREA_YMIN,AREA_YMAX の範囲でマウスオペレーション * を行います. * 現在のマウス位置を表示します. * ESC キーを押下すると終了します. */ void main(void) { int xpos,ypos,stat; _setvideomode( _MAXRESMODE ); /* QuickC2.0 では _98RESS16COLOR */ _displaycursor( _GCURSOROFF ); _setcolor ( 3 ); _rectangle( _GBORDER ,AREA_XMIN,AREA_YMIN,AREA_XMAX,AREA_YMAX); if( !mouse_reset()){ printf("\nmouse driver not installed "); exit(1); } mouse_style( 9,0,cursor_and_mask); mouse_on(); mouse_area( AREA_XMIN,AREA_XMAX,AREA_YMIN,AREA_YMAX ); mouse_setpos( 100, 100 ); _setcolor( 6 ); for(;;){ mouse_getpos( &xpos,&ypos,&stat); if(stat&0x01){ _settextposition( 3, 30 ); printf("LEFT "); } else if(stat&0x02){ _settextposition( 3, 30 ); printf("RIGHT"); } _settextposition( 1,1 ); printf("x : %3d y : %3d ", xpos,ypos); if( kbhit()){ if( getch() == 0x1b ) break; } } mouse_off(); _setvideomode( _DEFAULTMODE ); } /* マウスドライバの初期設定をします * <戻り値> 0: マウスドライバが組み込まれていません * -1: 正常終了 */ int mouse_reset() { inregs.x.ax = 0; int86( 0x33 ,&inregs,&outregs); return( outregs.x.ax ); } /* * マウスの形状を設定します. */ void mouse_style( int centerx,int centery, int far *mask ) { inregs.x.ax = 0x09; inregs.x.bx = centerx; inregs.x.cx = centery; segregs.es = FP_SEG( mask ); inregs.x.dx = FP_OFF( mask ); int86x( 0x33,&inregs,&outregs,&segregs); } /* * マウスカーソルを表示します. */ void mouse_on() { inregs.x.ax = 1; int86( 0x33 ,&inregs,&outregs); } /* * マウスカーソルを消去します */ void mouse_off() { inregs.x.ax = 2; int86( 0x33 ,&inregs, &outregs); } /* * マウスの現在位置,ボタン押下情報を取得します. */ void mouse_getpos( int *x,int *y,int *stat) { inregs.x.ax = 3; int86( 0x33 ,&inregs,&outregs); *x = outregs.x.cx; *y = outregs.x.dx; *stat = outregs.x.bx; } /* * マウスカーソル位置を設定します. */ void mouse_setpos( int x,int y) { inregs.x.ax = 4; inregs.x.cx = x; inregs.x.dx = y; int86( 0x33 ,&inregs,&outregs); } /* * マウスカーソルの移動範囲を設定します. */ void mouse_area( int xmin,int xmax,int ymin,int ymax ) { inregs.x.ax = 7; inregs.x.cx = xmin; inregs.x.dx = xmax; int86( 0x33 ,&inregs,&outregs); inregs.x.ax = 8; inregs.x.cx = ymin; inregs.x.dx = ymax; int86( 0x33 ,&inregs,&outregs); }
書籍名 :『マイクロソフト マウス プログラマーズ リファレンス』 著者 : Microsoft Corporation 訳 :マイクロソフト株式会社 編/発行 :富士ソフトウェア株式会社
Keywords: C6 C7 KBHOWTO QC20 VC10 VC15 KB402039
Technology: kbAudDeveloper kbCCompPDS600DOS kbCCompSearch kbQC200 kbvc150 kbVCsearch kbZNotKeyword3 kbZNotKeyword8