|
Quellcode : tip.h
//--------------------------------------------------------------------- #ifndef tipH #define tipH //--------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <ComCtrls.hpp> //--------------------------------------------------------------------- class TForm1 : public TForm { __published:// Von der IDE verwaltete Komponenten TButton *Button1; TButton *ButtonClose; void __fastcall FormCreate(TObject *Sender); void __fastcall ButtonCloseClick(TObject *Sender); private:// Anwender-Deklarationen public:// Anwender-Deklarationen int Flags; void ToolTip( HWND , wchar_t* wcText, TColor clBackCol, TColor clTextCol ); __fastcall TForm1(TComponent* Owner);
}; //--------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------- #endif
Quellcode tip.cpp
//--------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop
#include "tip.h" #include "windows.h" //--------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Flags = TTF_TRANSPARENT | TTF_SUBCLASS; ToolTip( Button1->Handle , L"Button1", clWhite, clBlack ); ToolTip( ButtonClose->Handle , L"Program exit!", clWhite, clBlack ); } //--------------------------------------------------------------------- void TForm1::ToolTip( HWND hWnd, wchar_t* wcText, TColor clBackCol, TColor clTextCol ) { HWND hWndToolTip; TOOLINFOW ti;
hWndToolTip = CreateWindow( TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | 0x40 | TTS_ALWAYSTIP, 0, 0, 0, 0, hWnd, 0, HInstance, NULL ); if( hWndToolTip != 0 ) { SetWindowPos( hWndToolTip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
memset(&ti,0,sizeof(ti)); ti.cbSize = sizeof(ti); ti.uFlags = Flags; ti.hwnd = hWnd; ti.lpszText = wcText; ti.rect = Form1->GetClientRect();
SendMessage( hWndToolTip, TTM_ADDTOOLW, 0, (LPARAM)&ti ); } }
void __fastcall TForm1::ButtonCloseClick(TObject *Sender) { Close(); } //---------------------------------------------------------------------
|
|