Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add tooltips to individual grid cells in a dialog
#1
Hello again,

We know how to attach a tooltip to a control, but how to add tooltips to individual grid cells in a dialog?

I would greatly appreciate any help.
#2
I would show tooltips on LVN_GETINFOTIP message.

This code is in C++, copied from one of my projects.

Code:
Copy      Help
    case LVN_GETINFOTIPW: {
        NMLVGETINFOTIPW& it=*(NMLVGETINFOTIPW*)nh;
        i=it.iItem; if(i<0 || i>=_nr) break;
        text=_GetTooltipText(i);
        if(empty(text)) _TooltipHide();
        else _TooltipShow(text, i);

//__________________________________________________________________

//Shows tooltip at x y relative to _hlv.
void QmDropdown::_TooltipShow(LPCSTR text, int i)
{
    TOOLINFOW ti; ZERO(ti); ti.cbSize=44;
    ti.uFlags=TTF_TRACK;
    ti.lpszText=Wstr(text);

    if(!_htooltip) {
        DWORD st=TTS_NOPREFIX|TTS_ALWAYSTIP|WS_POPUP|TTS_BALLOON;
        _htooltip=CreateWindowExW(WS_EX_TOPMOST|WS_EX_TOOLWINDOW, L"tooltips_class32", 0, st, 0, 0, 0, 0, 0, 0, 0, 0);
        SENDQ(_htooltip, TTM_SETMAXTIPWIDTH, 0, 500); //enable multiline
        SENDQ(_htooltip, TTM_ADDTOOLW, 0, &ti);
    }
    else SENDQ(_htooltip, TTM_UPDATETIPTEXTW, 0, &ti);

    RECT ri={}; _LvSend(LVM_GETITEMRECT, i, (LPARAM)&ri);
    POINT p={ri.right, (ri.top+ri.bottom)/2}; ClientToScreen(_hlv, &p);
    SENDQ(_htooltip, TTM_TRACKPOSITION, 0, MAKELONG(p.x, p.y));
    SENDQ(_htooltip, TTM_TRACKACTIVATE, 1, &ti);
    _isTooltip=1;
}
//__________________________________________________________________

void QmDropdown::_TooltipHide(bool destroy)
{
    if(!_htooltip) return;
    if(_isTooltip) {
        _isTooltip=0;
        TOOLINFOW ti; ZERO(ti); ti.cbSize=44;
        SENDQ(_htooltip, TTM_TRACKACTIVATE, 0, &ti);
    }
    if(destroy) { DestroyWindow(_htooltip); _htooltip=0; }
}

    long _LvSend(UINT message, WPARAM wParam=0, LPARAM lParam=0) { return SendMessageW(_hlv, message, wParam, lParam); }
#3
Thanks for your help. I have solved my question with some tricks.

It will be nice to see your posted code in a new QM version... :wink:

Macro Macro1488
Code:
Copy      Help
;(...)

,case WM_INITDIALOG
,SetTimer hDlg 1 1000 0

;(...)

,case WM_TIMER
,int cid=id(3 hDlg)
,POINT p; xm(p cid 1) ;;get mouse position into p.x and p.y
,,;out "%i %i %i %i" xm ym p.x p.y
,if p.x>5 and p.x<699 and p.y>24 and p.y<103
,,;out "[]%i %i" p.x p.y
,,int x=p.x/100
,,int y=(p.y-24)/16
,,str s1=g_c.Cell(y x)
,,ShowTooltip s1 1 xm ym-20


Forum Jump:


Users browsing this thread: 1 Guest(s)