To create a tooltip control specify TOOLTIPS_CLASS as the window class and register the class by specifying the ICC_WIN95_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.
#define _WIN32_WINNT 0x0501 #include <windows.h> #include <commctrl.h> #pragma comment(lib,"comctl32.lib") LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HWND hwndTip; HWND hButton; int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASS wc; wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("TooltipClass"); RegisterClass(&wc); CreateWindow( wc.lpszClassName, TEXT("Tooltip Demo"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInstance, NULL); while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { INITCOMMONCONTROLSEX iccex; // Load tooltip common control iccex.dwSize = sizeof(INITCOMMONCONTROLSEX); iccex.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&iccex); // Create button hButton = CreateWindowEx( 0, TEXT("BUTTON"), TEXT("Tooltip test"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 10, 150, 30, hwnd, NULL, NULL, NULL); // Create tooltip window hwndTip = CreateWindowEx( WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, NULL, NULL); // Describe the control that receives tooltip TOOLINFO toolInfo; ZeroMemory( &toolInfo, sizeof(TOOLINFO)); toolInfo.cbSize = sizeof(TOOLINFO); toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; toolInfo.hwnd = hwnd; toolInfo.uId = (UINT_PTR)hButton; toolInfo.lpszText = TEXT("This is a tooltip"); // Attach tooltip to button SendMessage( hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); break; } case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc( hwnd, msg, wParam, lParam); } return 0; }