Article View: borland.public.cppbuilder.nativeapi
Article #5582Re: ToolTip Notify ?
From: JD
Date: Wed, 03 Aug 2005 07:18
Date: Wed, 03 Aug 2005 07:18
203 lines
8189 bytes
8189 bytes
"Sasan" <sasan_vm@yahoo.com> wrote:
>
> [...] I test TTN_LINKCLICK in ToolTip wndproc but no result !
I found the problem. While my solution in the VCL.Using group
works and is perfectly ok to use, I have a better solution
because now I understand what you were trying to do with:
>#ifdef STRICT
> OLDWNDPROC WNDPROC
>#else
> OLDWNDPROC FARPROC
>#endif
>OLDWNDPROC TTDefWndProc;
Where ever you got the sample, what they had done was to
subclass the the target control's WindowProc method. The
reason that they took this approach was because for the
hwnd member of the TOOLINFO struct, if you used anything
other than the the target control's Handle, you have to
manualy position the ToolTip. BUT ... this also means that
all notification will be sent to the target control and
that's why the sample subclasses the target control's
WindowProc method:
//-------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//-------------------------------------------------------------
#include <Classes.hpp>
//-------------------------------------------------------------
class TToolTip : public TComponent
{
private:
HWND FHandle, FHToolTip;
bool FVisible;
unsigned int FTimer;
TOOLINFO FTInfo;
TControl *pControl;
TWndMethod OldWndProc;
void __fastcall NewWndProc( TMessage &Message );
void __fastcall StartTimer( bool Enable );
void __fastcall Hide();
protected:
virtual void __fastcall WndProc( TMessage &Message );
public:
void __fastcall Show( TWinControl *AControl, char *Title, char *Text, int IconType );
__fastcall TToolTip(TComponent* Owner);
__fastcall ~TToolTip();
};
//-------------------------------------------------------------
#endif
//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//-------------------------------------------------------------
#pragma package(smart_init)
//-------------------------------------------------------------
__fastcall TToolTip::TToolTip( TComponent *Owner ) : TComponent(Owner)
{
pControl = NULL;
FVisible = false;
FHToolTip = NULL;
FTimer = NULL;
FHandle = AllocateHWnd( WndProc );
}
//-------------------------------------------------------------
__fastcall TToolTip::~TToolTip()
{
if( FTimer ) ::KillTimer( FHandle, FTimer );
if( FHToolTip ) Hide();
DeallocateHWnd( FHandle );
}
//-------------------------------------------------------------
void __fastcall TToolTip::WndProc( TMessage &Message )
{
if( Message.Msg == WM_TIMER && (unsigned)Message.WParam == FTimer )
{
Hide();
}
else if( Message.Msg == WM_USER + 100 )
{
if( FHToolTip ) ::DestroyWindow( FHToolTip );
FHToolTip = NULL;
FVisible = false;
}
else Message.Result = DefWindowProc( FHandle, Message.Msg, Message.WParam, Message.LParam );
}
//-------------------------------------------------------------
void __fastcall TToolTip::NewWndProc( TMessage &Message )
{
if( Message.Msg == WM_NOTIFY )
{
LPNMHDR lp = (LPNMHDR) Message.LParam;
switch( lp->code )
{
case TTN_POP: StartTimer( false );
if( pControl ) pControl->WindowProc = OldWndProc;
::PostMessage( FHandle, WM_USER + 100, 0, 0 );
break;
case TTN_SHOW: break;
case TTN_NEEDTEXT: break; // same as TTN_GETDISPINFO
case TTN_LINKCLICK: Hide();
ShowMessage("Execute Link Click");
break;
case NM_CUSTOMDRAW: break;
}
}
OldWndProc( Message );
}
//-------------------------------------------------------------
void __fastcall TToolTip::Hide()
{
StartTimer( false );
if( FHToolTip ) ::DestroyWindow( FHToolTip );
FHToolTip = NULL;
FVisible = false;
if( pControl ) pControl->WindowProc = OldWndProc;
}
//-------------------------------------------------------------
void __fastcall TToolTip::StartTimer( bool Enable )
{
if( Enable )
{
if( !FTimer )
{
FTimer = ::SetTimer( FHandle, WM_USER + 100, 5000, NULL );
}
}
else
{
if( FTimer )
{
::KillTimer( FHandle, FTimer );
FTimer = NULL;
}
}
}
//-------------------------------------------------------------
void __fastcall TToolTip::Show( TWinControl *AControl, char *Title, char *Text, int IconType )
{
if( !FVisible )
{
DWORD dwExStyle = WS_EX_TOPMOST;
DWORD dwStyle = WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE;
if( FHToolTip ) ::DestroyWindow( FHToolTip );
FHToolTip = ::CreateWindowEx( dwExStyle, TOOLTIPS_CLASS, NULL, dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, Application->Handle, 0, HInstance, NULL );
if( FHToolTip )
{
UINT uFlags = TTF_PARSELINKS | TTF_SUBCLASS | TTF_TRANSPARENT | TTF_CENTERTIP;
::SetWindowPos( FHToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
FTInfo.cbSize = sizeof( TOOLINFO );
FTInfo.uFlags = uFlags;
FTInfo.hinst = HInstance;
}
else throw Exception("ERROR - In create window.");
TPoint P;
::ClientToScreen( AControl->Handle, &P );
::GetClientRect( AControl->Handle, &FTInfo.rect );
FTInfo.hwnd = AControl->Handle;
AnsiString aText = "Your evaluation period is over\r\n"
"for register program got to "
"<a href=\"http://www.trz.com\">"
"http://www.trz.com</a>\r\n"
"or mail to "
"<a href=\"mailto:cms@trz.com\">"
"cms@trz.com</a>\r\n\r\n"
"(c) Computer Center City\r\n"
"TELFAX : +22 0541 3211322\r\n"
"MOBILE : +22 0915 3409673";
FTInfo.lpszText = aText.c_str();
pControl = dynamic_cast<TControl*>( AControl );
if( pControl )
{
OldWndProc = pControl->WindowProc;
pControl->WindowProc = NewWndProc;
}
// SendMessage( FHToolTip, TTM_SETTIPBKCOLOR, (WPARAM)ColorToRGB(clBlue), 0 );
// SendMessage( FHToolTip, TTM_SETTIPTEXTCOLOR, (WPARAM)ColorToRGB(clBlack), 0 );
SendMessage( FHToolTip, TTM_ADDTOOL, 0, (LPARAM)&FTInfo );
SendMessage( FHToolTip, TTM_SETTITLE, IconType, (LPARAM)Title );
SendMessage( FHToolTip, TTM_TRACKPOSITION, 0, (LPARAM)MAKELONG(P.x,P.y) );
SendMessage( FHToolTip, TTM_TRACKACTIVATE, (WPARAM)true, (LPARAM)&FTInfo );
StartTimer( true );
FVisible = true;
}
}
//-------------------------------------------------------------
~ JD
Technical Details
Message-ID:
<42f06fc5$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<42eeff0c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7cccfbb0a45ed729 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: ToolTip Notify ? Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 205.188.116.135 X-Forwarded-For: 172.136.209.154 References: <42eeff0c@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <42f06fc5$1@newsgroups.borland.com> Date: 3 Aug 2005 00:18:29 -0700 X-Trace: newsgroups.borland.com 1123053509 207.105.83.66 (3 Aug 2005 00:18:29 -0700) Lines: 204 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!newsread.com!newsprint.newsread.com!news-out.newsfeeds.com!propagator3-LAX.newsfeeds.com!news-in.newsfeeds.com!news-in.superfeed.net!caladan.landsraad.net!newsgroups.borland.com!not-for-mail