108 lines
2.7 KiB
C++
108 lines
2.7 KiB
C++
//---------------------------------------------------------------------------
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
|
|
#include "GlobalUnit.h"
|
|
#include "SkinHintWindow.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
__fastcall TSkinHintWindow::TSkinHintWindow(TComponent* Owner)
|
|
: THintWindow(Owner)
|
|
{
|
|
// Canvas->Font->Name = "黑体";
|
|
// Canvas->Font->Color = RGB(60,43,23);
|
|
// Canvas->Font->Size = int(10 * 96.0 / g_yDpi + 0.5); //18; //
|
|
|
|
m_pImgTile = new TBitmap();
|
|
m_pImgTile->LoadFromResourceName(int(HInstance), L"HintBkTile");
|
|
}
|
|
|
|
__fastcall TSkinHintWindow::~TSkinHintWindow()
|
|
{
|
|
delete m_pImgTile;
|
|
}
|
|
|
|
void __fastcall TSkinHintWindow::Paint(void)
|
|
{
|
|
TRect rect = ClientRect;
|
|
// Hint边框颜色
|
|
Canvas->Brush->Bitmap = m_pImgTile;
|
|
|
|
Canvas->FillRect(rect);
|
|
// 绘制整个Hint的边框
|
|
//Canvas->Pen->Width = 2;
|
|
Canvas->Pen->Color = RGB(161,113,69);
|
|
//Canvas->RoundRect(0, 0, rect.Width(), rect.Height(), 4, 4);
|
|
Canvas->Rectangle(rect);
|
|
// Hint背景的颜色
|
|
Color = clWhite;
|
|
// Hint文字透明
|
|
Canvas->Brush->Style = bsClear;
|
|
// 绘出Hint文字
|
|
rect.left += 4;
|
|
rect.top += 4;
|
|
DrawText( Canvas->Handle, Caption.c_str(), -1, (RECT*)&rect, DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
|
|
}
|
|
|
|
void __fastcall TSkinHintWindow::NCPaint(HDC hdc)
|
|
{
|
|
//Invalidate();
|
|
}
|
|
|
|
void __fastcall TSkinHintWindow::CreateParams(TCreateParams &Params)
|
|
{
|
|
THintWindow::CreateParams(Params);
|
|
// 去掉Hint窗口的边框
|
|
Params.Style = Params.Style & ~WS_BORDER;
|
|
}
|
|
|
|
void __fastcall TSkinHintWindow::ActivateHint(const TRect &Rect, const String AHint)
|
|
{
|
|
FActivating = true;
|
|
try
|
|
{
|
|
Caption = AHint;
|
|
TRect r = Rect;
|
|
r.Left -= 2;
|
|
r.Right += 2;
|
|
r.Top -= 2;
|
|
r.Bottom += 4;
|
|
|
|
// 更新区域
|
|
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;
|
|
|
|
// 创建一个矩形
|
|
HRGN hRgn = CreateRectRgn(0, 0, r.Width(), r.Height());
|
|
//HRGN hRgn = CreateRoundRectRgn(0, 0, r.Width(), r.Height(), 4, 4);
|
|
// 设置指定句柄的窗口形状
|
|
SetWindowRgn(Handle, hRgn, true);
|
|
DeleteObject( hRgn );
|
|
|
|
// 改变窗口的位置,Z Order,及其他一些属性
|
|
SetWindowPos(Handle, HWND_TOPMOST, r.Left, r.Top, r.Width(),
|
|
r.Height(), SWP_SHOWWINDOW | SWP_NOACTIVATE);
|
|
// 重画窗口
|
|
Invalidate();
|
|
}
|
|
__finally
|
|
{
|
|
// FActivating = false;
|
|
}
|
|
}
|
|
|
|
void __fastcall TSkinHintWindow::ShowHintWindow( const TPoint &Point, const String Ahint )
|
|
{
|
|
TRect rHint = CalcHintRect( 300, Ahint, NULL );
|
|
OffsetRect( rHint, Point.x, Point.y );
|
|
ActivateHint( rHint, Ahint );
|
|
}
|