Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Using The Windows API
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 Alias, Private, And Public Keywords
These three keywords are optional components of a Declare statement. The Alias keyword lets you define an alternate name, or alias, for the DLL procedure. This allows you to use a different name to call the procedurea name other than the one it is assigned in the DLL. For example, the statement
Declare Function APIProc1 Lib MyDLL Alias APIProc2 () as Long
declares that the DLL named MyDLL contains a procedure named APIProc2, which we will call APIProc1 in the program.
Why are aliases necessary? The most common reason is that some DLL procedures have the same name as a Visual Basic reserved word. In this situation, trying to use the DLL procedure under its real name can cause confusion and errors. By assigning an alias, you can use both the DLL procedure and the reserved word without conflict. Other uses of Alias are internal to the API and are not related to Visual Basic itself. Declare statements that you copy from the API Text Viewer already contain the required aliases. The only time youll need to add one yourself is when a DLL function name conflicts with a Basic function or procedure that you defined in your program.
Using the Public and Private keywords allows you to control where in your program an API declaration is effective. This determines which of the programs modules can use the declared procedure. If a procedure is declared Public, you can use it in all of the programs modules. Public is the default, so including the keyword in the Declare statement is optional. A procedure declared Private can be used only by code in the module that contains the Declare statement. The Public or Private keyword goes at the beginning of the Declare statement:
Public Declare Sub APIProc1
Private Declare Function APIProc2
Within a form module, only Private procedure declarations are allowed, meaning that you can place Public declarations only in code modules. The primary use for making a procedure declaration Private occurs when you are writing a form module that you intend to use in other programs as a software component. A software component needs to be completely portable. This means that any API procedures it uses must be declared within the module, requiring the Private keyword. This ensures that the module is completely self-contained.
Declaring API Functions As Procedures
Most of the procedures in the API are functionsin other words, they return a value to the calling program. While your program will often need the return value, this will not always be the case. When an API functions return value is not needed, you can declare and use the API procedure as one that does not return a value, simplifying its use in the program. For example, the SetTextAlign API procedure specifies the alignment of text that is printed on the screen. It is a function with the following declaration:
Declare Function SetTextAlign Lib gdi32 (ByVal hDC As Long, _
ByVal wFlags As Long) As Long
A Visual Basic program would call it this way:
RetVal = SetTextAlign(...)
The value this API function returns is the previous text alignment setting. This value is not much use to most programs. To use SetTextAlign as a procedure, you would declare it as
Declare Sub SetTextAlign Lib GDI (ByVal hDC As Long, ByVal wFlags _
As Long)
and call it using the Call statement:
Call SetTextAlign(...)
You cannot define an API procedure as both a function and a procedure in the same program with the same name. If you want to use an API procedure both ways, you can declare it with an Alias name:
Declare Sub SetTextAlign Lib GDI (...)
Declare Function SetTextAlignFunction Lib GDI Alias _
SetTextAlign (...) As Long
You can then call it using whichever declaration fits the situation at hand:
Call SetTextAlign (...)
or
RetVl = SetTextAlignFunction (...)
A Windows API Demonstration
The program I will develop in this section not only shows you a real example of using an API procedure, but it also does something useful. When you use Visual Basics Print method to display text on a form or a Picture Box, the position of the text is determined by the objects CurrentX and CurrentY properties, which give the horizontal and vertical positions of the current position where the text will appear. The text is always left-aligned with respect to this position. Visual Basic itself provides no other alignment options.
You can, however, use a Windows API call to obtain different types of text alignmentboth vertical and horizontal. This is accomplished with the SetTextAlign procedure. Its declaration is:
Declare Sub SetTextAlign Lib gdi32 (ByVal hDC As Long, ByVal wFlags _
As Long)
The argument hDC specifies the hDC property of the object you are printing to, and the argument wFlags contains the flags specifying the desired text alignment. These flags specify the text justification with respect to the objects current position. You can specify both vertical and horizontal justification. The possible values for horizontal alignment are defined by the following Windows global constants:
TA_CENTERCenters the text at the current position
TA_LEFTPositions the left edge of the text at the current position (the default)
TA_RIGHTPositions the right edge of the text at the current position
You can also specify vertical alignment. To understand vertical alignment, consider the total vertical extent that characters can span, using these terms:
BOTTOMThe lowest any character extends, such as the descenders on g and y
TOPThe highest any character extends, such as tall uppercase letters or diacritical marks, such as Ä and é
BASELINEThe bottom of characters that dont have descenders, such as a and c
The vertical alignment options are defined using the following terms:
TA_BASELINEFont baseline aligned with the current position
TA_BOTTOMFont bottom aligned with the current position
TA_TOPFont top aligned with the current position (the default)
Because the available text alignment settings operate with respect to the objects current position, the SetTextAlign procedure does not align text with respect to the edges of the print area, as a word processing program does. If you want to specify alignment with respect to the object edges, you must do some fiddling in code. For example, to right-align text in a Picture Box so that the right edge of the text lines up with the right edge of the Picture Box, set the Picture Boxs CurrentX property to the right edge (obtained from the ScaleWidth property), then use the SetTextAlign procedure to set right alignment before displaying the text with the Print method. Similarly, to center text in a Picture Box, first set CurrentX to the center of the box (ScaleWidth/2) and then use SetTextAlign to specify center alignment.
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:
27 02 2014 Terminologia DługoszTPW 1CA; 27 02 2011 rodzina jako systemPszczoły innowacyjne metody Lipsko 27 02 2011ustawa o przeciwdziałaniu przemocy w rodzinie 27,02,2015Obama ogłosił termin wycofania żołnierzy z Iraku (27 02 2009)TI 01 02 27 T pl(2)Przyklad 01 2012 02 2702 (27)TI 02 05 27 B pl(2)więcej podobnych podstron