Ctl32 BalloonTip class

ctl32_balloontip: overview

Overview
This class provides a BalloonTip control that can be used in VFP9. This class has two functions:
1. Emulate the "CAPS LOCK ON" warning of XP in a password entry textbox,
2. Display a BalloonTip pointing to any control or point in a form with any text you want.
The balloontip can be customized by adding an icon, a title, change its style from balloontip to tooltip, change its font, colors, position relative to the control, alignment, etc.
This class uses the Windows API functions to create a true Windows common controls ToolTip.
This class uses BINDEVENT with the new features only available in VFP9. It will not work in previous versions of VFP. If you are using a previous version of VFP, you should really upgrade to take advantage of the many new features, and to support VFP.




Quick Start
If you want a ctl32_balloontip on a form, drag the ctl32_balloontip control from the Project Manager window and drop it into the Form. You can only have ONE instance of the class in a form. You use the same control and change its Icon, Title and Text and other properties as required.

Sample Project
See the sample project included in the Sample folder to see examples of how to use the control and what can be done.

BindEvent
This class does Bindevents to the following windows and window messages:
ThisForm.hWnd, WM_KEYDOWN
ThisForm.hWnd, WM_LBUTTONDOWN
ThisForm.hWnd, WM_NOTIFY
If you hook to those same window/event pairs in some other part of your code, recall what the Help file says:
"When binding to Windows message (Win Msg) events, only one hWnd to Windows message pairing can exist."
Icon files used should be included in the project. There is no need to redistribute the icon files to end users. The icon files should contain one 16x16 256 color icon, that is used to display in the statusbar.

Bugs
20060926
There is a bug in the positioning code in tmrShow.ctl32_Show() that sometimes rises an error that thisform.activecontrol is not an object. I have fixed that for next version, and also added more features.

Known Problems

Change Log
2006xxxx
Changed the _ThemeStatus, _HostHWnd, _FormType functions in _util of ctl32_common. Eliminated all references to ThisForm, now the form is determined from the control that is passed as a parameter to this functions.
Changed the way _Util object is added to control, from newobject to addproperty, so it will not count as another control.
Added Chinese traditional and Chinese simplified to caps lock warning message laguages.
Changed the name of the ctl32_SetLangStrings to ctl32_SetLocaleStrings
Add a space to the end of the title strings of some languages to prevent compilation errors on DBCS Windows.
Moved routines for getting language ids to _util class
Added ctlVcxStructs and ctlVcxCommon, they specify the name/location of the ctl32_structs and ctl32_common classes.
20061010
ctlOS() method removed.
20061001
Fixed bug in tmrShow.ctl32_Show().
Added ctlPositionStyle 6: ballontip positions itself relative to the current position of the mouse pointer.
Added ctlOS() method
20060926
The updated structure of TOOLINFO does not seem to work in Vista RC1 5600  so I changed the _toolinfo class to not have the HBITMAP member, see http://windowssdk.msdn.microsoft.com/en-us/library/ms650460.aspx 
WindowFromPoint in EvtHandler_WM_LBUTTONDOWN only works in XP and up, in 98 and 2K it always returns the HWND of the form, and not of the ballootip, even if you click on the balloontip.
GetWindowRect is used then in 98 and 2K, the problem is that it includes the area near the stem as part of the window rectangle, but is close enough.
Added Event ctlHide that is raised by clicks in balloontip, outside balloontip,  in X close button and links in balloontips
Added bindevent to _Screen.Moved to hide when VFP Screen is moved
Changed ctlBalloon and ctlBorder to ctlStyle.
Added code to deal with textboxes with SelectOnEntry = .T. and when ctlPositionStyle is set to 3, align to cursor caret. It reverts to ctlPositionStyle = 2.

