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
|
void setParent(HWND parent=WindowMain)
{
if (hwnd==NULL)
{
WNDCLASS tooltipclass;
HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
ZeroMemory(&tooltipclass, sizeof(WNDCLASS));
GetClassInfo(mod, TEXT("BUTTON"), &tooltipclass);
tooltipclass.hInstance = mod;
tooltipclass.lpszClassName = TEXT("tooltip");
tooltipclass.style=CS_DBLCLKS;
// store the old WNDPROC of the button window class
SetProp(parent, tooltippropname, (HANDLE)tooltipclass.lpfnWndProc);
// replace it with local WNDPROC
tooltipclass.lpfnWndProc = WndProcToolTip;
tooltipclass.hbrBackground = (HBRUSH) GetStockBrush(NULL_BRUSH);
// register the new window class"
RegisterClass(&tooltipclass);
RECT textrect={0};
HDC txthdc=GetDC(hwnd);
DrawText (txthdc,strCaption.c_str(),strCaption.size(),&textrect,DT_CALCRECT | DT_LEFT);
//size correct
hwnd = CreateWindowEx( 0, TEXT("tooltip"), strCaption.c_str(),
BS_OWNERDRAW |WS_TABSTOP| BS_NOTIFY | WS_CHILD | WS_CLIPSIBLINGS,
CW_USEDEFAULT, CW_USEDEFAULT, textrect.right-textrect.left, textrect.bottom-textrect.top,
parent, 0, mod, this);
if (hwnd == NULL)
MessageBox(NULL, "Can't create the control", "error", MB_OK);
if (SetProp(hwnd, tooltipclassprop, (HANDLE)this) == 0)
MessageBox(NULL, "can't set the class property", "error", MB_OK);
}
else
{
SetParent(hwnd,parent);
}
}
|