1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
HWND hwndToolTips;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// liens
// <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb760250(v=vs.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx</a>
// <a href="http://support.microsoft.com/kb/134209" target="_blank">http://support.microsoft.com/kb/134209</a>
// <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb760414(v=vs.85).aspx" target="_blank">http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx</a>
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
POINT cursor;
if(Edit1->Text == "")
{
return;
}
int l = Edit1->Text.Length();
if (l > 0)
if (isupper(Edit1->Text[l]))
{
// on active l'affichage
SendMessage(hwndToolTips, TTM_ACTIVATE, true, 0);
// on acquier la position du curseur
GetCursorPos(&cursor);
// on simule un deplacement
SetCursorPos(cursor.x + 1, cursor.y);
}
if(islower(Edit1->Text[l]))
{
// on desactive l'affichage
SendMessage(hwndToolTips, TTM_ACTIVATE, false, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// gestion affichage Balloon
hwndToolTips = CreateWindow(TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_BALLOON | TTS_ALWAYSTIP,
0, 0, 0, 0, Handle, NULL, HInstance, NULL);
if (hwndToolTips != NULL)
{
TOOLINFO ti;
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_SUBCLASS | TTF_TRANSPARENT | TTF_CENTERTIP;
ti.hinst = NULL;
ti.rect = Edit1->ClientRect;
ti.hwnd = Edit1->Handle;
ti.lpszText = "texte qui s'affiche sur plusieurs lignes parcequ'il depasse la largeur du balloon";
CopyRect( &ti.rect, &(Edit1->ClientRect));
SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti);
// IconType 0 - No icon 1 - Information 2 - Warning 3 - Error
SendMessage(hwndToolTips, TTM_SETTITLE, 0, (LPARAM) "Titre"); // icon 0 a 3
SendMessage(hwndToolTips, TTM_SETMAXTIPWIDTH, 0, 60);
SendMessage(hwndToolTips, TTM_ADJUSTRECT, TRUE, (LPARAM)&ti.rect);
SendMessage(hwndToolTips, TTM_SETTIPTEXTCOLOR, RGB(255,000,125), (LPARAM) &ti);
SendMessage(hwndToolTips, TTM_SETTIPBKCOLOR, RGB(245,255,255), (LPARAM) &ti);
//SendMessage(hwndToolTips, TTM_SETDELAYTIME, TTDT_AUTOPOP, (LPARAM) MAKELONG(8000, 0));
//SendMessage(hwndToolTips, TTM_SETDELAYTIME, TTDT_AUTOMATIC, (LPARAM) MAKELONG(5000, 0));
// SendMessage(hwndToolTips, TTM_SETDELAYTIME, TTDT_INITIAL, 0);
// SendMessage (hwndToolTips, TTM_SETDELAYTIME, TTDT_AUTOMATIC, -1);
// SendMessage (hwndToolTips, TTM_TRACKACTIVATE, false, (LPARAM) &ti);
// SendMessage(hwndToolTips, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG (ti.rect.left - 100, ti.rect.bottom - 200) );
//SendMessage(hwndtooltip, TTM_UPDATETIPTEXT, 0, (LPARAM) (LPTOOLINFO)&ti);
//============
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_SUBCLASS | TTF_TRANSPARENT | TTF_CENTERTIP;
ti.hinst = NULL;
ti.rect = Form1->ClientRect;
ti.hwnd = Form1->Handle;
ti.lpszText = "texte qui s'affiche sur plusieurs lignes parcequ'il depasse la largeur du balloon";
CopyRect( &ti.rect, &(Form1->ClientRect));
SendMessage(hwndToolTips, TTM_ADDTOOL, 0, (LPARAM) &ti);
SendMessage(hwndToolTips, TTM_ACTIVATE, false, 0);
//============
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
POINT cursor;
if((GetKeyState(VK_CAPITAL)&1))
{
// on active l'affichage
SendMessage(hwndToolTips, TTM_ACTIVATE, true, 0);
// on acquier la position du curseur
GetCursorPos(&cursor);
// on simule un deplacement
SetCursorPos(cursor.x + 1, cursor.y);
}
else
{
// on desactive l'affichage
SendMessage(hwndToolTips, TTM_ACTIVATE, false, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
POINT cursor;
if(Edit1->Text == "")
{
return;
}
int l = Edit1->Text.Length();
if (l > 0)
if (isupper(Edit1->Text[l]))
{
// on active l'affichage
SendMessage(hwndToolTips, TTM_ACTIVATE, true, 0);
// on acquier la position du curseur
GetCursorPos(&cursor);
// on simule un deplacement
SetCursorPos(cursor.x + 1, cursor.y);
}
if(islower(Edit1->Text[l]))
{
// on desactive l'affichage
SendMessage(hwndToolTips, TTM_ACTIVATE, false, 0);
}
}
//--------------------------------------------------------------------------- |
Partager