Under The Hood
The class creates a Windows Common Controls ToolTip, and adds only one Tool to it. It uses the TTM_TRACKACTIVATE to display the ToolTip, and TTM_TRACKPOSITION to position the ToolTip.
Starting from INIT(), first all the used API functions are declared in ctl32_RegisterFunctions. The Api functions are dlecared only if they have not been declared before.
Then some properties for internal use are added to the class. Next the HWnd of the window to use as a parent for the control is found. This is because top level forms, or forms with scrollbars have an inner window inside the form window.
Then the language strings are set and stored, and then the actual tooltip control is created.
To position the ToolTip, two methods are used: If you set ctlPositionStyle to 3,  the position of the cursor caret in the form is retrieved, and based on that the tooltip is positioned next to it. You should use this position style with controls that have a cursor caret, for example a textbox.
New in version 20061001: A third positioning method is available, the current mouse cursor position.
If the caret is not visible, because some text is selected in the control, or the control does not have a caret, ctlPositionStyle reverts to 2, and the form active control is used for positioning.
The problem with using the caret or the current active control, is that you will put some code to show a tooltip in the GotFocus event of a control. But in the GotFocus event, the previous control still owns the caret or is the current active control.
To overcome this, when you set ctlVisible to TRUE, a timer is activated that waits for 200 milliseconds , so it lets the GotFocus event finish, not because of the time elapsed, but because the timer event code is out of the code flow of the GotFocus.
The ctl32_balloontip_show timer class has a ctl32_Show method that is responsible for positioning and displaying the balloontip.
When the balloontip is visible, it will be hidden automatically when the user clicks on the balloontip, clicks on the form, moves or resizes the form, or moves the VFP window. Also a keypress will hide the balloontip. This is all done by means of BINDEVENTS to some VFP events and window messages. Check ctl32_BindEvents() method of the class.
Also a timer is enabled when the control is made visible, that will hide thecontrol
An event is raised when the ballontip is hidden: ctlHide, with a parameter that tells you the reason code, so you can react different in response to the way the user dismissed the balloontip.
When you set ctlCapsLockStyle to TRUE, the balloontip emulates the "Caps Lock ON" warning ballontip that Windows XP display at the logon screen. You can use this in a password textbox.
TIP: set the PasswordChar of the texbox to "l" and the FontName to "WingDings" to emulate the look of XP password textboxes.
Also check the sample for a way to handle spacebar in a password textbox, to work around a VFP bug. (The space shows in the textbox instead of the PassWordChar).
The "Caps Lock ON" warning title and text is available in 28 languages, and it is set to the operating system user selected locale. You can override the language by setting a locale value in ctlLangID.
Check here for language IDs:
See the ctl32_SetLangStrings method to see how its done. The language strings where extracted from comctl32.dll version 6. I have not been able to add non-latin charsets languages (lack of knowledge and time, maybe someone interested can help me there).
Starting in Windows XP SP2, you can specify a custom icon to display in the balloontip. this is done by storing the icon file name and path if needed in ctlIcon. The LOADPICTURE VFP function is used to load the icon. The icon file can be included in the project.
Starting with XP, a link can be displayed in the balloontip. To provide compatibility with older versions of Windows, the link is converted to plain text. You fill the ctlLinkLabel and ctlLinkUrl properties, and then you set ctlText to something like "Visit here: " + ctlLink
In Vista, you can choose to display large icons, setting ctlIconLarge to TRUE. The Vista API regarding tooltips controls is not yet firmly defined it seems.

Properties, Events and Methods
 ctlActive
Property.
Value Type: Logical.
Default Value: TRUE
R/W: Read/Write.
When set to FALSE, the tooltip is inactive, it does not show. Can be used as a global ON/OFF switch for tooltips for the form, maybe based on some user preference stored somewhere.
Remarks:
Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
See Also:
ctlActive | ctlSHow | ctlVisible

 ctlAlignment
Property.
Value Type: Numeric.
Default Value: 3
R/W: Read/Write.
Specifies the alignment of the tooltip, relative to its position. Possible values are:
0 Middle LeftCON_ALIGN_MIDDLELEFT
1 Middle RightCON_ALIGN_MIDDLERIGHT
2 Middle CenterCON_ALIGN_MIDDLECENTER
3 AutomaticCON_ALIGN_AUTOMATIC
4 Top LeftCON_ALIGN_TOPLEFT
5 Top RightCON_ALIGN_TOPRIGHT
6 Top CenterCON_ALIGN_TOPCENTER
7 Bottom LeftCON_ALIGN_BOTTOMLEFT
8 Bottom RightCON_ALIGN_BOTTOMRIGHT
9 Bottom CenterCON_ALIGN_BOTTOMCENTER
See Also:
ctlAlignment | ctlPosition | ctlPositionStyle | ctlOffsetX | ctlOffsetY

 ctlBackColor
Property.
Value Type: Numeric.
Default Value: Design time: -1, RunTime: System default BackColor for tooltips.
R/W: Read/Write.
Specifies the backcolor of the tooltip. Set to -1 to use the system default backcolor for tooltips.
Remarks:
I have added this property because it was requested, please do not abuse it, try to comply with the user preferences.
Example:

