2010-12-03 35 views
5

Est-il possible de créer une info-bulle jaune dans Windows multiline?Windows tooltip jaune multiligne?

http://img830.imageshack.us/img830/6117/tooltip.gif

J'ai essayé avec \n mais il ne fonctionne pas.

EDIT:

Ceci est la fonction que j'ai dans mon code. J'ai suivi les instructions de MSDN mais je n'ai pas réussi à le faire fonctionner (regardez le commentaire: // Multiline tooltip).

void CreateToolTipForRect(HWND hwndParent) 
{ 
    if (!bCanCreateToolTips) 
     return; 
    // Get list of areas we want tooltips on 
    NSUI::TButton* tbt; 
    tbt = gUserInterface->buttonList; 

    HWND hwndTT; 

    // Array to store all tooltip texts 
    static char string[100][ RM_SCROLLTEXT_MAXLEN + 2 ]; 

    // Go through the list 
    while (tbt != NULL) 
    { 
     // Check id there is a tooltip text defined for this area 
     int sid = GetResourceIdFromButtonId(tbt->id); 
     if (sid == -1) 
     { 
      tbt = tbt->next; 
      continue; 
     } 

     if (!ttwnd[tbt->id]) 
     { 
      // Create a ToolTip. 
      hwndTT = CreateWindowEx(WS_EX_TOPMOST, 
       TOOLTIPS_CLASS, NULL, 
       WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,      
       CW_USEDEFAULT, CW_USEDEFAULT, 
       CW_USEDEFAULT, CW_USEDEFAULT, 
       hwndParent, NULL, ((QunicApp *)CQMainGetApp())->CQWinApp_GetHInst(),NULL); 

      ttwnd[tbt->id] = hwndTT; 

      SetWindowPos(hwndTT, HWND_TOPMOST, 
       0, 0, 0, 0, 
       SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 
      // Get tooltip from resources 
      int res = LoadString(((QunicApp *)CQMainGetApp())->CQWinApp_GetHInst(), sid, string[tbt->id], RM_SCROLLTEXT_MAXLEN); 
     } 
     // Set up "tool" information. 
     TOOLINFO ti = { 0 }; 
     ti.cbSize = sizeof(TOOLINFO); 
     ti.uFlags = TTF_SUBCLASS; 
     ti.hwnd = hwndParent; 
     ti.hinst = ((QunicApp *)CQMainGetApp())->CQWinApp_GetHInst(); 

     ti.lpszText = string[tbt->id]; 

     // Set area 
     ti.rect.left = tbt->tx; 
     ti.rect.right = tbt->bx; 
     ti.rect.top = tbt->ty; 
     ti.rect.bottom = tbt->by; 

     // Associate the ToolTip with the "tool" window. 
     SendMessage(ttwnd[tbt->id], TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); 

     // Multiline tooltip - Ilija tried with this 
     /*LPNMTTDISPINFO pInfo = (LPNMTTDISPINFO)tbt; 
     SendMessage(pInfo->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, 0, 150);*/ 

     tbt = tbt->next; 
    } 
    // Extra one, area or button is not known yet 
    // Create a ToolTip. 
    hwndTT = CreateWindowEx(WS_EX_TOPMOST, 
     TOOLTIPS_CLASS, NULL, 
     WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,      
     CW_USEDEFAULT, CW_USEDEFAULT, 
     CW_USEDEFAULT, CW_USEDEFAULT, 
     hwndParent, NULL, ((QunicApp *)CQMainGetApp())->CQWinApp_GetHInst(),NULL); 

    SetWindowPos(hwndTT, HWND_TOPMOST, 
     0, 0, 0, 0, 
     SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); 

    // Set up "tool" information. 
    TOOLINFO ti = { 0 }; 
    ti.cbSize = sizeof(TOOLINFO); 
    ti.uFlags = TTF_SUBCLASS; 
    ti.hwnd = hwndParent; 
    ti.hinst = ((QunicApp *)CQMainGetApp())->CQWinApp_GetHInst(); 

    // Get tooltip from resources 
    int res = LoadString(ti.hinst, IDS_PREVIEW, string[99], RM_SCROLLTEXT_MAXLEN); 

    ti.lpszText = string[99]; 

    // Set area 
    ti.rect.left = 7; 
    ti.rect.right = 104; 
    ti.rect.top = 131; 
    ti.rect.bottom = 145; 

    // Associate the ToolTip with the "tool" window. 
    SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); 
} 

Merci,
Ilija

Répondre

0

Windows utilise pour \r\n sauts de ligne. Essayez-le à la place, cela devrait fonctionner. Voir MSDN.

+0

Pourquoi -1? Celui qui a downvoted, avez-vous vraiment essayé cela? – ybungalobill

+0

Cela ne fonctionne pas ... Dans le lien que vous avez envoyé cela fonctionne si vous avez déjà utilisé TTM_SETMAXTIPWIDTH ... mais pour moi rien ne fonctionne ... btw, -1 n'est pas à moi :) –

7

Il existe 3 types d'info-bulles. Votre capture d'écran montre une info-bulle de suivi. Ensuite, il y a une info-bulle multiligne, envoyez TTM_SETMAXTIPWIDTH et répondez à TTN_GETDISPINFO. Et il y a des infobulles de ballon, spécifiez l'indicateur de style de fenêtre TTS_BALLOON. Les deux derniers correspondent à votre facture.

Il existe de bons exemples de code dans le SDK article pour eux.

+0

Hans, merci pour la réponse. J'ai suivi les instructions du lien mais je n'ai pas réussi à le faire fonctionner. Je ne suis pas un utilisateur C++ expérimenté donc j'ai de la difficulté à comprendre cela. J'ai édité ma question et j'ai collé le code de la fonction actuelle que je suis supposé changer. Pourriez-vous vérifier ce que je faisais de mal? Merci!! –

+1

Essayez d'utiliser 'SendMessage (..., TTM_SETMAXTIPWIDTH, 0, MAXINT);'. – wj32

+0

peut-être le premier paramètre dans 'SendMessage' est faux? –

0

J'ai trouvé que \ n fonctionne pour les info-bulles normales, mais ni \ n ni \ n \ n ne fonctionne pour les infobulles de ballon. Je n'utilise pas Unicode.

1

Vous pouvez forcer le contrôle standard infobulle faire multiligne en utilisant l'astuce suivante:

Dans votre gestionnaire TTN_NEEDTEXT:

// force multi-line tool tips 
::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, kToolTipWidth); 

Quelle que soit, en réglant la largeur, alors je suis en mesure de tirer muiltiline conseils:

pToolTipText->lpszText = _T("blah blah blah\r\nmore blah blah\r\nline 3 of blah"); 

Où kToolTipWidth est une largeur maximale utile, par exemple 600-800. Etrangement, je dois réémettre ce message dans le gestionnaire TTN_NEEDTEXT, et pas seulement lors de la création de la fenêtre, par exemple. Cela est vrai pour notre application MFC, où MFC utilise un contrôle d'infobulle global par thread, qui est probablement réinitialisé aux valeurs par défaut chaque fois qu'une nouvelle boîte de dialogue est créée. Il est donc possible que pour une application non MFC, vous puissiez l'initialiser une seule fois.

Profitez-en!