how can i do the control autosize?
i think in these way:
1 - get the text rect:

RECT textrect;
                int a=DrawText (test->hDC,inst->strCaption.c_str(),-1,&textrect,DT_CALCRECT);

(the a isn't zero)

2 - testing the rectangle with image size:

if(textrect.bottom<inst->imgtest.height())
                    inst->intHeight=inst->imgtest.height();
                if(textrect.right<inst->imgtest.width())
                    inst->intWidth=inst->imgtest.width();

3 - change the control size:

SetWindowPos(inst->hwnd, 0, 0, 0, inst->intWidth, inst->intHeight,
                    SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOCOPYBITS);

so why the control size isn't changed? did i forget something?

//Set Picture box and button relative to main window dialog

CRect rect_dialog; this->GetWindowRect(rect_dialog);

picture_box.SetWindowPos(NULL, 0, 0, rect_dialog.right - 400, rect_dialog.bottom - 100, SWP_NOMOVE);

buton_1.SetWindowPos(NULL, rect_dialog.right - 200, 50, 0, 0, SWP_NOSIZE);

sorry i don't use MFC.
i found some problems with debugging:

RECT textrect{0};
                    int a=DrawText (test->hDC,inst->strCaption.c_str(),-1,&textrect,DT_CALCRECT);
                    int intwidth=0;
                    int intheight=0;
                    if (a==0)
                        MessageBox(NULL,"error","erro", MB_OK);
                    if(textrect.bottom<inst->imgtest.height())
                        intheight=inst->imgtest.height();
                    else
                        intheight=textrect.bottom;
                    if(textrect.right>inst->imgtest.width())
                        intwidth=inst->imgtest.width();
                    else
                        intwidth=textrect.right;

the textrect isn't recive, sometimes, correct values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.