CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 39
  1. #16
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    finally i found 1 solution(doublebuffering for avoid flickers and others):
    (these code is in my label window procedure)
    Code:
    case WM_ERASEBKGND:
                {               
                    HDC mdc = CreateCompatibleDC(NULL);//creating the doublebuffer
                    Size a=inst->GetSize();//get the control size
                    Position b=inst->GetPosition();//get ocntrol position
                    HBITMAP mbmp =  CreateBitmap(a.Width,a.Height,1,24,NULL); //create the bimap with a size
                    HBITMAP moldbmp = (HBITMAP)SelectObject(mdc,mbmp);//select the DC from that bitmap
                    HDC labeldc=GetDC(inst->hwnd);//get the label DC
                    BitBlt(mdc,0,0,a.Width,a.Height,GetDC(GetParent(inst->hwnd)),b.X, b.Y,SRCCOPY);//copy the parent control 
                    TransparentBlt(mdc,0,0,a.Width,a.Height,labeldc,0,0,a.Width,a.Height,(UINT)inst->clrBackColor);//copy the label DC to mdc(double buffer), without backcolor
                    BitBlt(GetDC(inst->hwnd),0,0,a.Width,a.Height,mdc,b.X, b.Y,SRCCOPY);//now copy the double buffer to label dc
                    //clean objects
                    SelectObject(mdc,moldbmp);
                    DeleteObject(mbmp);
                    DeleteDC(mdc);
                }
    but i get these strange error on TransparenBlt():
    "obj\Debug\main.o||In function `ZN5label7WndProcEP6HWND__jjl@16':"
    "undefined reference to `_imp__TransparentBlt@44'"

    the clrBackColor it's a COLORREF type.
    isn't the 1st time that i get these strange error, can you please give me more information?

  2. #17
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - transparent and opacy

    Quote Originally Posted by Cambalinho View Post
    finally i found 1 solution(doublebuffering for avoid flickers and others):
    (these code is in my label window procedure)
    ...
    but i get these strange error on TransparenBlt():
    ...
    It means you did NOT find a solution yet!

    Quote Originally Posted by Cambalinho View Post
    get these strange error on TransparenBlt():
    "obj\Debug\main.o||In function `ZN5label7WndProcEP6HWND__jjl@16':"
    "undefined reference to `_imp__TransparentBlt@44'"
    the clrBackColor it's a COLORREF type.
    isn't the 1st time that i get these strange error, can you please give me more information?
    It is a Linker error. Some .lib or .obj file containing TransparenBlt was not included (nor added) in your project.

    Didn't you read the MSDN documentation about TransparenBlt ?
    Didn't you add the Msimg32.lib library?
    Victor Nijegorodov

  3. #18
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by VictorN View Post
    It means you did NOT find a solution yet!

    It is a Linker error. Some .lib or .obj file containing TransparenBlt was not included (nor added) in your project.

    Didn't you read the MSDN documentation about TransparenBlt ?
    Didn't you add the Msimg32.lib library?
    you have right... i never thot that... thanks
    and yes the code seems not working
    maybe i will do it in other time
    Last edited by Cambalinho; January 3rd, 2014 at 05:09 PM.

  4. #19
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    finally i found 1 solution(doublebuffering for avoid flickers and others):
    (these code is in my label window procedure)
    I hope the version of this case code you use has a break statement at the end.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #20
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    I hope the version of this case code you use has a break statement at the end.
    yes.. it have

  6. #21
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    see the 2 cases:
    Code:
    case WM_ERASEBKGND:
                {
                    if (inst->blnTransparent==true)
                    {
                        HDC mdc = CreateCompatibleDC(NULL);//creating the doublebuffer
                        Size a=inst->GetSize();//get the control size
                        Position b=inst->GetPosition();//get ocntrol position
                        HBITMAP mbmp =  CreateBitmap(a.Width,a.Height,1,24,NULL); //create the bimap with a size
                        HBITMAP moldbmp = (HBITMAP)SelectObject(mdc,mbmp);//select the DC from that bitmap
                        HDC labeldc=GetDC(inst->hwnd);//get the label DC
                        BitBlt(mdc,0,0,a.Width,a.Height,GetDC(GetParent(inst->hwnd)),b.X, b.Y,SRCCOPY);//copy the parent control
                        TransparentBlt(mdc,0,0,a.Width,a.Height,labeldc,0,0,a.Width,a.Height,(UINT)inst->clrBackColor);//copy the label DC to mdc(double buffer), without backcolor
                        BitBlt(GetDC(inst->hwnd),0,0,a.Width,a.Height,mdc,b.X, b.Y,SRCCOPY);//now copy the double buffer to label dc
                        //clean objects
                        SelectObject(mdc,moldbmp);
                        DeleteObject(mbmp);
                        DeleteDC(mdc);                
                    }
                    
                }
                break;
                
                case WM_CTLCOLORSTATIC:
                {
                    if (inst->blnTransparent==false)
                    {
                        HDC hdcStatic = (HDC)wParam;
                        SetTextColor(hdcStatic, inst->clrTextColor);
                        SetBkMode(hdcStatic, TRANSPARENT);
                        SetBkColor(hdcStatic,inst->clrBackColor);
                        g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
                        return (LONG)g_hbrBackground;
                    }
                }
                break;
    or the WM_ERASEBKGND message is ignored or the text override it

  7. #22
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    or the WM_ERASEBKGND message is ignored
    Have you put a break point on it in the debugger to see if you are getting this message? Or do what I had in one of my earlier code posts, output all message values received to a text file so then you can easily establish what messages are received in what order.

    If you are receiving this message, then obviously the code is not doing what you expected - which is what exactly?

    Also note from the documentation for WM_ERASEBKGND that if this message is processed, then you need to return a non-zero value. Returning a zero value indicates that the window will be erased and redrawn. Read the documentation! http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #23
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    Have you put a break point on it in the debugger to see if you are getting this message? Or do what I had in one of my earlier code posts, output all message values received to a text file so then you can easily establish what messages are received in what order.

    If you are receiving this message, then obviously the code is not doing what you expected - which is what exactly?

    Also note from the documentation for WM_ERASEBKGND that if this message is processed, then you need to return a non-zero value. Returning a zero value indicates that the window will be erased and redrawn. Read the documentation! http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    i recive a black rectangle with the text:
    Code:
    case WM_ERASEBKGND:
                {
                    if (inst->blnTransparent==true)
                    {
                        HDC mdc = CreateCompatibleDC(NULL);//creating the doublebuffer
                        Size a=inst->GetSize();//get the control size
                        Position b=inst->GetPosition();//get ocntrol position
                        HBITMAP mbmp =  CreateBitmap(a.Width,a.Height,1,24,NULL); //create the bimap with a size
                        HBITMAP moldbmp = (HBITMAP)SelectObject(mdc,mbmp);//select the DC from that bitmap
                        HDC labeldc=GetDC(inst->hwnd);//get the label DC
                        BitBlt(mdc,0,0,a.Width,a.Height,GetDC(GetParent(inst->hwnd)),b.X, b.Y,SRCCOPY);//copy the parent control
                        TransparentBlt(mdc,0,0,a.Width,a.Height,labeldc,0,0,a.Width,a.Height,(UINT)inst->clrBackColor);//copy the label DC to mdc(double buffer), without backcolor
                        BitBlt(GetDC(inst->hwnd),0,0,a.Width,a.Height,mdc,b.X, b.Y,SRCCOPY);//now copy the double buffer to label dc
                        //clean objects
                        SelectObject(mdc,moldbmp);
                        DeleteObject(mbmp);
                        DeleteDC(mdc);
                        Sleep(2000);
                        return DefWindowProc(hwnd, msg, wParam, lParam);;
                    }
    
                }
                break;
    so the problem is how i use bitblt()?

  9. #24
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    Code:
    Sleep(2000);
    return DefWindowProc(hwnd, msg, wParam, lParam);
    You're supposed to return a non-zero value - not call defproc.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #25
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    Code:
    Sleep(2000);
    return DefWindowProc(hwnd, msg, wParam, lParam);
    You're supposed to return a non-zero value - not call defproc.
    now i changed to:
    Code:
    return (LONG)CreateSolidBrush(NULL_BRUSH)

  11. #26
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    Now you have a resource leak as you are creating a brush every time you change the background but you never delete the object.
    See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Why don't you just return 1?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  12. #27
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    Now you have a resource leak as you are creating a brush every time you change the background but you never delete the object.
    See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Why don't you just return 1?
    you have right. but i continue with same result: a black rectangle

  13. #28
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    Code:
    HDC mdc = CreateCompatibleDC(NULL);//creating the doublebuffer
    Size a=inst->GetSize();//get the control size
    Position b=inst->GetPosition();//get ocntrol position
    HBITMAP mbmp =  CreateBitmap(a.Width,a.Height,1,24,NULL); //create the bimap with a size
    HBITMAP moldbmp = (HBITMAP)SelectObject(mdc,mbmp);//select the DC from that bitmap
    HDC labeldc=GetDC(inst->hwnd);//get the label DC
          BitBlt(mdc,0,0,a.Width,a.Height,GetDC(GetParent(inst->hwnd)),b.X, b.Y,SRCCOPY);//copy the parent control 
          TransparentBlt(mdc,0,0,a.Width,a.Height,labeldc,0,0,a.Width,a.Height,(UINT)inst->clrBackColor);//copy the label DC to mdc(double buffer), without backcolor
          BitBlt(GetDC(inst->hwnd),0,0,a.Width,a.Height,mdc,b.X, b.Y,SRCCOPY);//now copy the double buffer to label dc
                    //clean objects
         SelectObject(mdc,moldbmp);
         DeleteObject(mbmp);
         DeleteDC(mdc);
    And you think this code does what? From where did you obtain it?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  14. #29
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    Code:
    HDC mdc = CreateCompatibleDC(NULL);//creating the doublebuffer
    Size a=inst->GetSize();//get the control size
    Position b=inst->GetPosition();//get ocntrol position
    HBITMAP mbmp =  CreateBitmap(a.Width,a.Height,1,24,NULL); //create the bimap with a size
    HBITMAP moldbmp = (HBITMAP)SelectObject(mdc,mbmp);//select the DC from that bitmap
    HDC labeldc=GetDC(inst->hwnd);//get the label DC
          BitBlt(mdc,0,0,a.Width,a.Height,GetDC(GetParent(inst->hwnd)),b.X, b.Y,SRCCOPY);//copy the parent control 
          TransparentBlt(mdc,0,0,a.Width,a.Height,labeldc,0,0,a.Width,a.Height,(UINT)inst->clrBackColor);//copy the label DC to mdc(double buffer), without backcolor
          BitBlt(GetDC(inst->hwnd),0,0,a.Width,a.Height,mdc,b.X, b.Y,SRCCOPY);//now copy the double buffer to label dc
                    //clean objects
         SelectObject(mdc,moldbmp);
         DeleteObject(mbmp);
         DeleteDC(mdc);
    And you think this code does what? From where did you obtain it?
    copy the parent HDC to doublebuffer... copy the child HDC to doublebuffer(transparent... without backcolor) and then copy the doublebuffer to child HDC

  15. #30
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    You have checked, haven't you, that GetSize() and GetPosition() are returning the expected values?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured