2010-12-03 14 views
5

¿Es posible hacer una información sobre herramientas amarilla en windows multiline?Windows yellow tooltip multiline?

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

he intentado con \n pero no está funcionando.

EDIT:

Ésta es la función que tengo en mi código. Seguí instrucciones de MSDN pero no pude hacerlo funcionar (mira el comentario: // 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); 
} 

Gracias,
Ilija

Respuesta

0

Windows utiliza \r\n para saltos de línea. Pruébalo, debería funcionar. Ver MSDN.

+0

¿Por qué? Quien downvoted, ¿realmente has probado esto? – ybungalobill

+0

No funciona ... En el enlace que enviaste funciona si utilizaste previamente TTM_SETMAXTIPWIDTH ... pero para mí nada funciona ... btw, -1 no es mío :) –

7

Hay 3 tipos de información sobre herramientas. Su captura de pantalla muestra una información sobre herramientas de seguimiento. Luego hay una información sobre herramientas multilínea, envíe TTM_SETMAXTIPWIDTH y responda a TTN_GETDISPINFO. Y hay globo información sobre herramientas, especifique el indicador de estilo de ventana TTS_BALLOON. Los dos últimos se ajustan a tu factura.

Hay buenos ejemplos de código en el SDK article para ellos.

+0

Hans, gracias por la respuesta. Seguí las instrucciones del enlace pero no pude hacerlo funcionar. No soy un usuario experimentado de C++, así que estoy teniendo problemas para entender esto. Edité mi pregunta y el código pegado de la función actual que se supone que debo cambiar. ¿Podrían verificar lo que estaba haciendo mal? ¡¡Gracias!! –

+1

Intenta usar 'SendMessage (..., TTM_SETMAXTIPWIDTH, 0, MAXINT);'. – wj32

+0

tal vez el primer parámetro en 'SendMessage' es incorrecto? –

0

He encontrado que \ n funciona para información general sobre herramientas, pero ni \ n ni \ r \ n funcionan para la información sobre herramientas de globo. No estoy usando Unicode.

1

Puede forzar el control sobre herramientas estándar de hacer de varias líneas utilizando el siguiente truco:

En el controlador de TTN_NEEDTEXT:

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

En cualquier caso, por establecer el ancho, entonces yo soy capaz de dibujar muiltiline consejos:

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

Donde kToolTipWidth es un ancho máximo útil, digamos 600-800.

Extrañamente, tengo que volver a enviar este mensaje en el controlador TTN_NEEDTEXT, y no solo en decir creación de ventana. Esto es cierto para nuestra aplicación MFC, donde MFC utiliza un control de sugerencia de herramienta global por subproceso, que probablemente se restablece a los valores predeterminados cada vez que se crea un nuevo cuadro de diálogo. Entonces, es posible que para una aplicación que no sea MFC, pueda inicializarlo solo una vez.

¡Disfrútalo!