CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 39

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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?

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    Are you compiling as ASCII or UNICODE?
    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)

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    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()

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - transparent and opacy

    You should not call GetLastError unless the API function (SetLayeredWindowAttributes in your case) has failed.
    Victor Nijegorodov

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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.
    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)

  6. #6
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    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?

  7. #7
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - transparent and opacy

    Quote Originally Posted by Cambalinho View Post
    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?
    FYI: SetLayeredWindowAttributes function
    Victor Nijegorodov

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    Last edited by 2kaud; January 3rd, 2014 at 12:10 PM.
    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)

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by 2kaud View Post
    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?

  10. #10
    Join Date
    Apr 2009
    Posts
    1,355

    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

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: [win32] - transparent and opacy

    But see also the community additions section on
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    which refers to
    http://blogs.msdn.com/b/oldnewthing/.../10230811.aspx
    as I referenced in my post #11.
    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)

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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.
    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)

  13. #13
    Join Date
    Apr 2009
    Posts
    1,355

    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?

  14. #14
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - transparent and opacy

    Quote Originally Posted by Cambalinho View Post
    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!

    Quote Originally Posted by Cambalinho View Post
    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

  15. #15
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - transparent and opacy

    Quote Originally Posted by VictorN View Post
    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.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured