 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Sasan Guest
|
Posted: Tue Aug 02, 2005 5:05 am Post subject: ToolTip Notify ? |
|
|
Hello,
I want do something when user click on link in tooltip but
i have not know how can grab this message (click on link) ?
I test TTN_LINKCLICK in ToolTip wndproc but no result !
can help me about this notify TTN_LINKCLICK ?
Best regards,
M.T
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifdef STRICT
OLDWNDPROC WNDPROC
#else
OLDWNDPROC FARPROC
#endif
OLDWNDPROC TTDefWndProc;
//---------------------------------------------------------------------------
// ToolTip Window procedure
//
LRESULT CALLBACK TTWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
lParam)
{
LRESULT lRes;
if ( uMsg == WM_NOTIFY )
{
LPNMHDR lp = (LPNMHDR) lParam;
if ( lp->code == TTN_LINKCLICK )
SendMessage(GetParent(hwnd), WM_NOTIFY, wParam, lParam);
}
lRes = CallWindowProc(TTDefWndProc, hwnd, uMsg, wParam, lParam);
return lRes;
}
//---------------------------------------------------------------------------
// Create ToolTip
//
bool __fastcall TToolTip::Create()
{
bool bRes = false;
try
{
DWORD dwExStyle, dwStyle;
dwExStyle = WS_EX_TOPMOST;
if ( FRtl ) dwExStyle |= WS_EX_RIGHT | WS_EX_RTLREADING;
dwStyle = WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP;
if ( FBalloon ) dwStyle |= TTS_BALLOON;
if ( FClose ) dwStyle |= TTS_CLOSE;
if ( FHToolTip )
if ( !DestroyWindow(FHToolTip) )
throw Exception("ERROR - In destroy window.");
FHToolTip = CreateWindowEx( dwExStyle,
TOOLTIPS_CLASS,
NULL,
dwStyle,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
FHParent,
0,
HInstance,
NULL );
if ( FHToolTip != 0 )
{
TTDefWndProc = (OLDWNDPROC) GetWindowLong(FHToolTip,
GWL_WNDPROC);
if ( TTDefWndProc )
{
if ( !SetWindowLong(FHToolTip, GWL_WNDPROC, (LONG)
TTWndProc) )
throw Exception("ERROR - In assign window procedure.");
}
else
throw Exception("ERROR - In get window procedure.");
UINT uFlags;
uFlags = TTF_SUBCLASS | TTF_ABSOLUTE;
if ( FTracking ) uFlags |= TTF_TRACK;
if ( FTransparent ) uFlags |= TTF_TRANSPARENT;
if ( FRtl ) uFlags |= TTF_RTLREADING;
if ( FCenter ) uFlags |= 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.");
bRes = true;
}
catch(Exception & e)
{
Application->ShowException(&e);
}
return bRes;
}
//---------------------------------------------------------------------------
// Form1 Window procedure (Parent of ToolTip)
//
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == WM_NOTIFY)
{
LPNMHDR lp = (LPNMHDR) Message.LParam;
if ( lp->code == TTN_LINKCLICK)
{
////////////////////////////
// Do my code but never happend
}
}
TForm::WndProc(Message);
}
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Aug 02, 2005 6:41 am Post subject: Re: ToolTip Notify ? |
|
|
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote
| Quote: | I want do something when user click on link in tooltip but
i have not know how can grab this message (click on link) ?
I test TTN_LINKCLICK in ToolTip wndproc but no result !
can help me about this notify TTN_LINKCLICK ?
|
Did you read the documentation for TTN_LINKCLICK?
TTN_LINKCLICK only works on XP for balloon tooltips, and only if you include
a manifest file for the application. Your code, however, is not always
creating a balloon tooltip to begin with. You are only creating balloon
tooltips under certain conditions.
Also, you are not taking into account that WM_NOTIFY is always sent to the
window procedure of the *parent* window, but you are trying to catch the
TTN_LINKCLICK notification from the window procedure of the tooltip window
itself, which will never work. At no point in that code did you show where
FHParent is coming from. That is the window where the TTN_LINKCLICK
notification will be sent to.
| Quote: | #ifdef STRICT
OLDWNDPROC WNDPROC
#else
OLDWNDPROC FARPROC
#endif
|
That shouldn't even compile. You are missing #define statements:
#ifdef STRICT
#define OLDWNDPROC WNDPROC
#else
#define OLDWNDPROC FARPROC
#endif
Gambit
|
|
| Back to top |
|
 |
