发新话题
打印

如何建立多行的球状工具栏

如何建立多行的球状工具栏

  How to create multi-line balloon style tool tips in Visual Basic.
by Sheppe Pharis

June 2000

--------------------------------------------------------------------------------

The code in this article has only been tested in Visual Basic 6 SP3, though it should work without a problem in all versions of Visual Basic that support API Declarations.

**Note: This code has not been tested on a platform with a version of the Windows Common Controls that is below 5.81. The Balloon, NoAnimate, and NoFade styles will only work if you have version 5.80 and up of the Windows Common Controls (Comctl32.DLL).

--------------------------------------------------------------------------------

An oft asked question about Visual Basic is, "How do I make multi-line tool tips?". This article is going to to explain the process necessary to do this in as clear and readable a format as possible.

Firstly, you should know that creating multi-line tool tips in VB requires the use of the API (application programming interface). A quick description of the steps taken to create a multi-line tool tip in Visual Basic follows:

Make the necessary API declarations.
Declare the variables to contain and pass the information to and from the API.
Set the necessary values of the declared variables.
Create a new window using the CreateWindowEx API call. This window is the window the tool tip will be contained in.
Determine the region in which the tool tip will be activated.
Set the information necessary to creating a tool tip in a TOOLINFO structure.
Tell the tool tip window to apply itself to the window you want it to be displayed for.
Set the maximum width of the tool tip.
Set the fore and back colours of the tool tip window.
Below is a well commented code example. Understanding this example should not be a problem, and it will give you a good glimpse into how to begin creating all of your own tool tips through the API.

--------------------------------------------------------------------------------

Code Example:

API Declarations. Place all of the code in the table below at the beginning of your form, or change all of the ** statements to Public statements and paste it into a module:

Option Explicit
注释: Beware of word-wrap when copying this code!
注释: API calls necessary for creating and destroying tool tip windows.
** Declare Function CreateWindowEx Lib "user32"  Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal  lpClassName As String, ByVal lpWindowName As String,  ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long,  ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
** Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

** Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

** Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

** Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long

注释: A RECT user defined type. This is used for setting the bounds of the tool tip window.
** Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

注释: A TOOLINFO user defined type. This is used for setting 注释:all of the necessary
注释: flags when creating a tool tip window.
** Type TOOLINFO
cbSize As Long
uFlags As Long
hwnd As Long
uid As Long
RECT As RECT
hinst As Long
lpszText As String
lParam As Long
End Type

注释: A constant used in conjunction with the CreateWindowEx 注释:API. It indicates to use the default value.
** Const CW_USEDEFAULT =

TOP

发新话题