Toolbar et Tooltip

cs_trif Messages postés 5 Date d'inscription lundi 3 mars 2003 Statut Membre Dernière intervention 11 juin 2003 - 31 mars 2003 à 13:47
cs_Kikx Messages postés 12 Date d'inscription vendredi 24 décembre 2004 Statut Membre Dernière intervention 11 janvier 2005 - 17 janv. 2005 à 12:02
Bonjour, j'ai creer une toolbar de la facon suivante, et j'aimerai creer des tooltips pour les boutons de cette toolbar
Comment faire?
HWND CreateToolBar(HWND hWnd, HINSTANCE hInst)
{
HIMAGELIST hImglBtn;//, hImglBtnHot; // Toolbar images handlers
TBBUTTON tbb[5]; // Button struct for tool bar
static HWND hWndTB; // Toolbar window handler
HBITMAP hBtn; // bitmaps handle

// begin ToolBar window creation
hWndTB = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | TBSTYLE_TOOLTIPS | TBSTYLE_AUTOSIZE, 0, 0, 0, 0,
hWnd, (HMENU)ID_TOOLBAR, GetModuleHandle(NULL), NULL);

/*hWndTB = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | WS_VISIBLE , 0, 0, 0, 0,
hWnd, (HMENU)ID_TOOLBAR, hInst, NULL);*/

// create image List
hImglBtn = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK , 4, 1);
hBtn = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(IDR_TOOLBAR1), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
// use transperacy
ImageList_AddMasked(hImglBtn, hBtn, RGB(255, 255, 255));
DeleteObject(hBtn); // Kill image object

// create image List Hot Bar
/*hImglBtnHot = ImageList_Create(24, 22, ILC_COLOR32 | ILC_MASK , 4, 1);
hBtn = (HBITMAP)LoadImage(hInst, MAKEINTRESOURCE(IDB_TOOLBARHOT), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
// use transperacy
ImageList_AddMasked(hImglBtnHot, hBtn, RGB(255, 0, 255));
DeleteObject(hBtn); // Kill image object*/

// Attach the image lists to the window handler
SendMessage(hWndTB, TB_SETIMAGELIST, (WPARAM)0, (WPARAM)hImglBtn);
//SendMessage(hWndTB, TB_SETHOTIMAGELIST, (WPARAM)0, (WPARAM)hImglBtnHot);

// button 1 properties
tbb[0].iBitmap = 0; // Array of picture to show
tbb[0].idCommand = 0;
tbb[0].fsState = TBSTATE_ENABLED; // button status
tbb[0].fsStyle = TBSTYLE_BUTTON; // button style
tbb[0].dwData = 0;
tbb[0].iString = 0;
tbb[0].idCommand=ID_FICHIER_OUVRIR; // button identifier

// button 2 properties
tbb[1].iBitmap = 1;
tbb[1].idCommand = 0;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0;
tbb[1].iString = 0;
tbb[1].idCommand=ID_FICHIER_ENREGISTRERSOUS;

// seperator properties
tbb[2].iBitmap = 0;
tbb[2].idCommand = 0;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_SEP;
tbb[2].dwData = 0;
tbb[2].iString = 0;

// button 4 properties
tbb[3].iBitmap = 2;
tbb[3].idCommand = 0;
tbb[3].fsState = TBSTATE_ENABLED;
tbb[3].fsStyle = TBSTYLE_BUTTON;
tbb[3].dwData = 0;
tbb[3].iString = 0;
tbb[3].idCommand=ID_FICHIER_QUITTER;

// button 5 properties
tbb[4].iBitmap = 3;
tbb[4].idCommand = 0;
tbb[4].fsState = TBSTATE_ENABLED;
tbb[4].fsStyle = TBSTYLE_BUTTON;
tbb[4].dwData = 0;
tbb[4].iString = 0;
tbb[4].idCommand=ID__APROPOS;

// Add the buttons
SendMessage(hWndTB, TB_ADDBUTTONS, (WPARAM)5, (LPARAM)(LPTBBUTTON)&tbb); // add buttons
// Auto Disable buttons on startup
/*SendMessage(hWndTB, TB_ENABLEBUTTON, IDC_PE_EDITOR, (LPARAM)FALSE); // Disable Buttons
SendMessage(hWndTB, TB_ENABLEBUTTON, IDC_SAVE_DISASM, (LPARAM)FALSE); // at first run*/

// Kill image object
DeleteObject(hBtn);

// Return tool bar window handler
return hWndTB;
}

4 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
31 mars 2003 à 14:45
J'ai fait un copier depuis un exemple que j'ai fait pour un autre. Te suffit adapter les idc_xxx. Tu recup WM_NOTIFY dans ta wndProc(), ici je ne verifie pas qui arrive car un seul emetteur possible, si tu as plusieurs controles pouvant emettre WM_NOTIFY alors regarde le hwndFrom.

case WM_NOTIFY:
switch (((LPNMHDR) lParam)->code) {
case TTN_NEEDTEXT:
LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam;
switch(lpttt->hdr.idFrom) {
case IDC_TOOL_NEWCATEG:
lpttt->lpszText = "Crée nouvelle catégorie"; break;
case IDC_TOOL_DELCATEG:
lpttt->lpszText = "Supprime catégorie courante"; break;
case IDC_TOOL_NEWURL:
lpttt->lpszText = "Crée nouveau lien"; break;
case IDC_TOOL_DELURL:
lpttt->lpszText = "Supprime lien sélectionné"; break;
case IDC_TOOL_F1:
lpttt->lpszText = "Aide du logiciel"; break;
case IDC_TOOL_ABOUT:
lpttt->lpszText = "A propos de..."; break;
case IDC_TOOL_QUIT:
lpttt->lpszText = "Fermeture logiciel"; break;
}
}
return 0;
BruNews, ciao...
0
superpa Messages postés 113 Date d'inscription lundi 24 février 2003 Statut Membre Dernière intervention 5 janvier 2004
31 mars 2003 à 14:52
On a beau critiquer MFC, c'est quand même plus simple à utiliser pour les bulles d'aides et pour la barre d'outils...

A bientôt,
P-A
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
31 mars 2003 à 15:12
oui sans mfc, SEMBLE + difficile, mais a la finale c'est faux. Quand on sait faire, alors tout est permis, ce qui n'est pas le cas de mfc ou il faudra appeler API native pour faire ce qui n'est pas fourni. Resultat mfc + API a apprendre. 1 seule me suffit.
BruNews, ciao...
0
cs_Kikx Messages postés 12 Date d'inscription vendredi 24 décembre 2004 Statut Membre Dernière intervention 11 janvier 2005
17 janv. 2005 à 12:02
Merci ce bou de code m'aide bien

Kikx
0
Rejoignez-nous