CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129

    Question Pointing Hwnd to a top-level dialog

    Hi...im trying to use a transparency code on my program...
    Code:
    // Set WS_EX_LAYERED on this window 
    SetWindowLong(hwnd, GWL_EXSTYLE,
            GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
    // Make this window 70% alpha
    SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
    But it seens to me that i cant point hwnd to a top-level dialog...
    Can someone help me please?!

    P.S.: Newbie speaking...
    Regards,
    Alexei

  2. #2
    Join Date
    Nov 2003
    Location
    Central Florida
    Posts
    44
    How are you getting the hWnd, and where is this code?
    But... but... I'll set the building on fire.

    How many keys do YOU press?

  3. #3
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    Code is from MSDN library

    hwnd was on that page... im not sure if im using it right...
    I need the transparent dialog box..
    My prog has only single dialog box... i want it to be transparent (The perfect solution will be making it transparent when its not active)...
    Regards,
    Alexei

  4. #4
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    the handle is a member variable of your dialog class.
    Use m_hWnd instead.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  5. #5
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    Okej... but still... im not sure how to...
    Can you please modify this code so it will make a window transparent when i click on a button?!
    I wrote it like this but it doesnt really work

    Code:
    void CFavoritesDlg::OnButton1()
    {
    	
    	// Set WS_EX_LAYERED on this window 
    	SetWindowLong(m_hWnd, GWL_EXSTYLE,
    			GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
    	// Make this window 70% alpha
    	SetLayeredWindowAttributes( 0, (255 * 70) / 100, LWA_ALPHA);
    }
    Regards,
    Alexei

  6. #6
    Join Date
    Nov 2003
    Location
    Central Florida
    Posts
    44
    What exactly isn't working about it? I dropped that code in a test project and it works fine...


    Are you sure you're using Windows 2000 or later?
    But... but... I'll set the building on fire.

    How many keys do YOU press?

  7. #7
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    Im using Win XP...

    I just dont know how to use this thingy...
    all i did is made a dialog base program...
    then i put a button... creat a function for that button... in that buttons function i wrote
    Code:
    void CFavoritesDlg::OnButton1()
    {
    	
    	// Set WS_EX_LAYERED on this window 
    	SetWindowLong(m_hWnd, GWL_EXSTYLE,
    			GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
    	// Make this window 70% alpha
    	SetLayeredWindowAttributes( 0, (255 * 70) / 100, LWA_ALPHA);
    }
    Nothing more...
    And i get a linkin problem now... before i just had an error...
    Regards,
    Alexei

  8. #8
    Join Date
    Nov 2003
    Location
    Central Florida
    Posts
    44
    Add this line at the beginning of your OnButton1 function:

    SetWindowText("Window should now be transparent.");

    and see if the title of the window changes when you click the button.


    Also, it'd help a LOT if you would say what errors you are getting.
    But... but... I'll set the building on fire.

    How many keys do YOU press?

  9. #9
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    Sure -- FATAL LINKING ERROR

    P.S.: .NET studio starts piising me off..lol
    Regards,
    Alexei

  10. #10
    Join Date
    Nov 2003
    Location
    Central Florida
    Posts
    44
    Have you tried completely rebuilding the solution? (i.e. Clean Solution, Build Solution)
    But... but... I'll set the building on fire.

    How many keys do YOU press?

  11. #11
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129

    Working now!

    Okej... thanx for help with this problem... its working... all i needed is a reboot...lol

    But more advanced problem_! Making it transparent ONLY When its not active...
    How shall i do that?!
    I mean when isa active -- it will be 100% visible...
    But when not... about 70% visible...
    Plus Button1 only turns this on...

    Possible to do that?!
    Regards,
    Alexei

  12. #12
    Join Date
    Nov 2003
    Location
    Central Florida
    Posts
    44
    Trap the WM_GETFOCUS and WM_KILLFOCUS messages; in WM_GETFOCUS, call your transparency code. In WM_KILLFOCUS, call SetWindowLong() and remove the WS_EX_LAYERED flag.


    Or you can call UpdateLayeredWindow() and set the transparency to 0 when you get a WM_KILLFOCUS.
    But... but... I'll set the building on fire.

    How many keys do YOU press?

  13. #13
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    okej... thanx.. i will try to do that...
    Bzway... How do i open a ClassWizard?? im on a .NET 2003 now... i had VS 6.0 before... cant find anything like that...
    Regards,
    Alexei

  14. #14
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129
    Still cant do that...Somehow i just dont get how to do that :S

    Trap it... how?!
    Where shall i put the code and WHAT code?!
    Regards,
    Alexei

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