国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

如何自定義提示窗口(Hint Window)

2019-11-17 05:32:19
字體:
來源:轉載
供稿:網友

  // 自定義 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 = "這是一個文本框";
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宾阳县| 渝北区| 柯坪县| 张家口市| 获嘉县| 静乐县| 永吉县| 资中县| 河北省| 宜兴市| 怀集县| 乡城县| 昌平区| 科尔| 贞丰县| 南皮县| 察隅县| 金平| 巴南区| 永福县| 南涧| 西华县| 三江| 池州市| 汉阴县| 星子县| 梓潼县| 广西| 华宁县| 博乐市| 扶风县| 沧源| 信阳市| 蒲江县| 安阳市| 平谷区| 彩票| 汪清县| 金溪县| 白银市| 密山市|