- // Dans vôtre projet ajouter ToolTip.cpp
- // Dans vôtre code principal incluer TooTip.h
- // modifier WM_INITDIALOG
-
- //*****************//
- //Variable Globales//
- //*****************//
-
- ToolTip TT; // Construction du controle nommé TT
-
- //******************//
- // Fichier ToolTip.h//
- //******************//
-
- #ifndef __TOOLTIP_H
- #define __TOOLTIP_H
-
- #include <windows.h>
- #include <commctrl.h>
-
- class ToolTip
- {
- private:
- HWND ToolTipHwnd;
- HWND ParentHwnd;
- HINSTANCE AppHinstance;
- TOOLINFO ToolTipStruct;
- public:
- BOOL TTInit(HWND hWind); //Initialise le controle
- BOOL TTAddTool(LPSTR Text,UINT Control); //Ajout un ToolTip au Controle
- };
- #endif
-
- //********************//
- // Fichier ToolTip.cpp//
- //********************//
-
- #include "ToolTip.h"
-
- BOOL ToolTip::TTInit(HWND hWind) //Initialise le controle
- {
- if (!InitCommonControls)
- {
- return FALSE;
- }
-
- ParentHwnd=hWind;
- AppHinstance=(HINSTANCE)GetWindowLong(hWind,GWL_HINSTANCE);
-
- ToolTipHwnd = CreateWindowEx(0L, TOOLTIPS_CLASS, NULL,
- WS_POPUP,
- CW_USEDEFAULT, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT,
- ParentHwnd, NULL, AppHinstance,
- NULL);
- if (ToolTipHwnd==NULL)
- {
- return FALSE;
- }
-
- if(!SetWindowPos(ToolTipHwnd, HWND_TOPMOST,0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE))
- {
- return FALSE;
- }
- if(!SendMessage(ToolTipHwnd, TTM_ACTIVATE, TRUE, 0L))
- {
- return FALSE;
- }
- return TRUE;
- }
-
- BOOL ToolTip::TTAddTool(LPSTR Text,UINT Control) //Ajout un ToolTip au Controle
- {
- memset(&ToolTipStruct, 0x0, sizeof(ToolTipStruct));
- ToolTipStruct.cbSize = sizeof(ToolTipStruct);
- ToolTipStruct.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
- ToolTipStruct.hwnd = (HWND)GetDlgItem(ParentHwnd, Control);
- ToolTipStruct.uId = (WPARAM)ToolTipStruct.hwnd;
- ToolTipStruct.lpszText = Text;
- ToolTipStruct.hinst = AppHinstance;
-
- if(!SendMessage(ToolTipHwnd, TTM_ADDTOOL, 0, (LPARAM)&ToolTipStruct))
- {
- return FALSE;
- }
- return TRUE;
- }
-
- //******************//
- //Dans WM_INITDIALOG//
- //******************//
-
- TT.TTInit(hwnd); // Initialisation du controle
- TT.TTAddTool("ToolTip1",BUTTON_OK); // Ajout du ToolTip "ToolTip1" au controle (Boutton dans ce cas) BUTTON_OK
// Dans vôtre projet ajouter ToolTip.cpp
// Dans vôtre code principal incluer TooTip.h
// modifier WM_INITDIALOG
//*****************//
//Variable Globales//
//*****************//
ToolTip TT; // Construction du controle nommé TT
//******************//
// Fichier ToolTip.h//
//******************//
#ifndef __TOOLTIP_H
#define __TOOLTIP_H
#include <windows.h>
#include <commctrl.h>
class ToolTip
{
private:
HWND ToolTipHwnd;
HWND ParentHwnd;
HINSTANCE AppHinstance;
TOOLINFO ToolTipStruct;
public:
BOOL TTInit(HWND hWind); //Initialise le controle
BOOL TTAddTool(LPSTR Text,UINT Control); //Ajout un ToolTip au Controle
};
#endif
//********************//
// Fichier ToolTip.cpp//
//********************//
#include "ToolTip.h"
BOOL ToolTip::TTInit(HWND hWind) //Initialise le controle
{
if (!InitCommonControls)
{
return FALSE;
}
ParentHwnd=hWind;
AppHinstance=(HINSTANCE)GetWindowLong(hWind,GWL_HINSTANCE);
ToolTipHwnd = CreateWindowEx(0L, TOOLTIPS_CLASS, NULL,
WS_POPUP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
ParentHwnd, NULL, AppHinstance,
NULL);
if (ToolTipHwnd==NULL)
{
return FALSE;
}
if(!SetWindowPos(ToolTipHwnd, HWND_TOPMOST,0, 0, 0, 0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE))
{
return FALSE;
}
if(!SendMessage(ToolTipHwnd, TTM_ACTIVATE, TRUE, 0L))
{
return FALSE;
}
return TRUE;
}
BOOL ToolTip::TTAddTool(LPSTR Text,UINT Control) //Ajout un ToolTip au Controle
{
memset(&ToolTipStruct, 0x0, sizeof(ToolTipStruct));
ToolTipStruct.cbSize = sizeof(ToolTipStruct);
ToolTipStruct.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
ToolTipStruct.hwnd = (HWND)GetDlgItem(ParentHwnd, Control);
ToolTipStruct.uId = (WPARAM)ToolTipStruct.hwnd;
ToolTipStruct.lpszText = Text;
ToolTipStruct.hinst = AppHinstance;
if(!SendMessage(ToolTipHwnd, TTM_ADDTOOL, 0, (LPARAM)&ToolTipStruct))
{
return FALSE;
}
return TRUE;
}
//******************//
//Dans WM_INITDIALOG//
//******************//
TT.TTInit(hwnd); // Initialisation du controle
TT.TTAddTool("ToolTip1",BUTTON_OK); // Ajout du ToolTip "ToolTip1" au controle (Boutton dans ce cas) BUTTON_OK