792 795




Visual Basic 6 Black Book:Connecting To The Windows API And Visual C++
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




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


That’s it—now 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. We’ve captured the mouse. To release the mouse, just release the mouse button.


Figure 23.6  Using the mouse outside a program.
There’s 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 program’s window, everything is fine—the program retains control of the mouse while you drag. If, on the other hand, you press the mouse button outside the program’s 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 program’s 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 book’s accompanying CD-ROM.
Copying Bitmaps Between Device Contexts Quickly
One 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


Here’s what this function’s arguments mean:


•  hDestDC—The destination device context to copy to
•  x—The x-coordinate of the upper-left corner of the destination rectangle
•  y—The y-coordinate of the upper-left corner of the destination rectangle
•  nWidth—The width of the destination rectangle and source bitmap
•  nHeight—The height of the destination rectangle and source bitmap
•  hSrcDC—The source device context to copy from
•  xSrc—The logical x-coordinate of the upper-left corner of the source bitmap
•  ySrc—The logical y-coordinate of the upper-left corner of the source bitmap
•  dwRop—The raster operation to be performed

You can find the possible values for the dwRop argument in Table 23.4.
Table 23.4 BitBlt raster operations.
dwRop Constant
Operation

SRCCOPY = &HCC0020
destination = source

SRCPAINT = &HEE0086
destination = source OR destination

SRCAND = &H8800C6
destination = source AND destination

SRCINVERT = &H660046
destination = source XOR destination

SRCERASE = &H440328
destination = source AND (NOT destination)

NOTSRCCOPY = &H330008
destination = (NOT source)

NOTSRCERASE = &H1100A6
destination = (NOT src) AND (NOT destination)

MERGECOPY = &HC000CA
destination = (source AND pattern)

MERGEPAINT = &HBB0226
destination = (NOT source) OR destination

PATCOPY = &HF00021
destination = pattern

PATPAINT = &HFB0A09
destination = pattern OR source

PATINVERT = &H5A0049
destination = pattern XOR destination

DSTINVERT = &H550009
destination = (NOT destination)

BLACKNESS = &H42
destination = BLACK

WHITENESS = &HFF0062
destination = WHITE

We’ll put BitBlt to work when we capture the screen in the next topic.
Capturing Images From The Screen
We’ll 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 program’s 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.

Figure 23.7  Outlining a region on the screen.
When you release the mouse buttons, the region you’ve outline appears in the picture box in the program, as shown in Figure 23.8. You’ve captured an image from the screen.


Figure 23.8  Capturing a region of the screen.
Why do we have to drag the mouse before making the screen capture? There’s 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 program’s form itself and only release all mouse buttons when we’re done capturing the image we want.




Previous
Table of Contents
Next






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.



Wyszukiwarka

Podobne podstrony:
index (795)
793 795
20030817180632id!795
index (792)
795 800
790 792
792 (2)
mbdch20 792
mbdch20 795

więcej podobnych podstron