win32- how can i get the string rectangle for resize the control?

how can i get the string rectangle?
i did with DrawText() with DT_CALRECT, but when the string is changed, the control size isn't correct :(
can anyone advice me?
I think you need to provide a bit more information.

OK, you calculated the size of the rectangle. (And use it to initialized the control?)

The when the string changed, the control size was no longer correct. (Did you recalculate the rectangle and resize the control?)

Andy
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);
        }
    }


when i show the control:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void show()
    {
        //Getting mouse cursor coordenates
        POINT a;
        GetCursorPos(&a);
        ScreenToClient(GetParent(hwnd),&a);


        //Getting mouse cursor size
        ICONINFO ii;
        GetIconInfo(GetCursor(), &ii);
        BITMAP bm;
        GetObject( ii.hbmColor, sizeof( bm ), &bm );
        //bm.bmHeight = ii.hbmMask ? bm.bmHeight : bm.bmHeight / 2;
        //Show the ToolTip
        blnvisible=true;
        HTHEME hTheme = OpenThemeData(hwnd, L"TOOLTIP");

        RECT textrect={0};
        HDC txthdc=GetDC(hwnd);
        GetThemeTextExtent(hTheme,txthdc,TTP_STANDARD , TTSS_NORMAL,towstring(strCaption).c_str(),strCaption.size(),DT_CALCRECT,NULL, &textrect);
        CloseThemeData(hTheme);
        SetWindowPos(hwnd, HWND_TOP, a.x, a.y+bm.bmHeight/2+3, textrect.right, textrect.bottom, SWP_SHOWWINDOW);
    }

(ok.. i forget delete the DC object)
but what i'm doing wrong, when i show the control?
but what i'm doing wrong, when i show the control?

Does the text extent you're passing to SetWindowPos() in your show() function look right?

Andy

PS I am a bit confused as I thought you were using an actual tooltip (class tooltips_class32) but you're code shows you're making your own tooltip out of a button. Out of interest, why aren't you using the standard tooltips functionality?
andy i get the same problem with DrawText() function :(

i don't use the class tooltips_class32 because i get problems with Region functions :(

see the print screen:

https://onedrive.live.com/?id=C3EF456E15C8DEB6!1282&cid=C3EF456E15C8DEB6&group=0&parId=C3EF456E15C8DEB6!197&o=OneUp
after some information and several tests i found the problem..
my problem was with my region function.. the backcolor was the problem :(
but please correct me on these thing:

1 - child control have the WS_CLIPSIBLINGS;

2 - the hbrBackground is (HBRUSH) GetStockBrush(NULL_BRUSH) ;

3 - the WM_ERASEBKGND returns TRUE;

4 - i use memory DC on WM_PAINT;

5 - i draw the memory DC to child control, using the TransparentBlt() ;

6 - i return 0 on WM_PAINT.

doing these the control will be transparent right?
Topic archived. No new replies allowed.