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?

Recommended Answers

All 5 Replies

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

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
commented: Nice. +14

sorry.. same error :(
the clrBackColor it's COLORREF

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.

so it's only valid for form(main window)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.