CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    90

    Aero effect Shadow, and transparency goes away if Rgn APIs are used

    hello,

    i have a Default MFC Application, and i have an imaginary Rectangle(larger then MFC Apps) in the Desktops,
    i want to clip the MFC applications when it moves beyond that rectangle. here is what i have been doing
    i used SetWindowRgn() with the offset rects, and i am able to clip it.

    Code:
    if ( pRect->right > 800)
    	{
    		
    		int delta = pRect->right - 800;
    
    		HRGN  hgn = CreateRectRgn(0,0, rc.Width() -delta, rc.Height());
    
    		HRGN hrgntemp = CreateRectRgn(0,0,0,0);
    		int regionType = GetWindowRgn(hrgntemp);
    		if (regionType != ERROR)
    		{
    			DeleteObject(hrgntemp);
    			SetWindowRgn(hgn, TRUE);
    		}
    		else
    		{
    			SetWindowRgn(hgn, TRUE);
    		}
    		
    
    	}
    but for some unknown reason, the tranperency and shadow effect goes away when i am using SetWindowRgn, is there any way to keep transperance and Shodow effect.

    then i dug more that found that there is a message(WM_DWMNCRENDERINGCHANGED fRenderingEnabled:False) that is sent to my widnow when i apply region API, and when i delete it same message with true (WM_DWMNCRENDERINGCHANGED fRenderingEnabled:True) is sent. looks windows itself is doing it, is there any way to prevent it?

    i added a message handle on WM_DWMNCRENDERINGCHANGED message and then try to re-enable it, but strangly for the first time it works multiple tries it does not work.

    Code:
    LRESULT CMonitorTestAppDlg::OndwmncRenderingChanged(WPARAM wp, LPARAM lp)
    {
    	if(wp == TRUE)
    	{
    		OutputDebugString(L"Nc Rendereing Enabled\n");
    	}
    	else
    	{
    		OutputDebugString(L"Nc Rendereing disabled\n");
    		EnableNCRendering(m_hWnd);
    	}
    
    	return 0;
    }
    
    HRESULT EnableNCRendering(HWND hwnd)
    {
       HRESULT hr = S_OK;
       DWMNCRENDERINGPOLICY ncrp = DWMNCRP_ENABLED;
    
       // Disable non-client area rendering on the window.
       hr = DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &ncrp, sizeof(ncrp));
    
       if (SUCCEEDED(hr))
       {
          // Do work here. 
       }
     
       return hr;
    }
    Any clue when using region deactivates Aero Effects, is there any way to fix it

    regards
    Deepak

  2. #2
    Join Date
    Jan 2007
    Posts
    90

    Re: Aero effect Shadow, and transparency goes away if Rgn APIs are used

    more update with screen shot. i am using this code in default MFC application.

    Code:
    void CMonitorTestAppDlg::OnMoving(UINT fwSide, LPRECT pRect)
    {
    	CRect rc(*pRect);
    
    	
    	if ( pRect->right > 800)
    	{
    		
    		OutputDebugString(L"In the Range\n");
    		int delta = pRect->right - 800;
    
    		HRGN  hgn = CreateRectRgn(0,0, rc.Width() -delta, rc.Height());
    
    		HRGN hrgntemp = CreateRectRgn(0,0,0,0);
    		int regionType = GetWindowRgn(hrgntemp);
    		if (regionType != ERROR)
    		{
    			DeleteObject(hrgntemp);
    			SetWindowRgn(hgn, TRUE);
    		}
    		else
    		{
    			SetWindowRgn(hgn, TRUE);
    		}
    		
    
    	}
    	else
    	{
    		OutputDebugString(L" out of Range\n");
    		HRGN hrgntemp = CreateRectRgn(0,0,0,0);
    		int regionType = GetWindowRgn(hrgntemp);
    		if (regionType != ERROR)
    		{
    			DeleteObject(hrgntemp);
    			SetWindowRgn(NULL, TRUE);
    		}	
    		
    
    	}
    
    	CDialogEx::OnMoving(fwSide, pRect);
    	
    }
    i have attached the image also.

    Regards
    DS
    Attached Images Attached Images  
    Last edited by Deepak_Sharma; June 9th, 2012 at 03:33 AM.

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