主题:c++builder自画提示
我想在c++Builder中自画带图标的提示栏,我已编写好两个重载函数如下:
Types::TRect __fastcall THcf::CalcHintRect(int MaxWidth, const
AnsiString AHint, void * AData)
{
Types::TRect DefRect=THintWindow::CalcHintRect(MaxWidth,AHint,AData);
DefRect.Right=AHint.Length()*5+Application->Icon->Width;
DefRect.Bottom=(Application->Icon->Height)*2;
return DefRect;
}
//---------------------------------------------------------------------------------------------
void __fastcall THcf::Paint(void)
{
THintWindow::Paint();
Canvas->Draw(5,25,Application->Icon);
SendMessage(Application->Handle,WM_NCPAINT, 0, 0);
}
__fastcall THcf::THcf(TComponent* Owner)
:THintWindow(Owner)
{
HintWindowClass=THcf;//在delphi中可直接这样赋值;在c++builder中我不知道怎样进行类型转化,希望各位朋友能帮我解决这个问题,我深表感谢。
}
//-------------------------------
delphi程序代码如下:
unit HintX;
interface
uses
Windows, Messages, Controls;
type
TIconHintX = class(THintWindow)
protected
procedure Paint; override;
public
function CalcHintRect(MaxWidth: Integer; const AHint: string;
AData: Pointer): TRect; override;
end;
implementation
uses Forms;
{ TIconHintX }
{-为了放置一个图标,重新计算提示栏窗体的大小:-}
function TIconHintX.CalcHintRect(MaxWidth: Integer; const AHint:
string;
AData: Pointer): TRect;
begin
Result := inherited CalcHintRect(MaxWidth, AHint, AData);
Result.Right := (Length(AHint) * 5) + Application.Icon.Width;
Result.Bottom := (Application.Icon.Height) * 2;
end;
procedure TIconHintX.Paint;
const
MARGIN = 5;
begin
inherited;
Canvas.Draw(MARGIN, MARGIN * 5, Application.Icon);
SendMessage(Handle, WM_NCPAINT, 0, 0); //画提示栏边框
end;
initialization
//把我们的新类设置为默认的提示栏类:
HintWindowClass := TIconHintX;
end.
//为了看到效果, 把这个单元放置在你的应用程序的引用单元列表中。
Emai:hcf740327a@yahoo.com.cn
Emai:bcbdev@china.com
Types::TRect __fastcall THcf::CalcHintRect(int MaxWidth, const
AnsiString AHint, void * AData)
{
Types::TRect DefRect=THintWindow::CalcHintRect(MaxWidth,AHint,AData);
DefRect.Right=AHint.Length()*5+Application->Icon->Width;
DefRect.Bottom=(Application->Icon->Height)*2;
return DefRect;
}
//---------------------------------------------------------------------------------------------
void __fastcall THcf::Paint(void)
{
THintWindow::Paint();
Canvas->Draw(5,25,Application->Icon);
SendMessage(Application->Handle,WM_NCPAINT, 0, 0);
}
__fastcall THcf::THcf(TComponent* Owner)
:THintWindow(Owner)
{
HintWindowClass=THcf;//在delphi中可直接这样赋值;在c++builder中我不知道怎样进行类型转化,希望各位朋友能帮我解决这个问题,我深表感谢。
}
//-------------------------------
delphi程序代码如下:
unit HintX;
interface
uses
Windows, Messages, Controls;
type
TIconHintX = class(THintWindow)
protected
procedure Paint; override;
public
function CalcHintRect(MaxWidth: Integer; const AHint: string;
AData: Pointer): TRect; override;
end;
implementation
uses Forms;
{ TIconHintX }
{-为了放置一个图标,重新计算提示栏窗体的大小:-}
function TIconHintX.CalcHintRect(MaxWidth: Integer; const AHint:
string;
AData: Pointer): TRect;
begin
Result := inherited CalcHintRect(MaxWidth, AHint, AData);
Result.Right := (Length(AHint) * 5) + Application.Icon.Width;
Result.Bottom := (Application.Icon.Height) * 2;
end;
procedure TIconHintX.Paint;
const
MARGIN = 5;
begin
inherited;
Canvas.Draw(MARGIN, MARGIN * 5, Application.Icon);
SendMessage(Handle, WM_NCPAINT, 0, 0); //画提示栏边框
end;
initialization
//把我们的新类设置为默认的提示栏类:
HintWindowClass := TIconHintX;
end.
//为了看到效果, 把这个单元放置在你的应用程序的引用单元列表中。
Emai:hcf740327a@yahoo.com.cn
Emai:bcbdev@china.com