Thisform.oBallonTip.BackColor Rgb(255, 198, 170)


*!* Sets tooltip BackCOlor to system default:

Thisform.oBallonTip.BackColor = -1
See Also:
ctlBackColor | ctlForecolor

 ctlCapsLockStyle
Property.
Value Type: Logical.
Default Value: FALSE
R/W: Read/Write.
When set to TRUE, the tooltip hides itself, sets the values of ctlIcon to 2 (), ctlTitle and ctlText to the stored strings of the System locale or to the locale specified in ctlLocale, and sets ctlHideDelay to 5000. If CAPS LOCK is on, the tooltip shows itself.
Remarks:
Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
Example:

*!* TextBox GotFocus

Thisform.ctl32_balloontip1.ctlCapsLockStyle = 1


*!* TextBox LostFocus

Thisform.ctl32_balloontip1.ctlCapsLockStyle = 0
See Also
ctlCapsLockStyle | ctlLangId

 ctlCloseButton
Property.
Value Type: Logical.
Default Value: FALSE
R/W: Read/Write.
When set to TRUE, the tooltip will have a Close Button in the upper right corner.
Applies to: comctl32.dll 5.8 Internet Explorer 5 or later.
Remarks:
Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
See Also:
ctlCloseButton | ctlIcon | ctlIconLarge | ctlTitle | ctlText | ctlStyle

 ctlControl
Property.
Value Type: Object.
Default Value: None
R/W: Read/Write.
Holds an object reference to a form control. The tooltip will position itself using this control position, if ctlPositionStyle is set to 5 CON_BTPOS_CTRLREF.
See Also:
ctlControl | ctlPositionStyle

 ctlFadeIn
Property.
Value Type: Logical.
Default Value: FALSE
R/W: Read/Write.
The control shows with a fade in effect.
Applies to: Windows 2000 or later. Ignored in Windows 95 and 98.
Remarks:
Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
See Also:
ctlFadeIn | ctlFadeOut

 ctlFadeOut
Property.
Value Type: Logical.
Default Value: FALSE
R/W: Read/Write.
The control hides with a fade out effect.
Applies to: Windows 2000 or later. Ignored in Windows 95 and 98.
Remarks:
Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
See Also:
ctlFadeIn | ctlFadeOut

 ctlFontBold
Property.
Value Type: Logical.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
Specifies if the font of the tooltip has this style.
Remarks:
I have added this property because it was requested, please do not abuse it, try to comply with the user preferences.
See Also:

 ctlFontCharSet
Property.
Value Type: Numeric.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
I really don't know anything about this, someone else will have to help with this.
See Also:

 ctlFontItalic
Property.
Value Type: Logical.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
Specifies if the font of the tooltip has this style.
Remarks:
I have added this property because it was requested, please do not abuse it, try to comply with the user preferences.
See Also:

 ctlFontName
Property.
Value Type: Character.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
Specifies the name of the font of the tooltip.
Remarks:
I have added this property because it was requested, please do not abuse it, try to comply with the user preferences.
See Also:

 ctlFontSize
Property.
Value Type: Numeric.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
Specifies the font size in points of the font of the tooltip.
Remarks:
I have added this property because it was requested, please do not abuse it, try to comply with the user preferences.
See Also:

 ctlFontStrikethru
Property.
Value Type: Logical.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
Specifies if the font of the tooltip has this style.
Remarks:
Not really useful ...
See Also:

 ctlFontUnderline
Property.
Value Type: Logical.
Default Value: Design Time: None, RunTime: Value of system default for tooltip text.
R/W: Read/Write.
Specifies if the font of the tooltip has this style.
Remarks:
Not a really useful ...
See Also:

 ctlForeColor
Property.
Value Type: Numeric.
Default Value: Design time: -1, RunTime: System default ForeColor for tooltips.
R/W: Read/Write.
Specifies the forecolor of the tooltip. Set to -1 to use the system default forecolor for tooltips.
Remarks:
I have added this property because it was requested, please do not abuse it, try to comply with the user preferences.
See Also:
ctlBackColor | ctlForecolor

 ctlHide
