|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Finally, when the user releases the mouse button, we release the mouse with ReleaseCapture and reset the Boolean flags:
Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, _
y As Single)
If blnAmCapturing Then
ReleaseCapture
blnStartCapture = False
blnAmCapturing = False
Command1.Caption = "Start capture"
End If
End Sub
Thats itnow run the program, as shown in Figure 23.6. Click the button in the program and drag the mouse. No matter where you drag the mouse, the mouse location is displayed in the text boxes in the program. Weve captured the mouse. To release the mouse, just release the mouse button.
Theres one peculiarity you should know about here: starting with Windows 95, you can only capture the mouse for one mouse operation; when you finish with the mouse, it is released. That means if you start the mouse drag by pressing the mouse button while inside the programs window, everything is finethe program retains control of the mouse while you drag. If, on the other hand, you press the mouse button outside the programs window and start to drag, the mouse is released. You can remedy this problem, as we do in our screen capture program later in this chapter, by using the right mouse button for mouse operations. In that program, we have the users drag the mouse by pressing the mouse button in the programs window, dragging the mouse to the top left of the rectangle they want to capture, then use the right mouse button (while holding the left one down) to capture that rectangle. The code for this program is located in the mousecap folder on this books accompanying CD-ROM. Copying Bitmaps Between Device Contexts QuicklyOne of the most common reasons to use Windows API functions is to make fast bitmap transfers, which you can do with the BitBlt function. This function lets you copy a bitmap from one device context to another very quickly:
Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As _
Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal _
nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal _
ySrc As Long, ByVal dwRop As Long) As Long
Heres what this functions arguments mean:
You can find the possible values for the dwRop argument in Table 23.4.
Well put BitBlt to work when we capture the screen in the next topic. Capturing Images From The ScreenWell put together the previous topics in this chapter into one substantial screen capture example: screencap. Using this program, you can capture sections of the screen and display them in a picture box. When you run this program, press the left mouse button on the programs form, then drag the mouse to the top left of the rectangular region you want to capture. Then, using the right mouse button (while holding the left one down) draw the rectangle you want to capture. A box outlining that region will appear on the screen as you move the mouse, as shown in Figure 23.7.
When you release the mouse buttons, the region youve outline appears in the picture box in the program, as shown in Figure 23.8. Youve captured an image from the screen.
Why do we have to drag the mouse before making the screen capture? Theres a peculiarity in mouse capture starting in Windows 95: when you capture the mouse, you can only hold it until you finish with a mouse operation; when you do, the mouse is released. To hold the mouse, we start the dragging process in the programs form itself and only release all mouse buttons when were done capturing the image we want.
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |