0

from VB6, i build these code for transparent:

void Transparent()
    {
        SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | 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 1 error from messagebox:
87:ERROR_INVALID_PARAMETER - The parameter is incorrect.

can anyone advice me?

3
Contributors
5
Replies
17
Views
3 Years
Discussion Span
Last Post by cambalinho
0

What type is clrBackColor?
Is the window that you're trying to make transparent a top level window?

Edited by Ketsuekiame

1

Now sure what that colour parameter is, but I use this:

void SetTransparency(HWND hwnd, std::uint8_t Transperancy)
{
    long wAttr = GetWindowLong(hwnd, GWL_EXSTYLE);
    SetWindowLong(hwnd, GWL_EXSTYLE, wAttr | WS_EX_LAYERED);
    SetLayeredWindowAttributes(hwnd, 0, Transperancy, 0x2);
}

SetTransparency(Some_Window_Handle, 0); //100% transparency
SetTransparency(Some_Window_Handle, 128); //50% transparency
SetTransparency(Some_Window_Handle, 255); //0% transparency

Edited by triumphost

Votes + Comments
Nice.
0

If the window (this includes controls) is not a top level window, you cannot make it WS_EX_LAYERED, unless you're running Windows 8. So if you're trying to run it against a child window (which is typically what controls are) then you will get an error.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.