Sasan Guest
|
Posted: Tue Aug 02, 2005 7:18 am Post subject: Re: ToolTip Notify ? |
|
|
Thanks,
Yes i active XP style in my program,
if i remove my define ToolTip window proc,
and trap WM_NOTIFY in Parent Proc,
but nothing happend
// Form1 Window procedure (Parent of ToolTip)
//
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == WM_NOTIFY)
{
LPNMHDR lp = (LPNMHDR) Message.LParam;
if ( lp->code == TTN_LINKCLICK)
{
////////////////////////////
// Do my code but never happend
}
}
TForm::WndProc(Message);
}
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Tue Aug 02, 2005 12:35 pm Post subject: Re: ToolTip Notify ? |
|
|
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote:
See my reply in the VCL.Using group.
~ JD
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Aug 02, 2005 4:54 pm Post subject: Re: ToolTip Notify ? |
|
|
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote
| Quote: | Yes i active XP style in my program,
if i remove my define ToolTip window proc,
and trap WM_NOTIFY in Parent Proc,
but nothing happend
|
You did not answer my question. Like I said earlier, at no point in the
code are you showing where 'FHParent' is coming from. That is the window
where the TTN_LINKCLICK notification will be sent to. Please always how
code snippets that actually compile.
Gambit
|
|
| Back to top |
|
 |
Sasan Guest
|
Posted: Tue Aug 02, 2005 5:22 pm Post subject: Re: ToolTip Notify ? |
|
|
for create ToolTip i use:
TToolTip::TToolTip(HWND Parent)
{
.........
FHParent = Parent;
}
TForm1::TForm1(...)
{
ToolTip = new TToolTip(this->WindowHandle);
}
//-------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == WM_NOTIFY)
{
LPNMHDR lp = (LPNMHDR) Message.LParam;
if ( lp->code == TTN_LINKCLICK)
{
////////////////////////////
// Do my code but never run
ShowMessage("Link click");
}
}
}
Best Regards,
M.T
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote in message
news:42ef1e5f (AT) newsgroups (DOT) borland.com...
Yes i active XP style in my program,
if i remove my define ToolTip window proc,
and trap WM_NOTIFY in Parent Proc,
but nothing happend
You did not answer my question. Like I said earlier, at no point in the
code are you showing where 'FHParent' is coming from. That is the window
where the TTN_LINKCLICK notification will be sent to. Please always how
code snippets that actually compile.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Aug 02, 2005 7:56 pm Post subject: Re: ToolTip Notify ? |
|
|
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote
| Quote: | TForm1::TForm1(...)
{
ToolTip = new TToolTip(this->WindowHandle);
}
|
You should be using the Handle property instead of the WindowHandle:
ToolTip = new TToolTip(this->Handle);
Also, you are not taking into account that the TForm's Handle can change
during the lifetime of the form. You should override the form's CreateWnd()
and DestroyWnd() methods in order to keep the Tooltip's parent window
up-to-date when the form's Handle changes.
Gambit
|
|
| Back to top |
|
 |
Sasan Guest
|
Posted: Tue Aug 02, 2005 8:50 pm Post subject: Re: ToolTip Notify ? |
|
|
I know may be you tired for my questions ,
But Form1 is MainForm and stay in life program.
Best Regards,
M.T
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote in message
news:42efabf1 (AT) newsgroups (DOT) borland.com...
TForm1::TForm1(...)
{
ToolTip = new TToolTip(this->WindowHandle);
}
You should be using the Handle property instead of the WindowHandle:
ToolTip = new TToolTip(this->Handle);
Also, you are not taking into account that the TForm's Handle can change
during the lifetime of the form. You should override the form's
CreateWnd()
and DestroyWnd() methods in order to keep the Tooltip's parent window
up-to-date when the form's Handle changes.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Aug 02, 2005 9:42 pm Post subject: Re: ToolTip Notify ? |
|
|
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote
| Quote: | But Form1 is MainForm and stay in life program.
|
Doesn't matter. What I said before still applies. The lifetime of the form
instance does not dictate the lifetime of the window for the form instance.
There are many operations that can force a control to recreate its window.
Gambit
|
|
| Back to top |
|
 |
JD Guest
|
Posted: Wed Aug 03, 2005 7:18 am Post subject: Re: ToolTip Notify ? |
|
|
"Sasan" <sasan_vm (AT) yahoo (DOT) com> wrote:
| Quote: |
[...] 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:
| Quote: | #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 overrn"
"for register program got to "
"<a href="http://www.trz.com">"
"http://www.trz.com</a>rn"
"or mail to "
"<a href="mailto:cms (AT) trz (DOT) com">"
"cms (AT) trz (DOT) com</a>rnrn"
"(c) Computer Center Cityrn"
"TELFAX : +22 0541 3211322rn"
"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
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|