Hint Personalizado
peguei ai no clube um código
abaixo..
ate que funciona na maioria dos componentes so que por exemplo
um hint em um speedButton,image ele nao funciona
procedure CreateToolTips(hWnd: Cardinal);
begin
hToolTip := CreateWindowEx(0, ´Tooltips_Class32´, nil, TTS_ALWAYSTIP or TTS_BALLOON,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT), hWnd, 0, hInstance, nil);
if hToolTip <> 0 then begin
SetWindowPos(hToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE or SWP_NOACTIVATE);
ti.cbSize := SizeOf(TToolInfo);
ti.uFlags := TTF_SUBCLASS;
ti.hInst := hInstance;
end;
end;
procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer; Text, Title: PChar);
Var Item: THandle;
Rect: TRect;
begin
CreateToolTips(hWnd);
Item := hWnd;
if (Item <> 0) AND (GetClientRect(Item, Rect)) then begin
lpti.hwnd := Item;
lpti.Rect := Rect;
lpti.lpszText := Text;
SendMessage(hToolTip, TTM_ADDTOOL, 0, Integer(lpti));
FillChar(buffer, sizeof(buffer), #0);
lstrcpy(buffer, Title);
if (IconType > 3) or (IconType < 0) then IconType := 0;
SendMessage(hToolTip, TTM_SETTITLE, IconType, Integer(@buffer));
end;
end;
procedure TForm1.ApplicationEvents1ShowHint(var HintStr: String;
var CanShow: Boolean; var HintInfo: THintInfo);
Var TextoHint,Icone,Cabecalho,Mensagem :String;
begin
if (HintInfo.HintControl is TWinControl) then begin
HintInfo.HintControl.ShowHint:=False;
CanShow:=False;
//Formato do Hint nos Controles : Icone, Texto do Cabecalho, Texto da Mensagem.
// Ex : 1Mensagem do SistemaEste botao fecha o cadastro.
//Onde Icone: 1=Informacao, 2=Aviso, 3=Erro.
TextoHint:=HintStr;
//Pega o Icone.
Icone:=Copy(TextoHint,Pos(´´,TextoHint)-1,1);
Delete(TextoHint,1,Pos(´#´,TextoHint));
//Pega o Cabecalho.
Cabecalho:=Copy(TextoHint,1,Pos(´´,TextoHint)-1);
Delete(TextoHint,1,Pos(´´,TextoHint));
//Pega a Mensagem.
Mensagem:=TextoHint;
AddToolTip(TWinControl(HintInfo.HintControl).Handle, @ti, StrToInt(Icone),PChar(Mensagem),Pchar(Cabecalho));
end
else begin
if (HintInfo.HintControl is TGraphicControl) then begin
TextoHint:=HintStr;
//Pega o Icone.
Delete(TextoHint,1,Pos(´´,TextoHint));
//Pega o Cabecalho.
Delete(TextoHint,1,Pos(´´,TextoHint));
//Pega a Mensagem.
Mensagem:=TextoHint;
TControl(HintInfo.HintControl).Hint:=Mensagem;
HintInfo.HintControl.Hint:=Mensagem;
HintInfo.HintControl.ShowHint:=True;
CanShow:=True;
AddToolTip(application.Handle, @ti, 1,PChar(Mensagem),Pchar(´sfsdf´));
end;
end;
end;
[/code]abaixo..
ate que funciona na maioria dos componentes so que por exemplo
um hint em um speedButton,image ele nao funciona
procedure CreateToolTips(hWnd: Cardinal);
begin
hToolTip := CreateWindowEx(0, ´Tooltips_Class32´, nil, TTS_ALWAYSTIP or TTS_BALLOON,
Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT), hWnd, 0, hInstance, nil);
if hToolTip <> 0 then begin
SetWindowPos(hToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or
SWP_NOSIZE or SWP_NOACTIVATE);
ti.cbSize := SizeOf(TToolInfo);
ti.uFlags := TTF_SUBCLASS;
ti.hInst := hInstance;
end;
end;
procedure AddToolTip(hwnd: dword; lpti: PToolInfo; IconType: Integer; Text, Title: PChar);
Var Item: THandle;
Rect: TRect;
begin
CreateToolTips(hWnd);
Item := hWnd;
if (Item <> 0) AND (GetClientRect(Item, Rect)) then begin
lpti.hwnd := Item;
lpti.Rect := Rect;
lpti.lpszText := Text;
SendMessage(hToolTip, TTM_ADDTOOL, 0, Integer(lpti));
FillChar(buffer, sizeof(buffer), #0);
lstrcpy(buffer, Title);
if (IconType > 3) or (IconType < 0) then IconType := 0;
SendMessage(hToolTip, TTM_SETTITLE, IconType, Integer(@buffer));
end;
end;
procedure TForm1.ApplicationEvents1ShowHint(var HintStr: String;
var CanShow: Boolean; var HintInfo: THintInfo);
Var TextoHint,Icone,Cabecalho,Mensagem :String;
begin
if (HintInfo.HintControl is TWinControl) then begin
HintInfo.HintControl.ShowHint:=False;
CanShow:=False;
//Formato do Hint nos Controles : Icone, Texto do Cabecalho, Texto da Mensagem.
// Ex : 1Mensagem do SistemaEste botao fecha o cadastro.
//Onde Icone: 1=Informacao, 2=Aviso, 3=Erro.
TextoHint:=HintStr;
//Pega o Icone.
Icone:=Copy(TextoHint,Pos(´´,TextoHint)-1,1);
Delete(TextoHint,1,Pos(´#´,TextoHint));
//Pega o Cabecalho.
Cabecalho:=Copy(TextoHint,1,Pos(´´,TextoHint)-1);
Delete(TextoHint,1,Pos(´´,TextoHint));
//Pega a Mensagem.
Mensagem:=TextoHint;
AddToolTip(TWinControl(HintInfo.HintControl).Handle, @ti, StrToInt(Icone),PChar(Mensagem),Pchar(Cabecalho));
end
else begin
if (HintInfo.HintControl is TGraphicControl) then begin
TextoHint:=HintStr;
//Pega o Icone.
Delete(TextoHint,1,Pos(´´,TextoHint));
//Pega o Cabecalho.
Delete(TextoHint,1,Pos(´´,TextoHint));
//Pega a Mensagem.
Mensagem:=TextoHint;
TControl(HintInfo.HintControl).Hint:=Mensagem;
HintInfo.HintControl.Hint:=Mensagem;
HintInfo.HintControl.ShowHint:=True;
CanShow:=True;
AddToolTip(application.Handle, @ti, 1,PChar(Mensagem),Pchar(´sfsdf´));
end;
end;
end;
Mysys
Curtidas 0