win32 - how the ::DrawText() RECT can change the Region size?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: win32 - how the ::DrawText() RECT can change the Region size?

  1. #1
    Join Date
    Apr 2009
    Posts
    933

    win32 - how the ::DrawText() RECT can change the Region size?

    see my DrawText():
    Code:
    void DrawText(string strText, int x=0, int y=0)
        {
            // geting the text rectangle
            RECT r = { 0, 0, 0, 0 };
            char *text=(char*)strText.c_str();
            ::DrawText(HBitmap, text, -1, &r, DT_CALCRECT);
            //change the position of the text
            r.left=x;
            r.top=y;
            //draw the text
            ::DrawText(HBitmap, text, -1,&r,DT_LEFT);
        }
    (i must use the '::' for the API functions, for i use the same name on my code )
    how these function can interfere on window Region shape?
    (if i use these code, i lose 1 or 2 pixel on width and height, on window)

  2. #2
    Join Date
    Apr 2009
    Posts
    933

    Re: win32 - how the ::DrawText() RECT can change the Region size?

    but these code don't:
    Code:
    char *text=(char*)inst->strCaption.c_str();
    
                    RECT b={test.rcPaint.left+2, test.rcPaint.top, test.rcPaint.right-2, test.rcPaint.bottom};
                    DrawTextEx(imglabel,text,-1,&b,DT_LEFT,NULL);
    these confusing me.. can anyone explain to me?

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,261

    Re: win32 - how the ::DrawText() RECT can change the Region size?

    The last two members of RECT are not width and height. When you "change the position of the text" you actually downsize your rect, but not offset the one.
    Last edited by Igor Vartanov; April 5th, 2015 at 03:18 PM.
    Best regards,
    Igor

  4. #4
    Join Date
    Apr 2009
    Posts
    933

    Re: win32 - how the ::DrawText() RECT can change the Region size?

    Quote Originally Posted by Igor Vartanov View Post
    The last two members of RECT are not width and height. When you "change the position of the text" you actually downsize your rect, but not offset the one.
    seems that the only way is draw the image, destroying the region and then create a new region:

    Code:
     void DrawText(string strText,int PosX=0, int PosY=0)
        {
            // geting the text rectangle
            RECT r = { 0, 0, 0, 0 };
            char *text=(char*)strText.c_str();
            ::DrawText(HBitmap, text, -1, &r, DT_CALCRECT);
            //change the position of the text
            r.left=PosX;
            r.top=PosY;
            r.bottom=r.bottom+PosY;
            r.right=r.right+PosX;
            //draw the text
            ::DrawText(HBitmap, text, -1,&r,DT_LEFT);
        }
    how use it:
    Code:
    //draw the image
                        TransparentBlt(test.hdc,0,0,imglabel.width(),imglabel.height(),imglabel,0,0, imglabel.width(),imglabel.height(), inst->clrBackColor);
                        
                        //destroy the region
                        SetWindowRgn(inst->hwnd,NULL,TRUE);
                        
                        //Create and set them region
                        inst->LabelRegion=RegionbyBitmap(imglabel, inst->clrBackColor);
                        SetWindowRgn(inst->hwnd,inst->LabelRegion,TRUE);

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,261

    Re: win32 - how the ::DrawText() RECT can change the Region size?

    I do not see how your DrawText issue relates to the other snippet. I commented the RECT issue which was clearly obvious. In case you prefer not to offset your rect, I believe you should init the one proper way:

    Code:
    RECT rc = { x, y, x, y };
    and DT_CALCRECT will do its job.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!


HTML5 Development Center