2007年12月22日星期六

【VB】对话框译文

Show the "Save File" Common Dialog

显示"保存文件"对话框

Show the "Browse Folder" Common Dialog

显示"浏览文件夹"对话框

Suspend a Computer

挂起计算机

Test if an application is responding and terminate application

测定一个应用程序是响应还是终止(IE为例)

Test if an application is responding and terminate application

(续:)测定一个应用程序是响应还是终止

Format a floppy disk

格式化软盘

Zero a portion of an array

清零一个数组

Determine the free space on a drive

测定驱动器上的空闲空间

Edit the files stored in the "Documents" menu

编辑保存在文档菜单的文件

Copy files using the File Copy Shell

使用File Copy Shell拷贝文件

Show the "File Open" Common Dialog

显示"文件打开"对话框

Converting Class IDs to a Prog IDs and back

转变class ID到一个prog ID

Obtaining the current user name

获得当前用户名

Return the path of the temporary directory

返回临时目录的路径

Return the path of the windows directory

返回windows目录的路径

Return the path of the system directory

返回system目录的路径

Create a GUID

创建一个GUID

Enable and Disable the windows task bar

激活和禁止windows任务条

Determining the system folder locations

设定system文件夹的位置

Obtaining information about the operating system

获得操作系统的信息

Find the path of the executable associated with a file

找到文件的完整路径

Locking the application screen area

锁住应用程序客户区。

Lock All GUI updating

阻止所有的GUI更新

Changing the screen resolution/colors

改变screen颜色

Convert a pointer to a string into a string

返回指向的字符串

Associate a file with a file extension

给文件扩展名关联打开文件

Shutdown/restart/logoff the local machine

关机,重启动,注销,本地计算机

Display the "Setup Prompt for Disk" dialog

显示"Setup Prompt for Disk"对话框

Display the "Setup Reboot" dialog

显示"Setup Reboot"对话框

Perform a recursive search for a file or pattern using API

使用api递归查找文件

Block keyboard and mouse input to an application

一个阻塞键盘和鼠标输入的应用程序

Return a dialog handle/class name from a caption

从标题栏里返回对话框的句柄名

Restrict the movement of a cursor to a specified area

限制鼠标指针的运动区域

Encrypt a file/folder (Windows 2000)

加密文件/文件夹(Windows 2000适用)

Setting the tab positions in a listbox

在列表框里设置tab的位置

Find an item in a listview

查找列表框的一项

Get a list of file version details for OCX, EXE and DLL files

得到一个OCX, EXE and DLL 文件的详细版本信息

Get and set a dialogs caption/title

取得和设置一个对话框标题

Controlling the clipboard (inc. clear, copy and query)

控制剪贴板

Get and set the list area width of a combo box

得到和设置一个组合框的列表宽度

Change to priority level of the current process

改变当前线程的优先级

Show the "System Settings Changed, Restart Computer?" dialog

显示"System Settings Changed, Restart Computer?"对话框

Creating new threads to perform asynchronous tasks

创建一个新的线程执行异步任务

Get and set volume information for a drive

得到和设定驱动器的卷信息

Using the ShellExecute API to send mails and print documents

使用ShellExecute API发送email和打印文档

Get the error message associated with and API error number

API error 号表示错误消息

Save a screen snapshot to a bitmap

bitmap格式保存一个屏幕快照。

Load and Save Images to a Database

在数据库里读出和保存图象

Changing a files created, modified and accessed times.

改变文件创建和修改,保存时间

Changing a files created, modified and accessed times.

()改变文件创建和修改,保存时间

Show system shut down/restart dialog

显示系统,关闭/重启 对话框

Checking to see if an application is already running

检查应用程序是否已运行