Event.
Occurs when the tooltip gets hidden after being shown
Parameters nHideStyle
-1: Link in tooltip clicked.
0: ctlAutoHide delay elapsed.
1: Click inside tooltip
2: Click outside tooltip.
3: Click in tooltip Close button.
4: Key pressed.
5: Caps Lock key set to off.
6: Form moved or resized, main program window moved.
See Also:

 ctlHideDelay
Property.
Value Type: Numeric.
Default Value: 5000
R/W: Read/Write.
Specifies the time in milliseconds that the tooltip will be shown, after the time elapses, the tooltip hides itself. Clicking in the tooltip, in a link in the tooltip, in the form, moving the form or the VFP main form will hide the tooltip.
Set to 0 to disable automatic hiding of the tooltip
See Also:
ctlActive ctlHide | ctlHideDelay | ctlShow | ctlShowDelay | ctlTrack | ctlVisible

 ctlHwnd
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read.
Returns a window handle to the control.
The Microsoft Windows operating environment identifies each form in an application by assigning it a handle, or hWnd. The hWnd property is used with Windows API calls. Many Windows operating environment functions require the hWnd of the active window as an argument.

 ctlIcon
Property.
Value Type: Numeric or Character (an Icon file name).
Default Value: 0
R/W: Read/Write.
Specifies the system icon or the custom icon to display.
0 No iconTTI_NONE
1 Info iconTTI_INFO
2 Warning iconTTI_WARNING
3 Error iconTTI_ERROR
4 Info icon largeTTI_INFO_LARGE (Vista)
5 Warning icon largeTTI_WARNING_LARGE (Vista)
6 Error icon largeTTI_ERROR_LARGE (Vista)
Instead of using 4,5,6, you can set ctliconLarge to .T.
You can instead specify a name of an ico file (requires XP SP2 or later).
If the file you specify does not exist, no error is raised, and the value is set to 0, no icon. The icon file should have a 16x16 256 color icon, or a 32x32 icon if you want to display a large icon (Vista only).
The icon files should be included in the project. There is no need to copy the icon files when deploying the application.
Applies to: System icon: All. Custom icon: requires XP SP2 or later.
See Also:

 ctlIconLarge
Property.
Value Type: Logical.
Default Value: FALSE
R/W: Read/Write.
If TRUE, the system icon is displayed in a 32x32 size instead of the standard 16x16.
Applies to: Vista.
Remarks:
This only applies if you ctlIcon has a value between 1 and 3 for system icons. If you use a custom icon, it does not apply. If you want to display a 32x32 custom icon in Vista, just use a 32x32 icon.
Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
See Also:
ctlCloseButton | ctlIcon | ctlIconLarge | ctlTitle | ctlText | ctlStyle

 ctlLangID
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
When set to a value other than 0x0, it overrides the user locale language when setting the title and text for a tooltip with ctlCapsLockstyle set to TRUE.
The ctl32_tooltip has text for 30 languages and variations. If you would like to see your language included, post in the forums.
See Also
ctlCapsLockStyle | ctlLangId

 ctlLeft
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the Left position of the tooltip when ctlPositionStyle 1 is used.
See Also:
ctlLeft | ctlTop | ctlPositionStyle

 ctlLink
Use the ctlMakeLink method instead.
Property.
Value Type: Character.
Default Value: None
R/W: Read.
Returns the values of ctlLinkURL and ctlLinkLabel into a valid <A></A> link to display in a tooltip.
Applies to: XP or later.
Remarks:
This property is used with ctlLinkLabel and ctlLinkURL so you can easily add a link to a tooltip, without having to create the html code yourself.
Example:

Local m.lcText


With Thisform.ctl32_balloontip1

  .ctlLinkURL = "http://www.ctl32.com.ar/ctl32_balloontip.asp"
  .ctlLinkLabel = "ctl32_BalloonTip Homepage"
  m.lcText = "Check " + .ctlLink + " for more info and docs."
Endwith


Thisform.ctl32_balloontip1.ctlShow(CON_BTPOS_SYS1270, ;
m.lcText, "This is a BalloonTip With a Web Link", 1)
In this example, the value of ctlLink is the following string:
<A href="http://www.ctl32.com.ar/ctl32_balloontip.asp">ctl32_BalloonTip Homepage</A>
See Also:

 ctlLinkLabel
Use the ctlMakeLink method instead.
Property.
Value Type: Character.
Default Value: None
R/W: Read/Write.
Specifies the label of the link returned by ctlLink.
Applies to: XP or later.
See Also:
ctlLink | ctlLinkLabel | ctlLinkURL | ctlMakeLink | ctlOpenLink

 ctlLinkURL
