Need help drawing rectangle on Windows desktop...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Need help drawing rectangle on Windows desktop...

  1. #1
    Join Date
    Jul 2017
    Posts
    6

    Need to create transparent window with visible boarder...

    I have created an application that copies a specified rectangle from the Windows desktop and creates a video stream from it. I have the basic functionality working.

    I need a means of drawing a re-sizable rectangle on the Windows desktop, that has a transparent background (transparent client area within the rectangle). I have been trying to experiment with drawing a transparent window, with a visible (opaque) border, but have not had much luck.

    I was looking to use some code I found that was supposed to create a Window frame that had no title bar, and a transparent client area, and just get the RECT of the client area (as a means to specify the desktop area that would be copied to the video stream). Unfortunately, with Windows 10 the window boarder size is 0, so if the window client area (background) is transparent, then the user can not see the boarder at all.

    Anyone know of any example code for drawing a rectangle on the Windows desktop that has a transparent area in the center? Even better would be code that allows for the rectangle to be resized with the mouse.

    It would be most helpful if you could point me to specific examples or documentation on how to do this.

    Thanks for any help you can offer!
    Last edited by mediawiz; July 25th, 2017 at 03:39 PM.

  2. #2
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    315

    Re: Need help drawing rectangle on Windows desktop...

    If I undestood right you can:

    1 - Draw just the frame of the rectangule with lines, do not worring about the transparency
    2 - Copy the area of this rectangle in a bitmap.
    3 - To draw something inside it drawn on the bitmap saved.
    4 - Copy this bitmap to the rectangle on the sreen with a mask.

    Hope it helps.

  3. #3
    Join Date
    Jul 2017
    Posts
    6

    Re: Need help drawing rectangle on Windows desktop...

    Quote Originally Posted by Rabelo View Post
    If I undestood right you can:

    1 - Draw just the frame of the rectangule with lines, do not worring about the transparency
    2 - Copy the area of this rectangle in a bitmap.
    3 - To draw something inside it drawn on the bitmap saved.
    4 - Copy this bitmap to the rectangle on the sreen with a mask.

    Hope it helps.
    What Windows function call do I use to do item 1, or where can I find a code example to do that?

  4. #4
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    315

    Re: Need help drawing rectangle on Windows desktop...

    just drawn a rectangle with the rectangle function of CDC, like pDC->Rectangle on ondraw;
    As the mouse is moving you have to redraw the new rectangle. There is a problem because you will need to call redrawwindow to draw the new rectangle (and erase the old one) and depending on yor computer speed the screen will blink. To avoid this you can redraw the window only at 10 ( for example) movements of the mouse.

  5. #5
    Join Date
    Jul 2017
    Posts
    6

    Need to create transparent window with visible boarder...

    I have an application in which I need to create a window with the following attributes:
    - The window background is transparent (the client area is invisible, and you can see what's behind it)
    - The window has no title bar (just a client area)
    - The window has a visible border
    - The window is re-sizable

    I have experimented with various MFC window classes (CWnd, CFrame), and I have been able to create a "layered" window that has some of these qualities, but either the entire window is transparent (invisibble... can't see the frame) or the entire window is visible (including the white background).

    Anyone know of any examples I can look at that will show me how to do this???

  6. #6
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,883

    Re: Need help drawing rectangle on Windows desktop...

    [Threads merged as same question]
    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++17 Compiler: Microsoft VS2017 (15.5.1)

  7. #7
    Join Date
    Jul 2017
    Posts
    6

    Re: Need help drawing rectangle on Windows desktop...

    Quote Originally Posted by Rabelo View Post
    If I undestood right you can:

    1 - Draw just the frame of the rectangule with lines, do not worring about the transparency
    2 - Copy the area of this rectangle in a bitmap.
    3 - To draw something inside it drawn on the bitmap saved.
    4 - Copy this bitmap to the rectangle on the sreen with a mask.

    Hope it helps.
    No. I'm sorry. This doesn't help at all.
    Where are examples of doing this? What function calls or classes would be used to do this?
    What you have described is very vague.

  8. #8
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    315

    Re: Need help drawing rectangle on Windows desktop...

    What you are trying to do is not a simple task. Mainly because there is no a "window with a transparent client area", you will have to do this by yourself. One soluction is: before show the 2nd window copy the backround area of the 1st window in a bitmap and draw it in the client area of the 2nd window. The other itens (Title bar, visible border and resizable) you can control on the Create or Createex functions. As I said before you can :

    1 - Simply draw a rectangle without worry about transparency, while the user is moving the mouse you have just to redraw the rectancle, nothing else. When the user stop to draw the rectangle (at this moment he defined the window size, so you will have to know this moment, you can use the mouse lbutton to signalize that, the user need to click the left button to do so) in this moment you copy the rectangle area of the 1st window (you already know the size, is the rectangle that is just defined, the last one you drawn) in a bitmap.
    2- Create the 2nd window as you wish changing its properties on oncreate, create or or createex functions.
    3 - Draw the bitmap you saved on the client area of this 2nd window, you can use the ondraw function.

    Will not be easy to find a ready code to do that.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)