Search a folder (and all it''''s subfolders) for a file

在一个文件夹里搜查一个文件

Create a name for a temporary file

为临时文件创建一个名城

View the contents of a block of memory

显示某块内存的内容

List/Enumerate all the OCX Controls installed on a computer

列举安装在计算机里的所有ocx控件

Returning an ExitCode parameter from an out of process application

从外部应用程序返回参数

Check if a loggin password and user name are correct

检查当前登录的密码和用户名是不是正确的。

Removing an item from a 1d array

在一维数组中移动一个元素

Changing the type of input a textbox can receive

改变文本框输入的类型(比如只能输入数字)

Changing the way a form is repainted while being dragged

改变拖动时窗口的重画方式

Terminate a Process

终止一个进程

Making a textbox resizable

建立可变尺寸的文本框

Swap the left and right mouse buttons over

按下按钮交换左由鼠标键。

Controlling the position of a MsgBox

控制MsgBox函数弹出消息框的位置

Returning the windows handle of a dialog at a specified point

返回指向对话框的句柄

Returning a files creation time

返回文件的创建时间

Adding custom system menu items to forms

给窗体加上定制的系统菜单

Register Components without using Regsvr32.exe

不使用Regsvr32.exe注册组件

Uncover internal DLL functions with Dependency Walker

公布内部调用的dll函数

Launch a PC''''s default browser with ShellExecute API

ShellExecute API函数启动默认的浏览器

Get File Version Information Details (OCX, EXE, DLL etc)

得到详细的文件版本信息

Create a timer using API calls

使用api创建一个时钟。

Play an audio file

播放音频文件

Set and get a Computer''''s name

设置和得到计算机名

Shell and wait for a process to finish

启动并等待一个进程结束

Make the current process pause/sleep for a specified time period

指定当前进程挂起时间

Determine system memory status

测定系统的内存状态

Send files to the Recycle bin

把文件送入回收站

Get a list of the system processes

得到系统进程的列表

Redim Preserve a 2d array

重定义2维数组

Turn the Screen Saver on or off

启动或禁止Screen Saver

Return the error message associated with Err.LastDllError

返回带Err.LastDllError的错误消息

Turn the monitor on and off

启动或禁止监视器

Show the "Choose a Color" Common Dialog

显示"选择颜色"对话框

Show the "Select a Font" Common Dialog

显示"选择字体"对话框

Show the Windows "Run" Dialog

显示windows"运行"对话框

Change Date Format of the system

改变系统的日期格式

Change your Novell Password

改变你的Novell密码

Shutdown your computer using ExitWindowEx API Call

使用ExitWindowEx API 关闭你的计算机

Adding AutoComplete to a VB Text Box

VB文本框加入自动完成功能

drop Down Combo box as it get focus

当组合框得到焦点时下拉组合框列表

this makes form transperent only controls are visible

制作仅控件可见的透明窗体

Map and Unmap network drives using Windows "Map Network Drives" dialog

使用Windows "Map Network Drives"对话框映射和不映射网络驱动器

Simple Code to Map a Network Drive

映射一个网络驱动器的简单代码

Get your Computer name using GetComputerName API

使用GetComputerNameapi得到你的计算机名

Get your windows system directory using GetSystemDirectory API

使用GetSystemDirectory API得到windows的系统目录

Get your windows temp directory using GetTempPath API

使用GetTempPath API得到windows的临时目录

Get your windows directory using GetWindowsDirectory API

使用GetWindowsDirectory API得到windows目录

Set your computer name using SetComputerName API

使用SetComputerName API设置你的计算机名

Clear the recent documents menu using SHAddToRecentDocs API

使用SHAddToRecentDocs API清除最近的文档菜单

Add a file to recent documents menu using SHAddToRecentDocs API

使用SHAddToRecentDocs API加一个文件到最近的文档菜单

To show/hide cursor using

显示/隐藏鼠标指针。

Swap the mouse button using SwapMouseButton API

使用SwapMouseButton API交换鼠标按钮

Connect or disconnect a network drive

连接或断开网络驱动器

Connect or disconnect a LPT port

连接或断开一个LPT端口

Display the windows About Box using ShellAbout API

使用ShellAbout API函数显示windows关于对话框

Get logged in username using GetUserName API

使用GetUserName API得到登录者的用户名

Get network logged in username using WNetGetUser API

使用WNetGetUser API得到网络的登录用户名

Copy a file using CopyFile API

使用CopyFile API copy一个文件

Move a file using MoveFile API

使用MoveFile API移动一个文件

Some API funcitons to move, hide/show the mouse

一些API函数,移动,隐藏/显示鼠标

This Includes ALL of Karthikeyans API Code into module-type procedures.

在模块里包括所有的Karthikeyans API代码

Some API functions for hiding/showing/moving the mouse, etc... enjoy.

一些API函数隐藏/显示/移动 鼠标等等。

Code to Display the % of Memory in Use

显示内存使用%的例子

choose the frequency and duration of sounds from the internal speaker

选择频率和持续时间,让内置扬声器发声

Put your application to sleep for a certain number of milliseconds.

让你的应用程序睡眠指定的秒数

Find out whether or not a laptop is running on battery power and if so how much battery time is remaining.

测定手提式电脑是否在使用电池运行,并且测试出它的剩于电池量

Find out the processor type of a system and the total number of processors in a machine

测定系统的cpu类型,和机器里cpu的个数。

Find Files using FindFirstFile,FindNextFile and FindClose API

使用FindFirstFile,FindNextFile and FindClose API查找文件

Show,Hide,Maximize,Minimize,Restore and more with ShowWindow API

ShowWindow API显示隐藏最大化最小化恢复。

Set window text using SetWindowText API

使用SetWindowText API设置控件窗口的文本

Set Disk Volume Label using SetVolumeLabel API

使用SetVolumeLabel API设置磁盘卷标

Set System Cursor using SetSystemCursor API

使用SetSystemCursor API设置系统鼠标

Get File Attributes using GetFileAttributes API

使用GetFileAttributes API得到文件属性

Set File atrributes using SetFileAttributes API

使用SetFileAttributes API设置文件属性

Get Environment Variable using GetEnvironmentVariable using API

使用GetEnvironmentVariable API得到环境变量

Set Environment Variable using SetEnvironmentVariable API

使用SetEnvironmentVariable API设置环境变量。

Remove Directory using RemoveDirectory API

使用RemoveDirectory API移动目录

Create Directory using CreateDirectory API

使用CreateDirectory API创建目录

Play system sounds using MessageBeep API

使用MessageBeep API播放系统声音

Get Current Greewich Mean Time using GetSystemTime API

使用GetSystemTime API得到当前的Greewich时间

Set System Time using SetSystemTime API

使用SetSystemTime API设置系统时间

Set double click time of mouse using SetDoubleClickTime API

使用SetDoubleClickTime API设置鼠标的双击间隔速度

Get double click time of mouse using GetDoubleClickTime API

使用GetDoubleClickTime API得到鼠标的双击间隔速度

Delete a File using DeleteFile API

使用DeleteFile API删除文件

Get Volume Information of disk drive using GetVolumeInformation API

使用GetVolumeInformation API得到磁盘驱动器的卷标信息

To check whether particular drive is present or not using GetLogicalDrives API

使用GetLogicalDrives API检查驱动器

Get the amount of physical and virtual memory free,used using GlobalMemoryStatus API

使用GlobalMemoryStatus API得到空闲物理和虚拟内存数。

Get current resolution,number of colors and bits/pixels using GetDeviceCaps API

使用GetDeviceCaps API得到当前分辨率颜色数和象素。

Check whether sound card is installed or not using waveOutGetNumDevs API

使用waveOutGetNumDevs API检查声卡是否安装

Check whether network is installed or not using GetSystemMetrics API

使用GetSystemMetrics API检查网络是否安装

Check whether mouse is installed or not using GetSystemMetrics API

使用GetSystemMetrics API检查鼠标是否安装

Get default Icon Width using GetSystemMetrics API

使用GetSystemMetrics API得到缺省图标的宽度

Get current resolution using GetSystemMetrics API

使用GetSystemMetrics API得到当前的分辨率。

Check how your windows booted using GetSystemMetrics API

使用GetSystemMetrics API检查你的windows启动模式

Returns the height and width in pixels of a string based on the current font characteristics

用象素单位返回当前特征字串的高和宽。

Extract,Draw and Destroy Icon using ExtractIcon,DrawIcon and DestroyIcon API

使用ExtractIcon,DrawIcon DestroyIcon API提取画和销毁图标。

Get details about your OS using GetVersionEx API

使用GetVersionEx API得到你的操作系统的详细信息

Writing a string data into WIN.INI using WriteProfileString API

使用WriteProfileString API写字符数据到win.ini

Get a string data from WIN.INI using GetProfileString API

使用GetProfileString APIwin.ini得到字符数据

Get a integer data from WIN.INI using GetProfileInt API

使用GetProfileInt APIwin.ini,得到一个整型数据

Write a string data to an INI file using WritePrivateProfileString API

使用WritePrivateProfileString API写一个字符数据到一个ini文件

Write a section of data to an INI file using WritePrivateProfileSection API

使用WritePrivateProfileSection API写部分数据到一个ini文件

Get an integer data from an INI file using GetPrivateProfileInt API

使用GetPrivateProfileInt APIINI文件得到整型数据

Get a string data from an INI file using GetPrivateProfileString API

使用GetPrivateProfileString APIini文件得到字符数据

Get the length of a string using

得到使用的字符串的长度

Copy a string to another variable using lstrcpy API

使用lstrcpy API拷贝字串到别的类型变量

Copy n-1 number of characters from source string to the target string using lstrcpyn API

使用lstrcpyn API从源字串copy n-1特征字符数到目标字串。

Display Shutdown dialog screen using ExitWindowsDialog API

使用ExitWindowsDialog API显示关闭屏障对话框

Display shutdown dialog screen using SHShutDownDialog API

使用SHShutDownDialog API显示关闭屏障对话框。

Display the restart or shutdown dialog using RestartDialog API

使用RestartDialog API显示重启或关闭对话框

Display shutdown or restart dialog using SHRestartSystemMB API

使用SHRestartSystemMB API显示关闭或重启对话框

Display the run dialog using SHRunDialog API

使用SHRunDialog API显示运行对话框

Display Format drive dialog using SHFormatDrive API

使用SHFormatDrive API显示格式化对话框

Display change icon dialog using SHChangeIconDialog API

使用SHChangeIconDialog API显示改变图标对话框

Display pick icon dialog using PickIconDlg API

使用PickIconDlg API显示挑选图标对话框

Get Shell Folders locations using SHGetSpecialFolderLocation API

使用SHGetSpecialFolderLocation API得到Shell文件夹位置

Flash a window using FlashWindow API

使用FlashWindow API闪动窗口

Get classname for some controls using GetClassName API

使用GetClassName API得到一些控件的类名

Get Current Process and Current ProcessID using GetCurrentProcess and GetCurrentProcessId API

使用GetCurrentProcess and GetCurrentProcessId API得到当前ProcessProcessID

Get Current Thread and Current Thread ID using GetCurrentThread and GetCurrentThreadId API

使用GetCurrentThread and GetCurrentThreadId API得到当前ThreadThread ID

Get Cursor Position using GetCursorPos API

使用GetCursorPos API得到鼠标位置。

Get foreground window using GetForegroundWindow API. Very useful to develop security programs and system logger programs

使用GetForegroundWindow API得到最前的窗口对于开发安全程序和系统程序很有用

Find a window knowing it''''s caption using FindWindow API

使用FindWindow API查找窗口并获知它的标提

Get Background color of a device context using GetBkColor API

使用GetBkColor API得到设备上下文使用的背景颜色

Get the caption of control which captures mouse event using GetCapture API

使用GetCapture API捕获鼠标事件。得到控件标题

Get system colors using GetSysColor API

使用GetSysColor API得到系统颜色

Set system colors using SetSysColors API

使用SetSysColors API设置系统颜色

Create a Elliptic Form using CreateEllipticRgn and SetWindowRgn API

使用CreateEllipticRgn and SetWindowRgn API创建椭圆形窗体

Create a Rectangular Form using CreateRectRgn and SetWindowRgn API

使用CreateRectRgn and SetWindowRgn API创建矩形窗体

Create a Round Rectangular Form using CreateRoundRectRgn and SetWindowRgn API

使用CreateRoundRectRgn and SetWindowRgn API创建圆矩形窗体

Get File information by it''''s Handle using GetFileInformationByHandle API

使用GetFileInformationByHandle API通过它的句柄得到文件信息

Get filetime using GetFileTime API

使用GetFileTime API得到文件时间

Set filetime using SetFileTime API

使用SetFileTime API设置文件时间

Set the File modified time to Current System Time using GetSystemTimeAsFileTime API

使用 GetSystemTimeAsFileTime API设置文件修改时间到当前系统时间

Get window position points using GetWindowRect API

使用GetWindowRect API得到窗口位置

Get Foreground Window Thread and Process ID using GetWindowThreadProcessId API

使用GetWindowThreadProcessId API得到前端窗体线程和进程的ID

Get current directory using GetCurrentDirectory API

使用GetCurrentDirectory API得到当前的目录。

Set Current directory using SetCurrentDirectory API

使用SetCurrentDirectory API设置当前的目录

Get handle of the window at mouse cursor position using WindowFromPoint API

使用WindowFromPoint API得到鼠标指向窗体的句柄。

Get a list of Open Window Names using GetDesktopWindow,GetWindow and GetWindowText API

使用GetDesktopWindow,GetWindow and GetWindowText API得到打开的窗口列表

Creates a icon in your System tray which minimizes all your applications when you double click it(icon in SysTray).

当你双击它最小化你的应用程序时,创建你的系统拖盘。

Display a message box using MessageBox API

使用MessageBox API显示一个消息框

Display Message Box using MessageBoxIndirect API

使用MessageBoxIndirect API显示一个消息框

Open the start menu using mouse_event API

使用mouse_event API打开开始菜单

Function CurrentTime. Returns the COMPLETE system time, including milliseconds (something VB''''s date/time func doesn''''t do).

CurrentTime函数返回完整的系统时间包括毫秒

An example for MulDiv API

一个使用MulDiv API的例子

Type some words in notepad without human intervention using keybd_event API

使用keybd_event API不需人干预打些单词到写字板里

Move a window to a specified point using MoveWindow API

使用MoveWindow API移动一个窗口到指定的点。

Get Drive Type using GetDriveType API

使用GetDriveType API得到驱动器类型

Set your Window on top of all forms using SetWindowPos API

使用SetWindowPos API把你的程序窗口在所有窗口中设置为最顶端。

Get File information is using SHGetFileInfo API

使用SHGetFileInfo API得到文件信息

Draw an Arc using Arc API

画弧线使用Arc API

Draw a chord using Chord API

画一个闭合弦使用Chord API

Draw a line from a point to specified point using LineTo API

画一个线条从一个点到另一个指定点。使用LineTo API

Draw a pie using Pie API

使用Pie API画饼图

Get the window which has got focus using GetFocus API

使用GetFocus API判断那个窗体得到焦点

Get the Entire command line passed using GetCommandLine API

得到完整的命令行

Capture desktop using GetDesktopWindow and BitBlt API

捕获桌面使用GetDesktopWindow and BitBlt API

Capture the window under mouse into the form using GetDC,BitBlt,GetCursorPos and WindowFromPoint API

使用GetDC,BitBlt,GetCursorPos and WindowFromPoint API捕获鼠标下面的窗口到一个窗体中

A simple code to catch any keypress and store it in a file named "file.txt" It runs in the background.

一个简单的代码,捕获键盘消息并且保存到文件名"file.txt",它是运行在后台的。

This code finds a window and sends message to the window.

这个代码是找到一个窗口并发送消息给窗口

This code brings a file from remote server to the client without asking the "Save to disk" dialog box.

这个代码从远程主机保存文件到客户机不出现"Save to disk"对话框。

Controlling carat blinking speed using API

使用API控制克拉闪亮的速度

This code puts your project icon in the system tray.

放工程图标到系统拖盘中。

Code to Check the Mode in which Windows is Loaded

检查windows的引导模式

Sets the time on the local machine.

设定本地机的时间

The following Code Helps To refresh Desktop using a different approach

这个代码使用一种不同的途径来更新桌面

This code initiates the screen saver of the system.

启动计算机系统的屏幕保护

Allows you to paint the system stock icons onto your form

在窗体上绘制系统托盘图标

Finds Hard-Drive Capacity. Will work with any size of drive.

发现硬盘的容量,在任何大小的驱动器上都可正常工作

Finds all Drives Free Space and Capacity

找出所有驱动器空闲的空间和容量

This code is useful when you are getting your logon user with domain name

这个代码很有用,当你正在获取你的登录帐号时

Did you ever wanted to create your own dll with api function export

API函数创建自己的DLL

This code will grab any window text box text from any aplication running on windows 32 bit

这个代码可以从任意的windows32位应用程序中获取文本框中的文本

Code to Get the Number of Function Keys in the KeyBoard

得到键盘键数的代码

This code gives the length of alphabets and numbers in pixels

这个代码给出了字母表的长度

This simple program loads or removes any FONT from a specified path & file name

从指定的路径和文件名中载入或删除字体

Get Cached Passwords from the PWL File

PWL文件中得到其保存的密码

Yet Another CenterForm Routine

另一个中心窗体

Code to Set a Animated Cursor(ani) as the MousePointer for the Form

为一个窗体设置一个动画鼠标指针。

Another Get-Set Key state program

另一个得到键盘状态的程序

Allways wanted to make your program hidden in that annoying Ctrl+Alt+Del(Tested on windows 9x)

使用简单的一行代码,让你的程序在Ctrl+Alt+Del中隐藏。

Make your CD-ROM drive open using the mciSendString API.

使用mciSendString API打开你的CD-ROM驱动器

copy a file to your windows desktop from dialog control box.

通过对话框控件拷贝一个文件到你的windows桌面

Shut down the computer

关闭计算机

for viewing the desktop with some magnification according to the moving of mouse

根据鼠标的移动查看桌面

Hide mouse pointer

隐藏鼠标指针

Control the speed of the Start Menu.

控制开始菜单的速度

【API】VB API初级入门

一、API是什么? 

 

  这个我本来不想说的,不过也许你知道其它人不知道,这里为了照顾一下新手,不得不说些废话,请大家谅解。 

 

  Win32 API即为Microsoft 32位平台的应用程序编程接口(Application Programming Interface)。所有在Win32平台上运行的应用程序都可以调用这些函数。 

 

  使用Win32 API,应用程序可以充分挖掘Windows32位操作系统的潜力。Mircrosoft的所有32位平台都支持统一的API,包括函数、结构、消息、宏及接口。使用 Win32 API不但可以开发出在各种平台上都能成功运行的应用程序,而且也可以充分利用每个平台特有的功能和属性。 

 

   

  以上为API的相关介绍,不过有些新手看了以后可能还是不怎么明白API到底有什么用?这里请不要着急,如果你有足够耐心的话,请慢慢往下看。 

 

二、如何使用API 

 

  估计这才是大家真正关心的,那么如何使用API呢?在了解API之前,先打开你的VB书,翻到过程函数这章来,在搞清楚API之前应该先搞懂过程函数是怎么一回事!如果你还不知道过程的工作方式,那么请先不要急着往下看,那样容易走很多弯路。 

 

  好了,当你理解了过程函数时,也就是你可以使用API的时候了,别把API看得太难,你就像使用过程函数一样使用API就可以了。首先,让我们看看一个简单的API,以下: 

 

  Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long) 

 

  以上这个API的呢是起一个延时作用。你如果是刚接触API的话可能会感到API的书写及其复杂,而且会感到很不适应。其实这没什么的,慢慢习惯就好了。至于API这些复杂的书写你就不用操心了,在你安装VB的时候微软已经帮我们带上了API浏览器,这些全部都可以利用API浏览器帮我们自动生成。 API浏览器的位置位于[开始菜单-程序-Microsoft Visual Basic 6.0 中文版-Microsoft Visual Basic 6.0 中文版工具-API 文本浏览器]。打开API浏览器,在最上面的一个文本框中输入Sleep,这时下面列表框中就会自动显示相应的API函数,然后点右边添加按钮即可,接着点击复制按钮,这时你就可以用Ctrl+V把声明的API添加到VB代码窗口中了。 

 

  这里我要说一下,有些新手可能还弄不明白。 API的声明范围一般有两种模式,一种是Private(私有的),一种是Public(公用的)。一般Private是声明在类模块或窗体类中, Public声明在模块中。你在添加API的时候,添加按钮下面就有API的声明范围,可以根据自己的需要进行添加。这里我们一般选择私有的 (Private)就可以了。 

 

  经过上面,我们知道如何添加API,接着我们分析一下API声明,这是你了解API必备的。首先看第一个单词Private,很显然,我上面刚刚讲过,这是申明一个私有的API变量。再看第二个Declare,这个单词帮我们告诉VB是在申明API函数,一般申明外在的API函数时都必须带上这个单词。第三个Sub,别告诉我你不知道什么意思?这就是我叫你先学习VB中过程函数的意思,这个说白了就是没有反回值,一般如果不是Sub而是Function都带有反回值的。第四个Lib,这个是告诉VB我们要声明哪一个DLL中的API函数,也就是告诉 VB我们要申明第五个单词kernel32.dLL中的API,一般写DLL名称时都要用双引号括起来,如"user32""shell32.dll" 等,至于后面的.dll这个可以带可不带。再来看第六个Alias,这个也是需要同后面一个一起用的,我们应该把第六个和第七个连起来一起看Alias "Sleep",这个意思表示将被调用的过程在DLL中还有另外的名称,这个是可选的。最后括号里面的,也就是和过程函数一样,你传入相应的值就可以了。  

 

  上面我们分析完API函数声明以后,接着我们就要自己动手写代码了。先把这个API复制到Form1代码窗口中,然后写如下代码: 

 

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 

Private Sub Form_Load() 

     Sleep 2000 

End Sub 

 

  解释一下也就是在窗体启动时使用Sleep API进行延时2后面的参数dwMilliseconds是表示你要延时的秒数基本上和设置Timer中的秒数一样。你再看一下Sleep  2000的使用方式是不是和使用VB过程函数一样呢好了我们的第一个VB API程序写完了可以看到使用API并不是一件很难的事。 

 

三、如何才能提升你对API的学习兴趣? 

 

  API,我常把它看做成过程函数,不过每人都有每人的见解和理解方式,自己的理解方式只要可以帮助自己更好的学习和掌握API,也没必要一定要学习他人的。 

 

  1,自己做MsgBox 

 

  了解API参数的使用方法是很重要的,这里我们不用VBMsgBox,直接使用API弹出MsgBox消息框。首先,打开API浏览器,选择 MessageBox,大家可以用这个APIVB内置的MsgBox比较一下,其实MsgBox也就是MessageBox的缩写,只不过一个是 API,一个是VB内置的,但两者都是通过API进行工作的。好了,选择私有声明方式,粘贴到VB代码编辑窗口中,然后新建一个 CommandButton,写入以下代码: 

 

Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA"  

(ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String,  

ByVal wType As Long) As Long 

Private Sub Command1_Click() 

     MessageBox Me.hwnd, "这里是内容", "标题", 0 

End Sub 

 

  先让我们来分析一下首先看第一个参数Byval hWnd As Long很显然这是一个长整形变量所以我们这里需要传递的是数字你可能会发现我们传递的并不是数字啊而是 Me.hwnd??很奇怪是吗如果你真的有此疑问说明你是真心想要学习好API现在就让我们来看看Me.hwnd到底是什么东西以下摘自VB帮助文档 

  hWnd 属性:返回窗体或控件的句柄。 

  句 柄:是由操作环境定义的一个唯一的整数值,它被程序用来标识或者切换到对象,如窗体或控件等。 

 

  现在估计你差不多就已经明白了,我们调用的hwnd其实是一个句柄整数值,你可以用 Msgbox Me.hwnd 看一下就知道了。至于Me这是一个关键字,代表当前Form窗体对象。如:Me.Caption="标题"Me.BackColor= vbRed等。 

 

  接上面的,首先我们传入了Me.hwnd,表示是当前窗口调用MessageBox,这里告诉大家一个技巧,也就是以后凡是看到Byval hwnd As Long,一般都是需要传入句柄的,至于传入哪个对象句柄,那就要看你是怎么实现的了。 

  ByVal lpText As String,这个是字符串变量,标识着叫我们需要传入字符串进去,可以看里面的变量字符lpText,属于文本的意思,也就是说是用来显示MsgBox中的消息文本的。 

  ByVal lpCaption As String,也是字符串变量,还是传入字符串进去。在看里面的变量字符lpCaption,其实就是显示MsgBox标题的。 

  ByVal wType As Long,这是一个整形变量,需要传递整形数字,还是看里面的变量字符wType,标识着显示MsgBox类型,这里可以像VBMsgBox一样使用,如这里可以传入:vbYesNo,vbOkCancel等,如果忽略那就传入0即可。 

 

  好了,按F5启动程序,点击Command1,接着就会弹出一个消息框,这里我们制作以及分析MsgBox已经完成了。希望你能在这段学习到一些知识。 

 

  2,来点实用的吧 

 

  就拿隐藏Windows任务管理器来说吧,这里只能隐藏任务管理器中的窗口,不能隐藏进程。(问:有没有隐藏进程的?答:你想干什么?),当程序运行后你无法从任务管理器的窗口中关闭程序,只能从进程中进行终止。好了,还是老规矩,打开API浏览器,输入GetWindowShowWindow两个 API,声明范围还是私有的,复制粘贴到Form代码窗口中,嗯,好了?别急,还是API浏览器,选择Combox中的常数,输入GW_OWNER SW_HIDE这两个API常数,然后粘贴到代码窗口中,问我这两个是干什么的?那就接着往下看吧。写入以下代码: 

 

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,  

ByVal wCmd As Long) As Long 

Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long,  

ByVal nCmdShow As Long) As Long 

Private Const GW_OWNER = 4 

Private Const SW_HIDE = 0 

Private Sub Form_Load() 

     Dim lphWnd As Long 

     lphWnd = GetWindow(Me.hwnd, GW_OWNER) 

     ShowWindow lphWnd, SW_HIDE 

End Sub 

 

  又到了分析的时候了,这对刚入门的新手可谓是最激动的时候了。好了,还是老子,看看两个API的表面意思和传递值变量。 

 

  先看GetWindow,表面意思:获取窗口。传递值变量:hWnd整形句柄,wCmd整形命令值。 

  再看ShowWindow,表面意思:显示窗口。传递值变量:hWnd整形句柄,nCmdShow整形命令值。 

 

  然后是使用代码,先看lphWnd = GetWindow(Me.hwnd, GW_OWNER)这句,这句意思是获取当前窗口的所有者窗口句柄,可以看到GetWindowFunction过程函数,执行以后会返回相应的窗口句柄值,这个值为Long整形(同句柄)。接着调用ShowWindow lphWnd, SW_HIDE,这句意思是显示lphwnd这个句柄的窗口,关键一句是最后的SW_HIDE,这是API函数的常量。通过设置常量能让系统知道API到底应该怎么执行显示窗口,是显示?还是隐藏?Hide当然是隐藏的意思。好了,编译成Exe,运行后打开任务管理器,查看程序窗口,还有吗? 

 

  我又要说一下了,有些人可能不懂为什么要用GW_OWNER这些常量,这些到底有什么用?还有就是我怎么知道哪些API对应哪些的常量?其实这些常量你只要稍微注意一下就知道它们是怎么回事了,如在GetWindow中我使用GW_OWNER,在ShowWindow中我使用SW_HIDE这些常量都有一个共同的特点,就是他们都是以API的单词第一个字母为标准。如GetWindow相对应的常量就是Get(G)Window(W)=GW ShowWindow相对应的常就是Show(S)Window(W)=SW,这些常量可以自己在VBAPI浏览器中找找看。