locked
Create Tranparent window using LWA_COLORKEY RRS feed

  • Question

  • I want to create a transparent window( not click through) with LWA_COLORKEY. Is there any way? Also is there any way to create it with out using alpha blending.

    Thanks, Renjith V R


    Wednesday, July 4, 2012 3:45 PM

Answers

  • The sample I pointed to above used just the LWA_COLORKEY.  Here is some minimal code you can quickly try:

    (i) Create a test MFC MDI project.
    (ii) Add the following code.

    BOOL CAboutDlg::OnInitDialog()
    {
       CDialog::OnInitDialog();
       ModifyStyleEx(0,WS_EX_LAYERED);
       SetLayeredWindowAttributes(0x111111, 255, LWA_COLORKEY);
       return TRUE; 
    }
    void CAboutDlg::OnPaint()
    {
      CPaintDC dc(this); 
      CRect r;
      GetClientRect(r);
      dc.FillSolidRect(r, 0x111111);
      CDialog::OnPaint();
    }

    Note that '0x111111' is used in OnPaint () to draw the fill client area background. It is also set as the color key to make transparent.  I tested it and it works perfectly fine for me.

    -Seetharam

    Wednesday, July 11, 2012 9:51 PM

All replies

  • I want to create a transparent window( not click through) with LWA_COLORKEY. Is there any way? Also is there any way to create it with out using alpha blending.

    Thanks, Renjith V R

    you can check the following codeproject article for make use LWA_COLORKEY

    http://www.codeproject.com/Articles/5475/Quick-and-Dirty-Window-Transparency


    Thanks and Regards Selvam http://www15.brinkster.com/selvamselvam/

    Wednesday, July 4, 2012 4:25 PM
  • it is not used LWA_COLORKEY. It is used LWA_ALPHA. I want code which only uses LWA_COLORKEY

    Thanks, Renjith V R

    Wednesday, July 4, 2012 5:34 PM
  • They are just different values? So, what you want ?


    Please not forget mark your answer, and unmark your disagreed point.


    • Edited by i1friend Wednesday, July 11, 2012 9:06 AM
    Wednesday, July 11, 2012 9:05 AM
  • I want sample which only uses LWA_COLORKEY as follows

    SetLayeredWindowAttributes (hWnd, 
                                           RGB(255,255,255), 
                                           factor,
                                           LWA_COLORKEY);

    As per my understanding LWA_ALPHA uses alpha channel. I dont want to use it. i want to use LWA_COLORKEY


    Thanks, Renjith V R

    Wednesday, July 11, 2012 10:21 AM
  • There some code in one of the answered posts:

    http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/a2d3547c-c822-4b96-856d-10ad4fd80f69

    What is the problem you are seeing if you just use the LWA_COLORKEY?

    -Seetharam 

    Wednesday, July 11, 2012 3:05 PM
  • When i used LWA_COLORKEY, the dialog not become transparent

    Could you please post the code for only make it transparent using LWA_COLORKEY. Not LWA_ALPHA.


    Thanks, Renjith V R

    Wednesday, July 11, 2012 5:54 PM
  • The sample I pointed to above used just the LWA_COLORKEY.  Here is some minimal code you can quickly try:

    (i) Create a test MFC MDI project.
    (ii) Add the following code.

    BOOL CAboutDlg::OnInitDialog()
    {
       CDialog::OnInitDialog();
       ModifyStyleEx(0,WS_EX_LAYERED);
       SetLayeredWindowAttributes(0x111111, 255, LWA_COLORKEY);
       return TRUE; 
    }
    void CAboutDlg::OnPaint()
    {
      CPaintDC dc(this); 
      CRect r;
      GetClientRect(r);
      dc.FillSolidRect(r, 0x111111);
      CDialog::OnPaint();
    }

    Note that '0x111111' is used in OnPaint () to draw the fill client area background. It is also set as the color key to make transparent.  I tested it and it works perfectly fine for me.

    -Seetharam

    Wednesday, July 11, 2012 9:51 PM