1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
//This function taken from http://msdn.microsoft.com/en-us/library/windows/desktop/hh298368(v=vs.85).aspx
HWND CreateToolTip(int toolID, HINSTANCE hInst, HWND hDlg, PTSTR pszText) {
if (!toolID || !hDlg || !pszText) {
return FALSE;
}
HWND hwndTool = GetDlgItem(hDlg, toolID);
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
hInst, NULL);
if (!hwndTool || !hwndTip) {
return (HWND)NULL;
}
TOOLINFO toolInfo;
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
return hwndTip;
}
HWND mybutton, tooltip_mess;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nCmd) {
//Well, this code is not important
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
switch (message) {
case WM_CREATE:
mybutton = CreateWindowEx(
WS_EX_CLIENTEDGE,
"BUTTON",
"My Button",
WS_VISIBLE|WS_CHILD,
10, 10, 100, 24,
hWnd,
(HMENU)MY_BUTTON_ID,
hInstance,
NULL);
tooltip_mess = CreateToolTip(TOOLTIP_ID, hInstance, mybutton , (char*)"Tooltip message");
break;
}
}
|