How to customize the Prompt window (Hint windows)

Source: Internet
Author: User
Tags border color
Custom Thintwindow Class
Class Tccrunhintwindow:public Thintwindow
{
BOOL factivating;
__fastcall Tccrunhintwindow (tcomponent* Owner)
: Thintwindow (Owner)
{
Canvas->font->name = "Song Body";
Canvas->font->color = Clblack;
Canvas->font->size = 9;
}
void __fastcall Paint (void)
{
Trect rect = clientrect;
Hint Border color
Canvas->brush->color = TColor (0XDBB8BA);
Canvas->fillrect (rect);
Draw the entire hint border
Canvas->pen->color = TColor (0x69230e);
Canvas->rectangle (rect);
Color of hint background
Color = Clwhite;
Hint Text transparency
Canvas->brush->style = Bsclear;
Draw the hint text
Canvas->font->color = Clblack;
Canvas->textout (4, int (rect). BOTTOM/2)
-Int (Canvas->textheight (Caption)/2), Caption);
}
virtual void __fastcall ncpaint (HDC HDC)
{
6E 2E 6F 6D
Invalidate ();
}
virtual void __fastcall createparams (tcreateparams &params)
{
Remove the border from the hint window
Params.style = Params.style & ~ws_border;
Thintwindow::createparams (Params);
}
Code by Ccrun (old demon), a person to be kind, reprint please be remembered
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;
Update area
Updateboundsrect (R);
Adjust the hint window when it is on the edge of the screen
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;
Create a rectangle
6E 2E 6F 6D
Hrgn hrgn = createrectrgn (0, 0, r.width (), R.height ());
Hrgn hrgn = createroundrectrgn (0, 0, r.width (), R.height (), 4, 4);
Sets the window shape of the specified handle
SetWindowRgn (Handle, Hrgn, true);
Change the position of the window, Z order, and some other attributes
SetWindowPos (Handle, Hwnd_topmost, R.left, R.top, R.width (),
R.height (), Swp_showwindow | Swp_noactivate);
Repaint window
Invalidate ();
}
__finally
{
Factivating = false;
}
}
};
//---------------------------------------------------------------------------
// 实现代码
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
  HintWindowClass = __classid(TCcrunHintWindow);
  //
  ShowHint = true;
  Button1->Hint = "这是一个按钮";
  Edit1->Hint = "这是一个文本框";
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.