日期:2011-03-22 13:55:00 来源:本站整理
若何自定义提醒窗口(Hint Window)[VC/C++编程]
本文“若何自定义提醒窗口(Hint Window)[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
// 自定义 THintWindow 类
class TCcrunHintWindow : public THintWindow
{
bool FActivating;
__fastcall TCcrunHintWindow(TComponent* Owner)
: THintWindow(Owner)
{
Canvas->Font->Name = "宋体";
Canvas->Font->Color = clBlack;
Canvas->Font->Size = 9;
}
void __fastcall Paint( void)
{
TRect rect = ClientRect;
// Hint边框颜色
Canvas->Brush->Color = TColor(0xDBB8BA);
Canvas->FillRect(rect);
// 绘制整个Hint的边框
Canvas->Pen->Color = TColor(0x69230E);
Canvas->Rectangle(rect);
// Hint后台的颜色
Color = clWhite;
// Hint文字透明
Canvas->Brush->Style = bsClear;
// 绘出Hint文字
Canvas->Font->Color = clBlack;
Canvas->TextOut(4, int(rect.Bottom / 2)
- int(Canvas->TextHeight(Caption) / 2), Caption);
}
virtual void __fastcall NCPaint(HDC hdc)
{
// 63 63 72 75 6E 2E 63 6F 6D
Invalidate();
}
virtual void __fastcall CreateParams(TCreateParams &Params)
{
// 去掉Hint窗口的边框
Params.Style = Params.Style & ~WS_BORDER;
THintWindow::CreateParams(Params);
}
// Code by ccrun(老妖),做人要诚恳,转载请留名
virtual void __fastcall ActivateHint( const TRect &Rect, const String AHint)
{
FActivating = true;
try
{
Caption = AHint;
TRect r = Rect;
r.Left -= 10;
r.Right += 10;
r.Top -= 5;
r.Bottom += 5;
// 更新区域
UpdateBoundsRect(r);
// Hint窗口处于屏幕边沿时的调整
if(r.Top + Height > Screen->DesktopHeight)
r.Top = Screen->DesktopHeight - Height;
if(r.Left + Width > Screen->DesktopWidth)
r.Left = Screen->DesktopWidth - Width;
if(r.Left < Screen->DesktopLeft)
r.Left = Screen->DesktopLeft;
if(r.Bottom < Screen->DesktopTop)
r.Bottom = Screen->DesktopTop;
// 成立一个矩形
// 63 63 72 75 6E 2E 63 6F 6D
HRGN hrgn = CreateRectRgn(0, 0, r.Width(), r.Height());
// HRGN hrgn = CreateRoundRectRgn(0, 0, r.Width(), r.Height(), 4, 4);
// 设置指定句柄的窗口形状
SetWindowRgn(Handle, hrgn, true);
// 改变窗口的位置,Z Order,及其他一些属性
SetWindowPos(Handle, HWND_TOPMOST, r.Left, r.Top, r.Width(),
r.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE);
// 重画窗口
Invalidate();
}
__finally
{
FActivating = false;
}
}
};
//---------------------------------------------------------------------------
// 实现代码
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
HintWindowClass = __classid(TCcrunHintWindow);
//
ShowHint = true;
Button1->Hint = "这是一个按钮";
Edit1->Hint = "这是一个文本框";
}
以上是“若何自定义提醒窗口(Hint Window)[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论