Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Darken Windows Desktop and draw normal brightness moveable rectangle [modified]

Darken Windows Desktop and draw normal brightness moveable rectangle [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtutorial
7 Posts 4 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Neville Franks
    wrote on last edited by
    #1

    Hi, I am trying to work out how to darken the Windows Desktop and then display a rectangular portion of the desktop normally (not darkened). This is for a screen area capture program. You can see the precise effect I am after in Jing http://www.jingproject.com/[^]. I understand how to make a window transparent, but that's not what I'm after. Fading the background in a Web page is also commonly done. Any tips/pointers/C++ source much appreciated. Google has not helped so far.

    Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

    modified on Monday, October 19, 2009 10:33 PM

    A N I 3 Replies Last reply
    0
    • N Neville Franks

      Hi, I am trying to work out how to darken the Windows Desktop and then display a rectangular portion of the desktop normally (not darkened). This is for a screen area capture program. You can see the precise effect I am after in Jing http://www.jingproject.com/[^]. I understand how to make a window transparent, but that's not what I'm after. Fading the background in a Web page is also commonly done. Any tips/pointers/C++ source much appreciated. Google has not helped so far.

      Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

      modified on Monday, October 19, 2009 10:33 PM

      A Offline
      A Offline
      Adam Roderick J
      wrote on last edited by
      #2

      To do this, Firstly capture the desktop image. then do the following steps. 1. Draw the captured image. 2. Draw the invererted image of captured image over it. some vc++ code snippet to help you:-

      void OnDraw( CDC* pDC_i )
      {
      if( 0 != m_NormalImage )
      {
      CDC MemDc;
      MemDc.CreateCompatibleDC( pDC_i );
      CImage *pOldImage = MemDc.SelectObject( m_NormalImage );
      CRect rect;
      GetClientRect( &rect );
      rect.left = HEADER_OFFSET;
      rect.right = max( rect.Width(), 300 ) + HEADER_OFFSET;
      rect.top = HEADER_OFFSET;
      rect.bottom = HEADER_OFFSET + HEADER_HEIGHT ;
      COLORREF CurrentBkgd = pDC_i->SetBkColor( IMAGE_HEADER_BKGDCOLOR );
      pDC_i->SetBkColor( CurrentBkgd );
      pDC_i->BitBlt( 0, HEADER_OFFSET + HEADER_HEIGHT + HEADER_OFFSET , m_nWidth, HEADER_OFFSET + m_nHeight + HEADER_HEIGHT + HEADER_OFFSET,
      &MemDc, 0, 0, SRCCOPY );
      if( m_bInvertStatus && 0 != m_pInverseImage )
      {
      DrawInverseImage( pDC_i );

              }
              MemDc.SelectObject( pOldImage );
              MemDc.DeleteDC();
          }
      

      }

      void SetInvertImage( HBITMAP himageinverse_i)
      {
      m_pinverseImage = new CBitmap();
      m_pinverseImage->Attach( himageinverse_i);
      }

      void DrawInvertImage( CDC* pDC_i )
      {
      if( 0 !=m_pinverseImage )
      {
      CDC Memdc;
      Memdc.CreateCompatibleDC( pDC_i );
      CBitmap *pOldBitmap = dcMem.SelectObject(m_inverseImage );
      pDC_i->BitBlt( 0, HEADER_OFFSET + HEADER_HEIGHT + HEADER_OFFSET, m_nWidth, HEADER_OFFSET + m_nHeight + HEADER_HEIGHT + HEADER_OFFSET,
      &dcMem, 0, 0, SRCINVERT );
      dcMem.SelectObject( pOldBitmap );
      dcMem.DeleteDC();
      }
      }

      Now screen will be fully black. 3. Now make the inverted image part as transparent of your wish, just refer this article.([^]) I think your task is achieved

      Величие не Бога может быть недооценена.

      modified on Tuesday, October 20, 2009 12:02 AM

      N 1 Reply Last reply
      0
      • N Neville Franks

        Hi, I am trying to work out how to darken the Windows Desktop and then display a rectangular portion of the desktop normally (not darkened). This is for a screen area capture program. You can see the precise effect I am after in Jing http://www.jingproject.com/[^]. I understand how to make a window transparent, but that's not what I'm after. Fading the background in a Web page is also commonly done. Any tips/pointers/C++ source much appreciated. Google has not helped so far.

        Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

        modified on Monday, October 19, 2009 10:33 PM

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        Neville Franks wrote:

        I understand how to make a window transparent, but that's not what I'm after.

        I think you can do this by creating one window in the excat size of the desktop. In the erase background function first fill the background of dialog with black color. After that bitblt the content of the desktop DC to the dialog( try the SRCPAINT flag in the bitblt ). Now after that paint the rectangle that you want to show without darkening using bitblt again( this time specify SRCCOPY in it ).

        nave [OpenedFileFinder] [My Blog]

        N 1 Reply Last reply
        0
        • N Neville Franks

          Hi, I am trying to work out how to darken the Windows Desktop and then display a rectangular portion of the desktop normally (not darkened). This is for a screen area capture program. You can see the precise effect I am after in Jing http://www.jingproject.com/[^]. I understand how to make a window transparent, but that's not what I'm after. Fading the background in a Web page is also commonly done. Any tips/pointers/C++ source much appreciated. Google has not helped so far.

          Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

          modified on Monday, October 19, 2009 10:33 PM

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          As the other replies said, the trick is to take a snapshot of the desktop, then put a window on top using that image. To make the area outside your selection be a bit darker, rather than black, I used GDI+: In the following, I've already attached a Graphics object to a HDC, pts is an array of PointF's, and nPoints is the size of that array. You could just make a rectangular exclude-from-shading area too, of course.

          CRect rcClient;
          GetClientRect (&rcClient);
          
          Color clrBrush (128,0,0,0);
          SolidBrush brush (clrBrush);
          
          GraphicsPath path;
          path.AddPolygon (pts, nPoints);
          
          Region region (Rect (rcClient.left, rcClient.top, rcClient.Width (), rcClient.Height ()));
          region.Exclude (&path);
          
          gfx.FillRegion (&brush, ®ion);
          

          This does the effect over the whole of a window - your window will probably be larger than mine, but the point remains. I hope that helps, Iain.

          I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

          N 1 Reply Last reply
          0
          • A Adam Roderick J

            To do this, Firstly capture the desktop image. then do the following steps. 1. Draw the captured image. 2. Draw the invererted image of captured image over it. some vc++ code snippet to help you:-

            void OnDraw( CDC* pDC_i )
            {
            if( 0 != m_NormalImage )
            {
            CDC MemDc;
            MemDc.CreateCompatibleDC( pDC_i );
            CImage *pOldImage = MemDc.SelectObject( m_NormalImage );
            CRect rect;
            GetClientRect( &rect );
            rect.left = HEADER_OFFSET;
            rect.right = max( rect.Width(), 300 ) + HEADER_OFFSET;
            rect.top = HEADER_OFFSET;
            rect.bottom = HEADER_OFFSET + HEADER_HEIGHT ;
            COLORREF CurrentBkgd = pDC_i->SetBkColor( IMAGE_HEADER_BKGDCOLOR );
            pDC_i->SetBkColor( CurrentBkgd );
            pDC_i->BitBlt( 0, HEADER_OFFSET + HEADER_HEIGHT + HEADER_OFFSET , m_nWidth, HEADER_OFFSET + m_nHeight + HEADER_HEIGHT + HEADER_OFFSET,
            &MemDc, 0, 0, SRCCOPY );
            if( m_bInvertStatus && 0 != m_pInverseImage )
            {
            DrawInverseImage( pDC_i );

                    }
                    MemDc.SelectObject( pOldImage );
                    MemDc.DeleteDC();
                }
            

            }

            void SetInvertImage( HBITMAP himageinverse_i)
            {
            m_pinverseImage = new CBitmap();
            m_pinverseImage->Attach( himageinverse_i);
            }

            void DrawInvertImage( CDC* pDC_i )
            {
            if( 0 !=m_pinverseImage )
            {
            CDC Memdc;
            Memdc.CreateCompatibleDC( pDC_i );
            CBitmap *pOldBitmap = dcMem.SelectObject(m_inverseImage );
            pDC_i->BitBlt( 0, HEADER_OFFSET + HEADER_HEIGHT + HEADER_OFFSET, m_nWidth, HEADER_OFFSET + m_nHeight + HEADER_HEIGHT + HEADER_OFFSET,
            &dcMem, 0, 0, SRCINVERT );
            dcMem.SelectObject( pOldBitmap );
            dcMem.DeleteDC();
            }
            }

            Now screen will be fully black. 3. Now make the inverted image part as transparent of your wish, just refer this article.([^]) I think your task is achieved

            Величие не Бога может быть недооценена.

            modified on Tuesday, October 20, 2009 12:02 AM

            N Offline
            N Offline
            Neville Franks
            wrote on last edited by
            #5

            Thanks all. Capturing the desktop as an image and then altering that seems like the way forward. I've been researching GDI+ and the Effect Class, and I plan on trying the BrightnessContrast Class tomorrow. I'll draw the normal rectangle area using the original desktop image. And use a window layered over the top of the desktop. Sounds like a plan.

            Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

            1 Reply Last reply
            0
            • N Naveen

              Neville Franks wrote:

              I understand how to make a window transparent, but that's not what I'm after.

              I think you can do this by creating one window in the excat size of the desktop. In the erase background function first fill the background of dialog with black color. After that bitblt the content of the desktop DC to the dialog( try the SRCPAINT flag in the bitblt ). Now after that paint the rectangle that you want to show without darkening using bitblt again( this time specify SRCCOPY in it ).

              nave [OpenedFileFinder] [My Blog]

              N Offline
              N Offline
              Neville Franks
              wrote on last edited by
              #6

              Thanks, see my reply to ARJ 09 above.

              Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

              1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                As the other replies said, the trick is to take a snapshot of the desktop, then put a window on top using that image. To make the area outside your selection be a bit darker, rather than black, I used GDI+: In the following, I've already attached a Graphics object to a HDC, pts is an array of PointF's, and nPoints is the size of that array. You could just make a rectangular exclude-from-shading area too, of course.

                CRect rcClient;
                GetClientRect (&rcClient);
                
                Color clrBrush (128,0,0,0);
                SolidBrush brush (clrBrush);
                
                GraphicsPath path;
                path.AddPolygon (pts, nPoints);
                
                Region region (Rect (rcClient.left, rcClient.top, rcClient.Width (), rcClient.Height ()));
                region.Exclude (&path);
                
                gfx.FillRegion (&brush, ®ion);
                

                This does the effect over the whole of a window - your window will probably be larger than mine, but the point remains. I hope that helps, Iain.

                I have now moved to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need contract work done, give me a job! http://cv.imcsoft.co.uk/[^]

                N Offline
                N Offline
                Neville Franks
                wrote on last edited by
                #7

                Thanks Iain, see my reply to ARJ 09 above.

                Neville Franks, Author of Surfulater www.surfulater.com "Save what you Surf" and ED for Windows www.getsoft.com

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups