-
September 9th, 2014, 03:39 AM
#1
c++ - how can i do a transparent form?
i continue with problems for make the form transparent
see these code:
Code:
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, clrBackColor, NULL, LWA_COLORKEY);
heres how i create the form:
Code:
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE|CS_HREDRAW | CS_VREDRAW , classname, strCaption.c_str(), WS_OVERLAPPEDWINDOW | BS_NOTIFY,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
the form can be transparent, but, in same cases, i can lose the events form...i don't understand why... can anyone explain more about it, please?
-
September 11th, 2014, 06:27 AM
#2
Re: c++ - how can i do a transparent form?
Code:
WS_EX_CLIENTEDGE|CS_HREDRAW | CS_VREDRAW
This is definitely not what you think it is. Here you need only Extended Window Styles. You need CS_ styles in your windows class registration only. And this is the place where you should use WS_EX_LAYERED.
Code:
WS_OVERLAPPEDWINDOW | BS_NOTIFY
Again, only Window Class Styles expected here, and button styles must be used only with button controls.
Please read MSDN articles carefully prior to putting any API in use. Now it looks like you play a sort of programming casino throwing dice and waiting for a jackpot.
Best regards,
Igor
-
September 11th, 2014, 10:22 AM
#3
Re: c++ - how can i do a transparent form?
Originally Posted by Igor Vartanov
Code:
WS_EX_CLIENTEDGE|CS_HREDRAW | CS_VREDRAW
This is definitely not what you think it is. Here you need only Extended Window Styles. You need CS_ styles in your windows class registration only. And this is the place where you should use WS_EX_LAYERED.
Code:
WS_OVERLAPPEDWINDOW | BS_NOTIFY
Again, only Window Class Styles expected here, and button styles must be used only with button controls.
Please read MSDN articles carefully prior to putting any API in use. Now it looks like you play a sort of programming casino throwing dice and waiting for a jackpot.
true.. thanks for correct me:
Code:
hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, classname, strCaption.c_str(), WS_OVERLAPPEDWINDOW|CS_HREDRAW | CS_VREDRAW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
if i create the form with WS_EX_LAYERED , the form is showed invisible.
but i continue with some strange effects
see how i put the form transparent:
Code:
property<color> BackColor
{
Get(color)
{
return clrBackColor;
},
Set(color clrColor)
{
if(clrBackColor!=clrColor && clrColor==-1)//if the color is changed and '-1'(transparent)
{
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, clrBackColor, Opacy, LWA_COLORKEY|LWA_ALPHA);
UpdateWindow(hwnd);
clrBackColor=-1;
}
else if(clrBackColor!=clrColor) //if the color is changed
{
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) |(~ WS_EX_LAYERED));
SetLayeredWindowAttributes(hwnd, -1, Opacy, LWA_COLORKEY | LWA_ALPHA);
UpdateWindow(hwnd);
SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, (LONG)CreateSolidBrush(clrBackColor));
InvalidateRect(hwnd,NULL,true);
}
}
};
is these code correct for add and take of the WS_EX_LAYERED style?
i'm getting only black color
-
September 11th, 2014, 11:20 AM
#4
Re: c++ - how can i do a transparent form?
now i understand why, when i create the form with WS_EX_LAYERED, i get the form invisible
by defauld, the opacy is '0'(zero).. so i did these:
Code:
hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYERED, classname, strCaption.c_str(), WS_OVERLAPPEDWINDOW | CS_HREDRAW | CS_VREDRAW ,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
SetLayeredWindowAttributes(hwnd, NULL, 255, LWA_ALPHA);
now the form is showed with WS_EX_LAYERED style.
now i must see why i only get 1 color(black) on backcolor
-
September 11th, 2014, 11:29 AM
#5
Re: c++ - how can i do a transparent form?
before i could change the backcolor with these code:
Code:
SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, (LONG)CreateSolidBrush(clrBackColor));
now i only recive the black color and not red\green
why these visual error?
-
September 11th, 2014, 11:36 AM
#6
Re: c++ - how can i do a transparent form?
now i found the error:
Code:
property<color> BackColor
{
Get(color)
{
return clrBackColor;
},
Set(color clrColor)
{
if(clrBackColor!=clrColor && clrColor==-1)//if the color is changed and '-1'(transparent)
{
SetLayeredWindowAttributes(hwnd, clrBackColor, Opacy, LWA_COLORKEY|LWA_ALPHA);
clrBackColor=-1;
}
else if(clrBackColor!=clrColor) //if the color is changed
{
SetClassLongPtr(hwnd,GCLP_HBRBACKGROUND, (LONG)CreateSolidBrush(clrColor));
InvalidateRect(hwnd,NULL,true);
clrBackColor=clrColor;
}
}
};
i wasn't change the clrBackColor value and not use the clrColor variable. now works fine
-
September 11th, 2014, 12:24 PM
#7
Re: c++ - how can i do a transparent form?
for finish, i have 1 question: why, when i maximizate the form, i lose the caption bar and borders actions?(like resize the caption menu and that 3 buttons on form)
-
September 12th, 2014, 01:36 AM
#8
Re: c++ - how can i do a transparent form?
I have to admit that I fail to understand your question. But whatever effect you run into, this would definitely have nothing to do with layered window transparency.
Best regards,
Igor
-
September 12th, 2014, 03:41 AM
#9
Re: c++ - how can i do a transparent form?
Originally Posted by Igor Vartanov
I have to admit that I fail to understand your question. But whatever effect you run into, this would definitely have nothing to do with layered window transparency.
just test yourself:
1 - put the form transparent;
2 - now maximize the form;
3 - can you click:
- on close button?('X');
- on icon menu?;
- and the others 2 buttons?
the caption bar is showed, but without any action activated.
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
|