Use the ctlMakeLink method instead.
Property.
Value Type: Character.
Default Value: None
R/W: Read/Write.
Specifies the URL of the link returned by ctlLink.
Applies to: XP or later.
See Also:
ctlLink | ctlLinkLabel | ctlLinkURL | ctlMakeLink | ctlOpenLink

 ctlMakeLink(cLinkLabel, cLinkURL)
Method.
Returns the values of cLinkLabel and cLinkURL into a valid <A></A> link to display in a tooltip. Also sets the values of ctLinkLabel and ctlLinkUrl
See Also:
ctlLink | ctlLinkLabel | ctlLinkURL | ctlMakeLink | ctlOpenLink

 ctlMargin
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the margin between the text and the tooltip borders. When setting ctlMargin, ctlMarginBottom, ctlMargeinLeft, ctlMarginRight and ctlMarginTop get set to this value.
Applies to: All except Vista, which ignores the value.
See Also:

 ctlMarginBottom
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the margin between the text and the bottom border of the tooltip.
See Also:
ctlMargin | ctlMarginBottom | ctlMarginLeft | ctlMarginRight | ctlMarginTop

 ctlMarginLeft
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the margin between the text and the left border of the tooltip.
See Also:

 ctlMarginRight
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the margin between the text and the right border of the tooltip.
See Also:
ctlMargin | ctlMarginBottom | ctlMarginLeft | ctlMarginRight | ctlMarginTop

 ctlMarginTop
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the margin between the text and the top border of the tooltip.
See Also:

 ctlMaxWidth
Property.
Value Type: Numeric.
Default Value: 255
R/W: Read/Write.
Specifies the maximum width for a tooltip window.
Remarks:
The maximum ToolTip width value does not indicate a ToolTip window's actual width. Rather, if a ToolTip string exceeds the maximum width, the control breaks the text into multiple lines, using spaces to determine line breaks. If the text cannot be segmented into multiple lines, it will be displayed on a single line. The length of this line may exceed the maximum ToolTip width.

 ctlOffsetX
Property.
Value Type: Numeric.
Default Value: 0.75
R/W: Read/Write.
Remarks:
See ctlAlignment for a detailed description.
See Also:

 ctlOffsetY
Property.
Value Type: Numeric.
Default Value: 0.75
R/W: Read/Write.
Remarks:
See ctlAlignment for a detailed description.
See Also:

 ctlOpenLink(cExpression)
Method.
Opens in the default program the link specified in ctlLinkURL. The link can be a web address that will open in the default browser, or a document that will open in the default program assigned to the document type.
See Also:
ctlLink | ctlLinkLabel | ctlLinkURL | ctlMakeLink | ctlOpenLink

 ctlPosition
Property.
Value Type: Numeric.
Default Value: 3 (CON_ALIGN_AUTOMATIC)
R/W: Read/Write.
Specifies the position of the tooltip, relative to a control. Possible values are:
0 Middle LeftCON_ALIGN_MIDDLELEFT
1 Middle RightCON_ALIGN_MIDDLERIGHT
2 Middle CenterCON_ALIGN_MIDDLECENTER
3 AutomaticCON_ALIGN_AUTOMATIC
4 Top LeftCON_ALIGN_TOPLEFT
5 Top RightCON_ALIGN_TOPRIGHT
6 Top CenterCON_ALIGN_TOPCENTER
7 Bottom LeftCON_ALIGN_BOTTOMLEFT
8 Bottom RightCON_ALIGN_BOTTOMRIGHT
9 Bottom CenterCON_ALIGN_BOTTOMCENTER
See Also:

 ctlPositionStyle
