[win32] - transparent and opacy
i build these function from VB6(programming language):
Code:
void Transparent()
{
long test=GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong( hwnd, GWL_EXSTYLE,test | WS_EX_LAYERED);
SetLayeredWindowAttributes (hwnd, clrBackColor, 0, LWA_COLORKEY);
const char *text;
text=to_string( GetLastError()).c_str();
MessageBox(NULL,text,"erro",MB_OK);
}
but i get an error from messagebox:
87:ERROR_INVALID_PARAMETER - The parameter is incorrect.
(these code is for hide the backcolor)
can anyone advice me?
Re: [win32] - transparent and opacy
Are you compiling as ASCII or UNICODE?
Re: [win32] - transparent and opacy
You should not call GetLastError unless the API function (SetLayeredWindowAttributes in your case) has failed.
Re: [win32] - transparent and opacy
Quote:
Originally Posted by
2kaud
Are you compiling as ASCII or UNICODE?
sorry i don't know answer to that question... i'm using the Code Blocks IDE.
VictorN: yes... theres no error, on compiling, but no results on running. that's why i used the GetLastError()
Re: [win32] - transparent and opacy
MessageBox takes 4 parameters, The second and third parameters are typed as LPCTSTR. If you are compiling as UNICODE, then these become LPCWSTR which is const WCHAR* which is const wchar_t*. If you are compiling as ASCII, LPCTSTR becomes LPCSTR which is const char*. As text is defined as const char *, this is ASCII. If you are compiling as UNICODE, then MessageBox would be expecting a type of const wchar_t* and not const char* which is being provided - which could be the reason for the error 87. Try changing MessageBox to MessageBoxA().
Victor is quite right. The value returned by GetLastError() is only valid when an error has actually occured and the function in error states that the error number can be obtained by calling this function. Calling GetLastError() in a context in which it is not expected to be called can provide erronous information. SetLayeredWindowAttributes() returns 0 on failure and only in that case should GetLastError() be used.
Re: [win32] - transparent and opacy
Quote:
Originally Posted by
2kaud
MessageBox takes 4 parameters, The second and third parameters are typed as LPCTSTR. If you are compiling as UNICODE, then these become LPCWSTR which is const WCHAR* which is const wchar_t*. If you are compiling as ASCII, LPCTSTR becomes LPCSTR which is const char*. As text is defined as const char *, this is ASCII. If you are compiling as UNICODE, then MessageBox would be expecting a type of const wchar_t* and not const char* which is being provided - which could be the reason for the error 87. Try changing MessageBox to MessageBoxA().
Victor is quite right. The value returned by GetLastError() is only valid when an error has actually occured and the function in error states that the error number can be obtained by calling this function. Calling GetLastError() in a context in which it is not expected to be called can provide erronous information. SetLayeredWindowAttributes() returns 0 on failure and only in that case should GetLastError() be used.
i change for MessageBoxA() and i get the same error message.
1 question: SetLayeredWindowAttributes() is only for main window and not child window?
now i tested the same code with main window and works fine.. so what is needed for work with child windows?
Re: [win32] - transparent and opacy
Quote:
Originally Posted by
Cambalinho
1 question: SetLayeredWindowAttributes() is only for main window and not child window?
now i tested the same code with main window and works fine.. so what is needed for work with child windows?
But do you ask this question instead of just read MSDN? :(:confused:
FYI: SetLayeredWindowAttributes function
Re: [win32] - transparent and opacy
Quote:
Originally Posted by
2kaud
When/where are you calling Transparent()?
inside of my class... it's a class member... so i can't hide the backcolor and make opacy?
Re: [win32] - transparent and opacy
But if read the MSDN documentation for SetLayeredWindowAttributes(), as pointed out by Victor, this function only works on child windows with Windows 8/8.1. What OS are you using? If you are using a Windows OS prior to version 8 then this function only works for top level windows. Read the MSDN on-line documentation!
Re: [win32] - transparent and opacy
Quote:
Originally Posted by
2kaud
But if read the MSDN documentation for SetLayeredWindowAttributes(), as pointed out by Victor, this function only works on child windows with Windows 8/8.1. What OS are you using? If you are using a Windows OS prior to version 8 then this function only works for top level windows. Read the MSDN on-line documentation!
my windows is 7, so is there another way for transparent and opacity?
Re: [win32] - transparent and opacy
Re: [win32] - transparent and opacy
Quote:
Originally Posted by
2kaud
i'm trying learn how use Regions, but i have 2 questions:
1 - i belive that i can do it pixel by pixel. but i'm confused... but i think that i can do it... at least i did with VB2010;
2 - with Regions, can i do opacy?
Re: [win32] - transparent and opacy
from here: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
i read:
"With WS_EX_COMPOSITED set, all descendants of a window get bottom-to-top painting order using double-buffering. Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents to be painted without flicker."
but i'm confused :(
i think that, when i create the main window, i must add the WS_EX_TRANSPARENT extended style and add the WS_EX_COMPOSITED with child window extended style.
but or i don't understand what these means or i did something wrong :(
because the STATIC control isn't created
Re: [win32] - transparent and opacy
Re: [win32] - transparent and opacy
With my test code (as posted previously), setting the main window as WS_EX_COMPOSITED and setting the static control WS_EX_TRANSPARENT has no effect as expected (non Windows 8 computer). I still get the static control created as if these styles weren't specified.