This last week of August, I thought how could I create a class that would show a tooltip with 3 parts: a header, a footer and a message to the possibility in the future to include a picture, I took the cue from the class Super tooltips DoNEtTcomponents (http : / / http://www.devcomponents.com / dotnetbar / SuperTooltips.aspx)
I think thi class could run ok if there is a CLASSDATA on WIndows CLASS called otooltip
on ttoltip class see the line // ::oWnd:oToolTip := Self where oWnd is the control where we want show the tooltip
I see this otooltip is only a static value now , but I think Antonio make it for speed!!
Now I use this class simply on bMMoved action then we can insert it as tooltip system
I not know how insert Balloons tooltip But I think Antonio found the solution for it
we can set the size of tooltip and the timer for now and insert an header, an footer, an message
if not therea re not headers and footer it show only the message as the tooltip system
this is the test.prg
- Code: Select all Expand view RUN
#include "fivewin.ch"
#define CLRTEXTBACK RGB( 113, 106, 183 )
#define COLOR_GRAYTEXT 17
#define DEFAULT_GUI_FONT 17
#define CS_DROPSHADOW 0x00020000
#define GCL_STYLE (-26)
fUNCTION TEST ()
Local oDlg,oBtn
DEFINE DIALOG oDlg SIze 400,400
@ 1,1 BUTTON oBtn PROMPT "TEST" SIZE 40,20 OF oDlg
oBtn:cTooltip:= NIL
oToolTip := TTooltip():New(oBtn)
cMessage :="This is a Super Tooltip for Fivewin Power"+CRLF+CRLF+CRLF+;
"This is also on Beta Test" +CRLF+CRLF+CRLF+;
" SuperTooltip with Image (on Future)"
cHeader := "Header Super Tooltip"
cFooter := "Press F1 for more Help "
* oToolTip:nHeightTip :=300
* oToolTip:nWidthTip :=300
oToolTip:nTimer :=1000
// With header , message and footer
oBtn:bMMoved := { || oToolTip:Show( oBtn:ntop - 6, oBtn:nLeft - 6, cHeader, oBtn,cFooter, cMessage ) } // rem this for try
// With header , message rem this for try
// oBtn:bMMoved := { || oToolTip:Show( oBtn:ntop - 6, oBtn:nLeft - 6, cHeader, oBtn,, cMessage ) } // rem this for try
// with only a message
// oBtn:bMMoved := { || oToolTip:Show( oBtn:ntop - 6, oBtn:nLeft - 6, , oBtn,, cMessage ) } // rem this for try
ACTIVATE DIALOG oDLg
return nil
this the class TToltip .prg
- Code: Select all Expand view RUN
CLASS TTooltip FROM TWindow
DATA nHeightRow
DATA oTimer, nTimer
DATA oToolTip
DATA nHeightTip,nWidthTip
DATA nColorTooltip
DATA cImage
DATA cHeader
DATA cMessage
DATA cFooter
CLASSDATA lRegistered AS LOGICAL
METHOD New( oWnd, nClrText, nClrPane, oFont,nHeightTip,nWidthTip,nTimer,nColorTooltip,cImage) CONSTRUCTOR
METHOD Hide() INLINE ::lVisible := .f., Super:Hide()
METHOD Show( nRow, nCol, cHeader, oWnd,cFooter,cMessage )
METHOD Paint()
METHOD Line( hDC, nTop, nLeft, nBottom, nRight, nColor )
METHOD CalcLen( cMessage ) // calc the text width for simply tooltip
ENDCLASS
METHOD New( oWnd, nClrText, nClrPane, oFont,nHeightTip,nWidthTip,nTimer,nColorTooltip,cImage ) CLASS TTooltip
Local nWText
DEFAULT nClrText := CLR_BLACK,;
nColorTooltip := CLR_YELLOW ,;
nClrPane := nColorTooltip,;
nHeightTip:= 300 ,;
nWidthTip := 300,;
nTimer := 1000
::nTimer := nTimer
::lVisible := .f.
::oWnd := oWnd
::nHeightTip := nHeightTip
::nWidthTip := nWidthTip
::nColorTooltip := nColorTooltip
::cImage := cImage
* ::oWnd:oToolTip := Self //if there is oToolTip as class data on window class
DEFINE FONT ::oFont NAME GetSysFont() SIZE 0, -8
::nHeightRow := ::oFont:nHeight + 3
::nStyle := nOR( WS_POPUP, WS_BORDER )
::SetColor( nClrText, nClrPane )
::Register()
::Create()
::Hide()
Return Self
METHOD Paint() CLASS TTooltip
Local hDC := ::GetDC()
Local oThis := self
Local hOldFont
local lHeader :=.f.
IF ::oTimer != nil
::oTimer:Deactivate()
endif
DEFINE TIMER ::oTimer INTERVAL ::nTimer ACTION oThis:Hide() OF Self
ACTIVATE TIMER ::oTimer
FillSolidRect( ::hDC, GetClientRect(::hWnd), ::nClrPane )
SetBkMode( ::hDC, 1 )
hOldFont := SelectObject( ::hDC, ::oFont:hFont )
SetTextColor( ::hDC, ::nClrText )
if ::cHeader != nil
DrawText ( ::hDC, ::cHeader, { 1, 1 , ::nHeight, ::nWidth }, 16 )
DrawText ( ::hDC, ::cMessage, { 40, 10 , ::nHeight, ::nWidth }, 16 )
oThis:Line( ::hDC, 35, 0, 35,::nWidthTip, CLR_BLUE)
else
DrawText ( ::hDC, ::cMessage, {1, 1 , ::nHeight, ::nWidth }, 16 )
endif
if ::cFooter != nil
DrawText ( ::hDC, ::cFooter, { ::nHeightTip-30, 40 , ::nHeight, ::nWidth }, 16 )
oThis:Line( ::hDC, ::nHeightTip-35, 0, ::nHeightTip-35,::nWidthTip, CLR_BLUE)
endif
SetBkMode ( ::hDC, 0 )
SelectObject( ::hDC, hOldFont )
if ::bPainted != nil
Eval( ::bPainted, ::hDC, self )
endif
::ReleaseDC()
return nil
METHOD Line( hDC, nTop, nLeft, nBottom, nRight, nColor ) CLASS TTooltip
local hPen, hOldPen
hPen = CreatePen( PS_SOLID, 1, nColor )
hOldPen = SelectObject( hDC, hPen )
MoveTo( hDC, nLeft, nTop )
LineTo( hDC, nRight, nBottom )
SelectObject( hDC, hOldPen )
DeleteObject( hPen )
return nil
METHOD Show( nRow, nCol, cHeader, oWnd, cFooter, cMessage) CLASS TTooltip
Local n
Local aPoint := { nRow, nCol }
Local aLin, nCalcLen
Local nHeight
Local nWidth
Local nHScreen := GetSysMetrics( 1 )
Local nWScreen := GetSysMetrics( 0 )
Local nLines
if ::lVisible
::Hide()
endif
//if there is the header and the footer
if cHeader != nil
::cHeader := cHeader
if cFooter != nil
::cFooter := cFooter
endif
if cMessage != nil
::cMessage:=cMessage
endif
nWidth:= ::nHeightTip
nHeight:=::nWidthTip
else
// if there is only the message
if cMessage != nil
::cMessage := cMessage
aLin := ::CalcLen( cMessage )
nCalcLen := aLin[1]
nLines := aLin[2]
nWidth := nCalcLen + 4
nHeight := ( nLines * ::nHeightRow ) + 2
endif
endif
ClientToScreen( oWnd:hWnd, aPoint )
if aPoint[ 1 ] == nRow
aPoint := ClientToScreen( oWnd:hWnd, aPoint )
endif
nRow := aPoint[ 1 ]
nCol := aPoint[ 2 ]
if nRow + nHeight > nHScreen
nRow := nHScreen - nHeight - 10
endif
if nCol + nWidth > nWScreen
nCol := nWScreen - nWidth - 10
endif
::Move( nRow, nCol, nWidth, nHeight , .t. )
Super:Show()
::lVisible := .t.
Return nil
METHOD CalcLen( cMessage ) CLASS TTooltip
Local n, cLine
Local nLines := mlcount( cMessage )
Local nCalcLen := 0
For n := 1 to nLines
cLine := rtrim( memoline( cMessage,, n))
nCalcLen := max( nCalcLen, ::GetWidth( cLine, ::oFont ) + 8 )
next n
return { nCalcLen, nLines }
#pragma BEGINDUMP
#include "Windows.h"
#include "hbapi.h"
HB_FUNC( FILLSOLIDRECT )
{
RECT rct;
COLORREF nColor;
HPEN hPen, hOldPen;
HDC hDC = ( HDC ) hb_parnl( 1 );
rct.top = hb_parni( 2, 1 );
rct.left = hb_parni( 2, 2 );
rct.bottom = hb_parni( 2, 3 );
rct.right = hb_parni( 2, 4 );
nColor = SetBkColor( hDC, hb_parnl( 3 ) );
ExtTextOut( hDC, 0, 0, ETO_OPAQUE, &rct, NULL, 0, NULL);
SetBkColor( hDC, nColor );
if( hb_pcount() > 3 )
{
hPen = CreatePen( PS_SOLID, 1,(COLORREF)hb_parnl( 4 ));
hOldPen = (HPEN) SelectObject( hDC, hPen );
MoveToEx( hDC, rct.left, rct.top, NULL );
LineTo( hDC, rct.right-3, rct.top );
LineTo( hDC, rct.right-3, rct.bottom );
LineTo( hDC, rct.left, rct.bottom );
LineTo( hDC, rct.left, rct.top );
SelectObject( hDC, hOldPen );
DeleteObject( hPen );
}
}
#pragma ENDDUMP