Contents xv Introduction xvii xix Part I Interfacing with the Mouse 1 How To Communicate with the Mouse: Interrupt 33 Hex The Mouse Driver Interrupt 33 Hex Interrupt Service Functions The Working Registers Declarations The General Registers Making a Function Call to the Mouse Driver Borland and Microsoft Compiler Compatibility Modifying C0MPILER.H Graphics and Text I/O 3 3 4 4 5 5 6 2 The Video Function Library Introduction to the Video Function Library Using the Same Format for Graphics and Text Modes Inner Workings of the Video Function Library Source Code for the Video Function Library The Borland Video Function Library The Microsoft Video Function Library Notes on the Video Function Library Testing the Video Function Library Compiling the Test Program Running the Test Program 11 11 11 12 15 15 21 28 29 29 30 6 The Ten Necessary Mouse Functions 33 7 9 10 Mouse Buttons The Mouse Functions Global Variables About Graphics and Text Modes 33 34 35 36 The Mouse Function Library Mouse Function 0: Reset and Status Determining Mouse Presence Number of Buttons Text Cell Sizes Mouse Cursor Size Your First Mouse Program The Invisible Mouse Cursor 36 44 45 46 46 47 47 49 Trapping Single Button Presses and Releases The Reverse Trap Double-Clicking Mouse Buttons Timing a Double-Click Determining a Double-Click Limiting Range in Sequential Applications 83 86 86 86 87 90 Limiting the Range Based on Mouse Cursor Size Warning: Mouse Function 38 51 52 I How To Keep A Mouse from Turning into a Rat The Golden Rule The Problem The Solutions Method 1: Hiding and Showing the Mouse Cursor Method 2: Setting an Exclusion Area EGA Registers, Compatibility, and OEM Mice EGAS.SYS The EGA_REG-READ Variable EGA Workaround Tracking the Mouse Cursor and Emulating Cursor Movement with the Keyboard Tracking Mouse Coordinates Tracking Text Coordinates in a Graphics Mode Emulating Mouse Cursor Movement with the Keyboard Moving the Mouse Cursor 6 Determining the Button Status and Limiting the Range of Movement The Button Functions 53 53 54 57 58 62 66 68 68 69 7 Creating an Event Handler The Problems with Polling What is an Event Handler? Installing an Event Handler The Call Mask Event Handler Address Mouse Functions Used to Install an Event Handler Mouse Function 12: Set Event Handler Limitations Overcoming the Limitations in Assembler Compiling the Event Handler Different Memory Models If You Don’t Have the Assembler Using the Event Handler 71 71 74 76 77 81 81 Compiling a Program that Uses the Event Handler File Order Stack Checking Integrated Environment Compiling Command-Line Compiling The New Header File Your First Program Using the Event Handler Terminating the Application and Event Handler Reseting the Global Status Variables The Full-Blown Event Handler/Processor Revisiting the touch_cursor() Function 95 95 96 96 96 97 97 98 100 100 107 108 108 111 111 112 112 112 113 115 115 117 118 118 122 Using the Mouse Cursor Coordinates Other Event Handler Functions Mouse Function 20: Swap Event Handlers Mouse Function 24: Set Alternate Event Handler The spawn () and exec () Functions Terminate-and-Stay-R&dent Applications (TSRs) Moving Forward 9 Handling Menus Floating Menus Keeping It Simple Horizontal Menu Considerations Vertical Menu Considerations Combined Menu Considerations The Floating Menu Program Finer Points and Details Restoring the Range Restoring the Mouse Cursor Position Resetting Event Status Variables Keyboard Input 10 Using the Mouse as a Crosshair Defining the Crosshair Interacting with the Mouse Cursor The Crosshair Algorithm Crosshair Restriction Crosshair Example Program Details Defining the Crosshair Turning the Mouse Cursor Off Cursor On Coordinates 123 123 123 124 124 125 125 Stretching a Graphics Object Dropping the Anchors The Undo Option XOR and COPY-PUT Drawing Modes Line Stretching Example Rectangle Stretching Example Ellipse Stretching Example 12 The Optional Mouse Functions 143 145 146 151 151 153 153 154 155 160 160 161 161 162 164 using the Mouse In CAD-Type Operations 165 Stretching or Dragging? 165 167 168 171 172 179 179 184 186 186 187 Six New Mouse Functions Using the Optional Functions About the Information Mouse Type and IRQ Number CRT Page Major and Minor Version Numbers 127 127 128 128 130 131 131 143 143 166 166 167 1.J 187 - Setting the Speed: Mickeys and Pixels 189 Mickeys Mickey-tGPiie1 Ratio Multiplication Factor DoubleSpeed Threshold Changing the Speed Speed Sensitivity Rates Speed Sensitivity Example Double-Speed Threshold Example Maximum Speed 189 190 190 190 190 191 192 194 198 14 Changing and Managing the 199 Graphics Mouse Cursor Graphics Mouse Cursor Mechanics The Screen and Cursor Masks Bit Expansion The Hot Spot Setting the Mouse Cursor Shape Windows-Style Cursor Management in DOS Sizing Arrows on Borders The Default Mouse Cursor Shape 200 200 201 203 203 208 208 209 15 The Mouse’s Text Cursor 229 The Two Types of Text Cursors The Software Text Cursor The Hardware Text Cursor Using the set_text_cursor() Function Modifying the Software Text Cursor Modifying the Hardware Text Cursor 16 Combining the Functions into One Library 229 230 230 231 231 234 239 A Real Mouse Function Library Library Files Creating the Library File Using the Library Using the Library with Your Own Applications 239 240 240 245 248 Part II Building Your Own Mouse Cursor and the Elusive 800 x 600 16-Color Mode 17 Building Your Own Mouse Cursor The Reason for Building Your Own Mouse Cursor The 800 x 600 16Color Super VGA Mode Existing Solutions A Universal Solution EGA/VGA Read/Write Mode 0 Cursor/Sprite Mechanics The Sprite Driver Low-Level Graphics Functions Sprite Functions The Sprite Driver Source Code Compiling SPRITELL.C On to the New Mouse Function Library 19 The New Mouse Function Library and Sprite Cursor 253 254 256 257 18 Building the Sprite Driver 259 The Graphics Mouse Cursor 260 290 291 Modifying the Mouse Function Library Show and Hide Functions Setting an Exclusion Area Event Processor Cursor Position The New Mouse Function Library Compiling M0USEDRV.C Combining the Event Handler, Mouse Function Library, and Sprite Driver The New Library Header File Using the Sprite Cursor Initializing the Sprite Cursor Destroying the Sprite Cursor The Default Mouse Cursor 20 The Sprite Cursor in the 800 x 600 16-Color Mode 253 260 262 263 264 265 266 288 291 291 292 292 292 293 304 306 306 310 313 316 316 317 New Video Functions Running in Any 16-Color Mode Setting the 800 x 600 16-Color Mode Verifying Proper Behavior 317 322 326 326 21 Sprite Usage Rules and Features 333 Sprite Cursor Usage Rules Global Variables Valid Ranges Display Boundaries Hiding the Sprite Cursor 333 333 334 334 334 Switching Cursors 335 Keeping the Event Handler Active 335 Destroying the Sprite Cursor 336 Sprite Features 336 Modifying the Sprite Color and Write Mode 337 Changing the Sprite Cursor Mask 342 Using Other Sprites 348 Dual Sprite Cursors 348 The Dual Cursor CAD Mirror Program 350 Part III Interfacing with the Mouse in Windows 22 The Generic Windows Program Windows, the Big Event Processor Communicating with the Mouse in Windows The Fundamental Windows Program The Module Definition File Compiling GENERIC.C Running GENERIC.EXE Understanding GENERIC.C Understanding GENERIC.DEF 23 Windows Mouse Button Messages Button Press and Release Messages Additional Information from Button Messages Detailed Information in the Client Area Detailed Information in the Nonclient Area Double-Click Time 367 368 368 369 371 371 374 376 380 383 383 390 391 398 405 24 Changing the Windows Cursor The Standard Windows Cursors Setting the Default Registered Cursor Loading Windows Cursors on the Fly WM_MOUSEMOVE WM_SETCURSOR Creating and Using Your Own Cursors Resource Cursors Dynamic Cursors 413 414 414 414 420 420 426 427 434 25 Additional Windows Mouse445 Related Topics Tracking Cursor Coordinates in Windows Emulating Mouse Movement with the Keyboard Determining Mouse Presence Moving the Cursor with the Keyboard The Internal Display Count Limiting Range of Movement Keyboard Mouse-Emulation Program Scope WM_NCHITTEST 445 450 452 452 452 454 455 461 462 Part IV Appendixes A The 50 Documented Mouse 465 Functions Conventions Mouse Function 0: Mouse Reset and Status 465 466 Mouse Function 1: Show Cursor 468 Mouse Function 2: Hide Cursor 468 Mouse Function 3: Get Button Status and Cursor Position 469 Mouse Function 4: Set Mouse Cursor Position 470 Mouse Function 5: Get Button Press Information 471 Mouse Function 6: Get Button Release Information 472 Mouse Function 7: Set Min/Max Horizontal Cursor Position 473 Mouse Function 8: Set Min/Max Vertical Cursor Position 474 Mouse Function 9: Set Graphics Cursor 475 Mouse Function 10: Set Text Cursor 476 Mouse Function 11: Read Mouse Motion Counters 477 Mouse Function 12: Set Event Handler 478 Mouse Function 13: Light-Pen Emulation Mode On 479 Mouse Function 14: Light-Pen Emulation Mode Off 480 Mouse Function 15: Set Mickey-to-Pixel Ratio 480 Mouse Function 16: Set Exclusion Area 481 Mouse Functions 17 and 18: Undocumented 482 Mouse Function 19: Set Double-Speed Threshold 482 Mouse Function 20: Swap Event Handlers 483 Mouse Function 21: Get Mouse Driver State Buffer Size 485 Mouse Function 22: Save Mouse Driver State 485 Mouse Function 23: Restore Mouse Driver State 486 Mouse Function 24: Set Alternate Event Handler 487 Mouse Function 25: Get Alternate Event Handler 489 Mouse Function 26: Set Sensitivity Rate 490 Mouse Function 27: Get Sensitivity Rate 491 Mouse Function 28: Set Mouse Interrupt Rate 491 Mouse Function 29: Set CRT Page Number 492 Mouse Function 30: Get CRT Page Number 493 Mouse Function 31: Disable Mouse Driver 494 Mouse Function 32; Enable Mouse Driver 494 Mouse Function 33: Software Reset 495 Mouse Function 34: Set Language for Messages 496 Mouse Function 35: Get Language Number 497 Mouse Function 36: Get Driver Version, Type, and IRQ # 498 Mouse Function 37: Get General Driver Information 500 Mouse Function 38: Get Maximum Virtual Coordinates 501 Mouse Function 39: Get Screen and Cursor Mask Values and Mickey Count 502 Mouse Function 40: Set Video Mode 503 Mouse Function 41: Enumerate Video Modes 504 Mouse Function 42: Get Cursor Hot spot 505 Mouse Function 43: Load Acceleration Curves 506 Mouse Function 44: Read Acceleration Curves 508 Mouse Function 45: Set/Get Acceleration Curve 509 Mouse Function 46: Undocumented 510 Mouse Function 47: Mouse Hardware Reset 510 Mouse Function 48: Set/Get Ballpoint Information 511 Mouse Function 49: Get Min/Max Virtual Coordinates 512 Mouse Function 50: Get Active Advanced Function 513 Mouse Function 51: Get Switch Settings 514 Mouse Function 52: Get MOUSE.INI 516 B Windows Mouse and Cursor Functions 517 ClipCursor CreateCursor DestroyCursor GetCapture GctClipGursor GetCursorPos GetDoubleClickTime LoadCursor ReleaseCapture SetCapture SetCursor SetCursorPos 518 519 519 520 520 521 521 521 523 523 523 524 SetDoubleClickTime ShowCursor SwapMouseButton C Windows Mouse Messages HIWORD( ) and LOWORD( ) Client Area Button Messages Nonclient Area Button Messages WM_MOUSEACTIVATE WM_MOUSEMOVE WM_NCHITTEST WM_NCMOUSEMOVE WM_SETCURSOR 524 525 525 527 527 527 528 529 530 531 532 532