Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tooltip in winapi

162 views
Skip to first unread message

tran tuan

unread,
Jul 8, 2015, 6:04:09 AM7/8/15
to
I have tried use tooltip in winapi and it's worked BUT i want to set position with a control specified. The tooltip is baloon. This is my code, it can help the tooltip alway appear and can set position of the tooltip in screen BUT not set position with a control specified.
I want to set position of the tooltip with a control specified eg: above, bellow, left or right of the control like my image: the tooltip is left of control edit: https://drive.google.com/file/d/0B07GVLo1Mf_bRmx0MGwyaU5jdEU/view?usp=sharing
I have read https://msdn.microsoft.com/en-us/library/windows/desktop/hh298402(v=vs.85).aspx but it's not help! So, how to i can set position the tooltip? Can you give me example code? Thanks!
This my code:
void CreateTooltip (HWND hwnd, TCHAR *tip, HWND &hwndToolTip, TOOLINFO &tootip, bool iShow, int nX, int nY)
{
// struct specifying control classes to register
INITCOMMONCONTROLSEX iccex;
HWND hwndTT; // handle to the ToolTip control
// struct specifying info about tool in ToolTip control

unsigned int uid = 0; // for ti initialization
wchar_t strTT[30] = L"This is your ToolTip string.";
LPTSTR lptstr = strTT;
RECT rect; // for client area coordinates

/* INITIALIZE COMMON CONTROLS */
iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);

/* CREATE A TOOLTIP WINDOW */
hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP |TTS_BALLOON,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hwnd,
NULL,
hInst_Tooltip,
NULL
);
if (hwndTT==NULL)
{
MessageBox(NULL,L"Couldn't create the ToolTip control.",L"Error",MB_OK);
}
SetWindowPos(hwndTT,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

/* GET COORDINATES OF THE MAIN CLIENT AREA */
GetClientRect (hwnd, &rect);
TOOLINFO ti;
/* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
//ti.cbSize = sizeof(TOOLINFO);
ti.cbSize = TTTOOLINFOW_V2_SIZE;//set size nhu vay moi chay dc project unicode
//ti.uFlags = TTF_SUBCLASS;
//ti.uFlags = TTF_CENTERTIP;
//ti.uFlags = TTF_SUBCLASS;
ti.uFlags = TTF_TRACK|TTF_ABSOLUTE;
ti.hwnd = hwnd;
ti.hinst = hInst_Tooltip;
ti.uId = uid;
ti.lpszText = tip;
// ToolTip control will cover the whole window
ti.rect.left = rect.left;
ti.rect.top = rect.top;
ti.rect.right = rect.right;
ti.rect.bottom = rect.bottom;

hwndToolTip = hwndTT;
tootip = ti;

/* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
if(!SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti))
{
MessageBox(NULL,L"Couldn't create the ToolTip control.",L"Error",MB_OK);
}
//SendMessage(hwndTT, TTM_SETMARGIN,0, (LPARAM)&rectSetMargin);

//SendMessage(hwndTT, TTM_TRACKACTIVATE, iShow, (LPARAM)(LPTOOLINFO) &ti);

SendMessage(hwndTT, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(nX, nY));
SendMessage(hwndTT, TTM_TRACKACTIVATE, iShow, (LPARAM)(LPTOOLINFO) &ti);
}

Christian Astor

unread,
Jul 8, 2015, 7:59:04 AM7/8/15
to
tran tuan a écrit :
> I have tried use tooltip in winapi and it's worked BUT i want to set position with a control specified. The tooltip is baloon.
This is my code, it can help the tooltip alway appear and can set
position of the tooltip in screen BUT not set position with a control
specified.
> I want to set position of the tooltip with a control specified eg: above, bellow, left or right of the control like my image:
the tooltip is left of control edit:
https://drive.google.com/file/d/0B07GVLo1Mf_bRmx0MGwyaU5jdEU/view?usp=sharing

The standard way to position Tooltips is in the TTN_SHOW notification.

Christian Astor

unread,
Jul 8, 2015, 8:43:51 AM7/8/15
to
tran tuan a écrit :

> I want to set position of the tooltip with a control specified eg: above, bellow, left or right of the control

As MSDN says, use SetWindowPos() in TTN_SHOW notification of the Tool
window.
0 new messages