Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Graphics
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 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
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
The MouseDown event procedure has the same details. Lets go over the arguments:
ButtonIndicates which button was pressed: left button = 1, right button = 2, center button = 4.
ShiftIndicates the state of the keyboard when the event occurred, whether the Shift, Ctrl, and/or Alt keys were pressed: Shift = 1, Ctrl = 2, Alt = 4. If more than one of these keys is pressed, the values are summed. For example, if Ctrl+Shift is pressed, then Shift is equal to 3.
X and YIndicates the position where the mouse pointer was located in the objects coordinate system when the event occurred.
When testing for buttons and/or Shift keys, you can use the predefined constants shown in Table 12.4.
As you can see, the MouseUp and MouseDown event procedures have everything we need. We can determine not only which button was clicked, but at which location.
TIP: Mouse-Related Events
Visual Basic has four events related to clicking the mouse. If youre not clear about how they relate to each other, you may end up with some subtle and hard-to-find bugs in your programs.
The MouseDown event occurs when the user presses a mouse button. The object that the mouse pointer is over then captures the mouse. This means that the object will receive all mouse events up to and including the MouseUp event when the mouse button is releasedeven if the mouse has been moved off the object while the button was down. The Click event, however, is generated only if both the MouseDown and MouseUp events occur on the object. If the mouse is moved off the object before releasing the button, the object receives a MouseDown and a MouseUp event, but no Click event. If the button is released on the object, then the events occur in the order MouseDown, MouseUp, Click. If you double-click on an object, the event order is MouseDown, MouseUp, DblClick, MouseUp.
Now we can get to the code that does the actual work. If we detect a left-button click, well want to perform the following steps:
1. Calculate the coordinates of a rectangle centered on the click location using the magnification constants defined in the declarations section of the program.
2. Check that the rectangle does not extend past the edges of the source picture. If it does, adjust it.
Table 12.4 Constants used to test for buttons and shift keys.
Constant
Value
Description
vbLeftButton
1
Left button is pressed
vbRightButton
2
Right button is pressed
vbMiddleButton
4
Middle button is pressed
vbShiftMask
1
Shift key is pressed
vbCtrlMask
2
Ctrl key is pressed
vbAltMask
4
Alt key is pressed
3. Call PaintPicture to copy the contents of this rectangle to the entire Picture2 Picture Box, thus magnifying it.
If its a right-button click, well follow these steps instead:
1. Use PaintPicture with the vbBlackness opcode to paint the entire destination Picture Box black.
2. Set up a nested loop. The outer loop will loop once for each of three rows, and the inner loop once for each of three columns.
3. In the inner loop, use PaintPicture with the vbWhiteness opcode to create nine white rectangles over the destination Picture Box, so that each one is slightly smaller than one-third of the Picture Box dimension.
4. Still in the inner loop, use PaintPicture with the vbSrcCopy opcode to put a small copy of the source picture on each of the white rectangles.
The code for these actions is in the MouseUp event procedure, which is shown in Listing 12.5, along with the rest of the forms code. Figure 12.7 shows the program after the user left-clicks on the source image, and Figure 12.8 shows the effects of a right-click.
When you run the program, you may notice one thing: If you cover the program window with another window, then redisplay it, the picture in the right Picture Box does not reappear. This is because the controls AutoRedraw property is at the default value of False. As a result, the graphic in the Picture Box is not persistent, as was discussed earlier in this chapter. If you set AutoRedraw to True, youll see the graphic is now persistent. Another way to achieve the same result without setting AutoRedraw to True is to put the statements that do the actual drawing (the calls to PaintPicture ) in the Picture Boxs Paint event procedure, where they will be executed every time the image needs to be refreshed.
Figure 12.7 Using the PaintPicture method to magnify part of a picture.
Figure 12.8 Using the PaintPicture method to create nine framed duplicates of a picture.
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. Read EarthWeb's privacy statement.
Wyszukiwarka
Podobne podstrony:
TI 00 12 07 T pl(2)TI 98 12 07 T B pl(1)12 072014 12 07 ZUSO Wykład 06ECU list ver 26 12 072005 12 0712 07 Roboty posadzkarskie i okladzinowe2011 12 07 2a1 SPR212 4 0796 12 07 praYr4 Group 3 Tests 07 12więcej podobnych podstron