////////////////////////////////////////////////////////////////////// // Gestion des tooltips a la main ! // // Sylvain Marechal ////////////////////////////////////////////////////////////////////// /*----------------------------------------------------------------------------- ** T O O L T I P . C P P **----------------------------------------------------------------------------- ** DESCRIPTION ** ** Creer un ctrl tooltip (bulle d'aide qui apparait sous la souris qd on ** reflechit ou qu'on dort) ** ** Demarche dans une fenetre hWnd ds laquelle on veut ajouter une bulle d'aide: ** Dans le WM_CREATE : ** // Creation ** hWndTT = CreateTooltipWindow(hWnd); ** AddTooltip( HWND hWndParent, HWND hwndTT ); ** Dans le WM_SIZE ** // Informer du chgt de taille ** SetTooltipInfo( hWnd, hwndTT ); ** Dans WM_LBUTTONDOWN ** WM_LBUTTONUP ** WM_MBUTTONDOWN ** WM_MBUTTONUP ** WM_MOUSEMOVE ** WM_RBUTTONDOWN ** WM_RBUTTONUP ** // Faire suivre les messages souris ** RelayTooltipMouseEvent( hWnd, hwndTT , wParam, lParam ) ** Dans le WM_NOTIFY ** NMHDR FAR *ph = (NMHDR FAR*)lParam ; ** if (ph->code==TTN_NEEDTEXT) ** { ** LPTOOLTIPTEXT pttt = (LPTOOLTIPTEXT)lParam ; ** strcpy( pttt->szText, "le texte a afficher dans le tooltip" ); ** return 0 ; ** } ** ** Rev 09/11/98 **---------------------------------------------------------------------------*/ #include #include #include "tooltip.h" /*----------------------------------------------------------------------------- ** C R E A T E T O O L T I P W I N D O W **----------------------------------------------------------------------------- ** DESCRIPTION ** --CreateTooltipWindow-- ** Creer la fenetre du controle tooltip bulle d'aide ** RETOUR/RESULTAT ** Rev 09/11/98 **---------------------------------------------------------------------------*/ HWND CreateTooltipWindow( HWND hWnd ) { return CreateWindowEx( WS_EX_TOOLWINDOW, // extended window style TOOLTIPS_CLASS, // pointer to registered class name NULL, // pointer to window name WS_POPUP | TTS_ALWAYSTIP, // window style CW_USEDEFAULT, // horizontal position of window CW_USEDEFAULT, // vertical position of window CW_USEDEFAULT, // window width CW_USEDEFAULT, // window height hWnd, // handle to parent or owner window (HMENU)NULL, // handle to menu, or child-window identifier GetModuleHandle(NULL), // handle to application instance NULL // pointer to window-creation data ); } /*----------------------------------------------------------------------------- ** C R E A T E T O O L T I P W I N D O W **----------------------------------------------------------------------------- ** DESCRIPTION ** --AddTooltip-- ** ** Ajouter le ctrl tooltip : En gros, ce ctrl enverra des message WM_NOTIFY ** a la fenetre hWndParent chaque fois qu'il faudra afficher la bulle d'aide ** ceci grace a LPSTR_TEXTCALLBACK. ** ** Si on veut que ca marche, faudra pas oublier de faire passer les messages ** souris au ctrl ** ** RETOUR/RESULTAT ** Rev 09/11/98 **---------------------------------------------------------------------------*/ BOOL AddTooltip( HWND hWndParent, HWND hwndTT ) { TOOLINFO ti; // tool information ti.cbSize = sizeof(TOOLINFO); ti.uFlags = 0; ti.hwnd = hWndParent; ti.hinst = GetModuleHandle(NULL); ti.uId = (UINT) 0; ti.lpszText = LPSTR_TEXTCALLBACK;//(LPSTR) ach; return SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); } /*----------------------------------------------------------------------------- ** S E T T O O L T I P I N F O **----------------------------------------------------------------------------- ** DESCRIPTION ** --SetTooltipInfo-- ** Informer le tooltip que la taille de la fenetre a change ** RETOUR/RESULTAT ** Rev 09/11/98 **---------------------------------------------------------------------------*/ void SetTooltipInfo( HWND hWndParent, HWND hwndTT ) { RECT rect; GetClientRect( hWndParent, &rect ); TOOLINFO ti; // tool information ti.cbSize = sizeof(TOOLINFO); ti.uFlags = 0; ti.hwnd = hWndParent; ti.hinst = GetModuleHandle(NULL); ti.uId = (UINT) 0; ti.lpszText = LPSTR_TEXTCALLBACK; ti.rect = rect; SendMessage(hwndTT, TTM_SETTOOLINFO , 0, (LPARAM) (LPTOOLINFO) &ti); } /*----------------------------------------------------------------------------- ** S E T T O O L T I P I N F O **----------------------------------------------------------------------------- ** DESCRIPTION ** --RelayTooltipMouseEvent-- ** Faire suivre les messages souris . Si on fait pas ca, ca marche pas ** RETOUR/RESULTAT ** Rev 09/11/98 **---------------------------------------------------------------------------*/ void RelayTooltipMouseEvent( HWND hWndParent, HWND hwndTT , UINT Msg, WPARAM wParam, LPARAM lParam ) { MSG message ; message.hwnd = hWndParent; message.message = Msg; message.wParam = wParam; message.lParam = lParam; message.time = GetTickCount(); message.pt.x = LOWORD(lParam); // horizontal position of cursor message.pt.y = HIWORD(lParam); // vertical position of cursor ClientToScreen( hWndParent, &message.pt ); // Faire suivre les messages souris a la fenetre tooltip (bulle d'aide) SendMessage( hwndTT , TTM_RELAYEVENT, 0, (LPARAM) (LPMSG) &message ); }