-
January 3rd, 2014, 04:23 PM
#16
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?
-
January 3rd, 2014, 04:40 PM
#17
Re: [win32] - transparent and opacy
Originally Posted by Cambalinho
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!
Originally Posted by Cambalinho
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
-
January 3rd, 2014, 04:58 PM
#18
Re: [win32] - transparent and opacy
Originally Posted by VictorN
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.
-
January 3rd, 2014, 05:01 PM
#19
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)
-
January 3rd, 2014, 05:08 PM
#20
Re: [win32] - transparent and opacy
Originally Posted by 2kaud
I hope the version of this case code you use has a break statement at the end.
yes.. it have
-
January 3rd, 2014, 05:12 PM
#21
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
-
January 3rd, 2014, 06:48 PM
#22
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)
-
January 4th, 2014, 06:26 AM
#23
Re: [win32] - transparent and opacy
Originally Posted by 2kaud
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()?
-
January 4th, 2014, 06:31 AM
#24
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)
-
January 4th, 2014, 06:35 AM
#25
Re: [win32] - transparent and opacy
Originally Posted by 2kaud
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)
-
January 4th, 2014, 06:41 AM
#26
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)
-
January 4th, 2014, 06:54 AM
#27
Re: [win32] - transparent and opacy
Originally Posted by 2kaud
you have right. but i continue with same result: a black rectangle
-
January 4th, 2014, 07:32 AM
#28
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)
-
January 4th, 2014, 07:37 AM
#29
Re: [win32] - transparent and opacy
Originally Posted by 2kaud
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
-
January 4th, 2014, 07:59 AM
#30
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|