Property.
Value Type: Numeric.
Default Value: 1 (CON_BTPOS_LEFTTOP)
R/W: Read/Write.
Specifies which method will be used to position the tooltip. The specific form x and y coordinates to where the tip will point to will be calculated according to the value of this property. Possible values are:
1 CON_BTPOS_LEFTTOPThe values stored in ctlLeft and ctlTop will be used  (This are form coordinates in pixels).
2 CON_BTPOS_ACTIVECTRLUse the form active control., If there is no active control, ctlPositionStyle defaults to CON_BTPOS_SYS1270.
3 CON_BTPOS_CARETUse the caret of the form. To use this style, the active control of the form should have a caret and it must be visible, otherwise, ctlPositionStyle defaults to CON_BTPOS_ACTIVECTRL.
4 CON_BTPOS_SYS1270Use control under the mouse, if there is no control under the mouse, ctlPositionStyle defaults to CON_BTPOS_MOUSE.
5 CON_BTPOS_CTRLREFUse control stored as a reference in ctlControl. If there is no control reference in ctlControl, it defaults to CON_BTPOS_SYS1270.
6 CON_BTPOS_MOUSEUse the present position of the mouse cursor.
Remarks:
When using CON_BTPOS_MOUSE, the position used is not the exact position of the mouse cursor, but it is near it. The mouse cursor is treated like a 16x16 pixels control. This is done so the mouse cursor itself will not force the tooltip to hide as soon as it shows. You can change the values of ctlOffsetX and ctlOffsetY to adjust the position of the tooltip when using CON_BTPOS_MOUSE. Even negative values can be used.
See Also:
ctlAlignment | ctlPosition | ctlPositionStyle | ctlOffsetX | ctlOffsetY | ctlLeft | ctlTop

 ctlSetDefaultFont()
Method.
Sets ctlFontName, ctlFontCharSet, ctlFontSize, ctlFontBold, ctlFontItalic, ctlFontStrikethru, ctlFontUnderline to the system defaults for tooltips.
See Also:

 ctlShow(nPositionStyle, cText, cTitle, nIcon | cIconFilename)
Method.
Displays the tooltip.
Parameters:
nPositionStyle: ctlPositionStyle
cText: ctlText, the text to display in the tooltip.
cTitle: ctlTitle, the title of the tooltip
nIcon or cIconFileName: ctlIcon
Remarks:
All parameters are optional, if you call ctlShow() without any parameters, or with nPositionStyle = 0, the tooltip gets hidden.
If you set a title or an icon for the tooltip, and later use ctlShow without specifing a title or icon, the previously set icon and/or title are used.
This method first hides the tooltip, so there is no need to hide it first.
This is the ideal way to display a ballontip for a control, just set ctlShowDelay to any value you prefer, then call this in the MouseEnter event of a control.
Do not forget to call CtlShow(0) in the MouseLeave of the control, to disable the delayed display of the balloon tip.
Example:


Thisform.ctl32_ballontip1.ctlShow(CON_BTPOS_SYS1270, "Tooltip text", "Tooltip Title", TTI_INFO)
See Also:

 ctlShowDelay
Property.
Value Type: Numeric.
Default Value: 200
R/W: Read/Write.
Specifies the time in milliseconds to wait to show the tooltip after setting ctlVisible to TRUE or calling the ctlShow() method.
The minimum value is 200 milliseconds.
See Also:
ctlActive ctlHide | ctlHideDelay | ctlShow | ctlShowDelay | ctlTrack | ctlvisible

 ctlStyle
Property.
Value Type: Numeric.
Default Value: 1
R/W: Read/Write.
Specifies the style of tooltip
1 CON_BTSTYLE_BALLOON A balloon shape.
2 CON_BTSTYLE_RECT Rectangular shape.
3 CON_BTSTYLE_NOBORDER Rectangular shape with no border (Vista ignores this style).
See Also:
ctlCloseButton | ctlIcon | ctlIconLarge | ctlTitle | ctlText | ctlStyle

 ctlText
Property.
Value Type: Character.
Default Value: None
R/W: Read/Write.
The text to display in the tooltip.
See Also:

 ctlTitle
Property.
Value Type: Character.
Default Value: None
R/W: Read/Write.
The text to display as a title of the tooltip. Optional.
See Also:
ctlCloseButton | ctlIcon | ctlIconLarge | ctlTitle | ctlText | ctlStyle

 ctlTop
Property.
Value Type: Numeric.
Default Value: 0
R/W: Read/Write.
Specifies the Top position of the tooltip when ctlPositionStyle = 1 is used.
See Also:

 ctlTrack(cText)
Method.
Displays the tip at the mouse cursor position.
Parameters:
cText: same as ctlText. This parameter is optional.
Remarks:
This method ignores ctlPosition and ctlAlignment properties, it always displays the tooltip below and to the right of the mouse pointer.
The mouse cursor is considered a 16 x 16 pixels object, the tip will point to the top left corner, the values of ctlOffsetX and ctlOffsetY are used.
See Also:

 ctlVcxCommon
Property.
Value Type: Character.
Default Value: ctl32_common.vcx
R/W: Read/Write.
Specifies the file name of the ctl32_common.vcx file.
Remarks:
The path of the ctl32_balloontip.vcx file is added to this property value, and used to locate the class file.
See Also:
ctlVcxCommon | ctlVcxStructs

 ctlVcxStructs
Property.
Value Type: Character.
Default Value: ctl32_structs.vcx
R/W: Read/Write.
Specifies the file name of the ctl32_structs.vcx file
Remarks:
The path of the ctl32_balloontip.vcx file is added to this property value, and used to locate the class file.
See Also:
ctlVcxCommon | ctlVcxStructs

 ctlVersion
Property.
Value Type: Numeric.
Default Value: Version number.
R/W: Read.
Returns the version number of the class in the format YYYYMMDD, for example 20060925.
See Also:
ctlAbout | ctlVersion

 ctlVisible
Property.
Value Type: Logical.
Default Value: FALSE
R/W: Read/Write.
Specifies if the tooltip is visible.
Remarks: Valid values are .T. / .F. You can also use 0 for FALSE and 1 or any number <> 0 for TRUE.
See Also:
ctlActive ctlHide | ctlHideDelay | ctlShow | ctlShowDelay | ctlTrack | ctlVisible

Remarks
If you want to be consistent in the look of your tooltips from Windows 98 to Vista, consider the following guidelines:
  • Only use the system icons for the tooltip, custom icons only work in XP SP2 or later.
  • Do not use a close button on the tooltip (XP or later only)
  • Do not use links in the tooltip text. (XP or later only)
  • Do not use fadeout and fadein effects (XP or later only)
Set the PasswordChar of the texbox to "l" and the FontName to "WingDings" to emulate the look of XP password textboxes.
Also check the sample for a way to handle the spacebar in a password textbox, to work around a VFP bug. (The space shows in the textbox instead of the PassWordChar).

Notes on ctlAlignment, ctlPosition, ctlOffsetX and ctlOffsetY
To better understand the ctlAlignment, ctlPosition, ctlOffsetX and ctlOffsetY, check the following images:
CtlOffsetX and ctlOffsetY are used when ctlPositionStyle involves a control.
ctlOffsetX is a value that represents a proportion of the  Width of the control. Its default value is 0.75
ctlOffsetY is a value that represents a proportion of the Height of the control. Its default value is 0.75
If for example we set ctlPosition = 8 (CON_ALIGN_BOTTOMRIGHT), ctlOffsetX = 1.00, ctlOffsetY = 1.00, then the tip of the ballontip will point to the lower right corner of the control.
Experiment with different values of ctlOffsetX and ctlOffsetY to understand how it works.
This method of calculating an offset works better than a fixed offset in pixels, the positioning of the tooltip is proportional to the size of the control.
ctlPosition specifies the point of the control where the tip of the tooltip will be positioned, or the way a rectangular tip will be positioned.
In the image, the red dots represent the possible ctlPosition values. This values where taken from the native Alignment VFP property for CommandButtons and TextBoxes.
ctlAlignment specifies the way the tooltip will be aligned according to the point specified by ctlPosition.
In the image, the red dots represent a certain ctlPosition, the yellow rectangle represents a tooltip.
If you choose 0 or 1 for a balloontip, the alignment will be by default 7 or 8, unless there is no space in the bottom of the screen, in that case the alignment will be 4 or 5.
If you set ctlPositionStyle to CON_BTPOS_LEFTTOP or CON_BTPOS_MOUSE, ctlPosition will be ignored, but not ctlAlignment.
The ctlTrack method ignores both ctlPosition and ctlAlignment, and always uses a value of 3 (CON_ALIGN_AUTOMATIC).
All this properties and their interaction are a little confusing, but the example project has a nice form that will allow you to experiment with this properties.
Here are some images with typical alignment and position values:
ctlAlignment values of 0, 1, 2 for balloontips will align the balloontip under the control, but will align the balloontip above the control if there is not enough space under it.
ctlAlignment value of 3 will align the tooltip under the control and to the right, but will align the tooltip to the left or above the control if there is not enough screen space.
ctlAlignment values of 4, 5, 6 will always align the tooltip as desired, even if there is not enough screen space.
ctlAlignment values of 7, 8, 9 will always align the tooltip as desired, even if there is not enough screen space.
And yes, I know, its Balloon not Ballon, but I refuse to make the images again.

 


Links

No comments:

Post a Comment