dcsimg
Results 1 to 25 of 25

Thread: [VB6] Windowed Shape Control

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    [VB6] Windowed Shape Control

    The standard Shape control is windowless and thus cannot stay over controls that have windows, like CommandButtons, TextBoxes, PictureBoxes and many others.

    This Shape control replacement is an UserControl that holds an standard Shape control inside.

    Name:  Windowed_Shape_Control_Test_Scr.png
Views: 110
Size:  7.7 KB
    Attached Files Attached Files
    Last edited by Eduardo-; Jan 15th, 2019 at 03:15 PM.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2016
    Posts
    308

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    The standard Shape control is windowless and thus cannot stay over controls that have windows, like CommandButtons, TextBoxes, PictureBoxes and many others.

    WinShape uses an UserControl to hold a Shape control inside.

    It is not perfect: It makes the final step of the transparency with a Timer, and with some FillStyle settings (and perhaps other situations) a blink can be noticeable when it is drawn. But even so I think it could work for most of the scenarios that such control could be needed, so here it is.

    Attachment 164697
    thanks。but i have a question ,why you used “tmrDoNotPaint_Timer“。may be no need ?

    Code:
    'Private Sub tmrDoNotPaint_Timer()
    '    tmrDoNotPaint.Enabled = False
    'End Sub
    
    Private Sub tmrTransparency_Timer()
        tmrTransparency.Enabled = False
    '    If tmrDoNotPaint.Enabled Then Exit Sub
        DoEvents
    Last edited by xxdoc123; Jan 13th, 2019 at 08:59 PM.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by xxdoc123 View Post
    thanks。but i have a question ,why you used “tmrDoNotPaint_Timer“。may be no need ?

    Code:
    'Private Sub tmrDoNotPaint_Timer()
    '    tmrDoNotPaint.Enabled = False
    'End Sub
    
    Private Sub tmrTransparency_Timer()
        tmrTransparency.Enabled = False
    '    If tmrDoNotPaint.Enabled Then Exit Sub
        DoEvents
    When the tmrTransparency timer runs the code it triggers a new Paint Event (a WM_PAINT message) and then the tmrTransparency timer is enabled again. So I added the tmrDoNotPaint timer to avoid the continuous auto triggering of tmrTransparency.

  4. #4
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,013

    Re: [VB6] Windowed Shape Control

    Hi Eduardo,

    I worked it all out using clipping region API calls. I didn't want to post it here because I didn't want to hijack your thread. However, here's the link to it.

    It's pretty clean in that no timers are needed.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Elroy View Post
    Hi Eduardo,

    I worked it all out using clipping region API calls. I didn't want to post it here because I didn't want to hijack your thread. However, here's the link to it.

    It's pretty clean in that no timers are needed.

    Take Care,
    Elroy
    Thank you. Perhaps that could be useful for someone needing such a control.
    In my version I tried to keep 1:1 replacement of the original control, implementing all the properties.
    And as you said I did it for fun also, I didn't need the control.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    I changed the code to the resize event and removed the timers. It seems to work.

  7. #7
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,237

    Re: [VB6] Windowed Shape Control

    If the shape's border is anti-aliased, it would be great.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] WinShape: Windowed Shape Control

    Quote Originally Posted by dreammanor View Post
    If the shape's border is anti-aliased, it would be great.
    The Circle and Oval could be relatively easy to be drawn anti-aliased using GDI+, but the difficult problem is that this control is a window, it is not translucent.

    It would be much easier to the an anti-aliased Shape control windowless.
    The challenge is set. In any case I would do the windowless version.

    Perhaps someone comes with an idea about how to make the windowed version... because in that case the transparency of the window would have to be set for each pixel individually, and I think that's not possible...

    Opinions?

  9. #9
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,013

    Re: [VB6] WinShape: Windowed Shape Control

    Quote Originally Posted by dreammanor View Post
    If the shape's border is anti-aliased, it would be great.
    I was actually thinking the same thing when I developed my region clipping approach. I thought about firing up the GDI+ engine to do it, but then took the "easy way out" (with CreateRectRgn and CreateEllipticRgn). Also, getting all the features of the intrinsic shape (BorderStyle, FillStyle, Rounded-Corners) would take a bit of work. It's an interesting idea though.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  10. #10
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,013

    Re: [VB6] Windowed Shape Control

    Also, on another point, Eduardo, I'm curious why you didn't place PropertyChanged methods in your Let properties. It's my understanding that these set some internal "Is_Dirty" flag so that WriteProperties is fired when either the form-designer is closed or when the form is saved to disk.

    Also, I'm not sure all those If tests are necessary, but they certainly don't hurt anything. The only time your Let properties should fire is when you specifically change one of those properties in the IDE Properties Window or when you change it in executing code. Also, I've never used Refresh when changing properties, but I've never seen any problems.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Elroy View Post
    Also, on another point, Eduardo, I'm curious why you didn't place PropertyChanged methods in your Let properties.
    Because I forgot.

    Quote Originally Posted by Elroy View Post
    It's my understanding that these set some internal "Is_Dirty" flag so that WriteProperties is fired when either the form-designer is closed or when the form is saved to disk.
    The strange thing is that it is actually saving the property settings if there are changes, and that's also why I didn't realize that I was forgetting to put the PropertyChanged statement.
    Why it is saving I don't know.
    Perhaps changing properties in the constituent controls renders the UserControl as Dirty (because I store the settings in the Shape1 control that is inside the UserControl). But that doesn't makes much sense from a logical point of view -that the UserControl must save its property settings because there were changed properties of the constituent controls.

    Quote Originally Posted by Elroy View Post
    Also, I'm not sure all those If tests are necessary, but they certainly don't hurt anything. The only time your Let properties should fire is when you specifically change one of those properties in the IDE Properties Window or when you change it in executing code.

    Take Care,
    Elroy
    If the properties are set to specific values from code, if the values are set to the values that them already had, it would be refreshed many times unnecessarily.

    Code:
        WinShape1.BorderColor = vbRed
        WinShape1.BorderWidth = 3
        WinShape1.FillColor = vbWhite
    I'm used to make that If check for that reason, for not executing code that is only necessary when the property actually changes.

    [BTW, while testing this I found a bug, I'll change the Refresh method]

    Quote Originally Posted by Elroy View Post
    Also, I've never used Refresh when changing properties, but I've never seen any problems.
    In this case, it is necessary for the UserControl to properly handle the transparency regions upon changing a property setting that changes the figure. It is not something necessary to do in every UserControl's property procedure, but in this case I saw the problem and fixed it this way.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Updated. Basically bug fixes.

    Added properties BackColor and BackStyle.
    Changed Refresh.
    Added PropertyChanged statements.
    Added property descriptions.

  13. #13
    Frenzied Member
    Join Date
    Sep 2012
    Posts
    1,237

    Re: [VB6] WinShape: Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    The Circle and Oval could be relatively easy to be drawn anti-aliased using GDI+, but the difficult problem is that this control is a window, it is not translucent.

    It would be much easier to the an anti-aliased Shape control windowless.
    The challenge is set. In any case I would do the windowless version.

    Perhaps someone comes with an idea about how to make the windowed version... because in that case the transparency of the window would have to be set for each pixel individually, and I think that's not possible...

    Opinions?
    Quote Originally Posted by Elroy View Post
    I was actually thinking the same thing when I developed my region clipping approach. I thought about firing up the GDI+ engine to do it, but then took the "easy way out" (with CreateRectRgn and CreateEllipticRgn). Also, getting all the features of the intrinsic shape (BorderStyle, FillStyle, Rounded-Corners) would take a bit of work. It's an interesting idea though.
    I used GDI to develop a border anti-aliased aqua(crystal) button 10 years ago, but I've completely forgotten the details. The process of border anti-aliasing is probably like this:
    (1) Determine the anti-aliasing algorithm
    (2) Get the background color of the control container(control parent)
    (3) According to the anti-aliasing algorithm, the color of the control border is mixed pixel by pixel with the background color of the container (alpha processing)

    The entire drawing process is extremely cumbersome, but the smooth border makes the controls look beautiful and stylish. In addition, I also added a shadow to the control.

    Although GDIPlus, Direct2D and Cairo can easily implement border anti-aliasing, it's also very meaningful to implement it with GDI. However, now I have not used GDI at all, and all the UIs of my new software will be drawn with RC5.Cairo.

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: [VB6] WinShape: Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    The Circle and Oval could be relatively easy to be drawn anti-aliased using GDI+, but the difficult problem is that this control is a window, it is not translucent.

    Opinions?
    If willing to set your logic based on O/S

    Win8+ ... use GDI+ to create the semitransparent shape into a 32bpp premultiplied bitmap. Then use GDI and layered window APIs to form the control's shape. Before Win8, this was only possible for top level windows.

    Win7 and lower ... do it the way your are. Otherwise, making the control a top level window and keeping it aligned with the form is an ugly solution but a possible one if still wanting to use layered window APIs.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Hello guys. I'm not sure if I could explain well what I meant.

    I think that Windowed and Anti-aliased cannot be done well together.
    Why? Because when a line, circle or whatever is anti-aliased, in some pixels the color must be blended with the pixel of the window that is behind. And if the control is windowed it means that the pixel would need some percentage of transparency so it could be blended with the other window.
    If all the pixels of the line or circle in the UserControl had the same degree of transparency, that would be possible to do (at least in later Windows version with layered child windows, as LaVolpe pointed out) but the case is that each pixels would need to have a different degree of transparency.

    It would be needed a mask for the window with the transparency values for each pixel. AFAIK that's not supported in any version of Window (correct me if I'm wrong).
    It would be like a bitmap with Alpha channel but applied to the window transparency.

    I tried to illustrate it with images.
    When the background window changes, the resultant color changes, and that is needed to be done it for each pixel independently.
    In the right side you can see the bott0m-left corder bigger

    Name:  red-line1.png
Views: 48
Size:  835 Bytes Name:  red-line1b.png
Views: 48
Size:  379 Bytes

    Name:  red-line2.png
Views: 49
Size:  1.1 KB Name:  red-line2b.png
Views: 48
Size:  435 Bytes

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Name:  red-line3.png
Views: 49
Size:  1.6 KB Name:  red-line3b.png
Views: 48
Size:  401 Bytes

    Another attempt:
    The pixels of a window can be opaque, transparent (in that case is like they doesn't exist) or translucent.
    When the pixels are translucent they have a degree of transparency but still shows their colors in part.

    The issue is, AFAIK, that there is no way to set the degree of translucently individually for each pixel.
    You can set the translucently with the API SetLayeredWindowAttributes and the parameter bAlpha, but it will be the same for all the pixels of the window, the translucently cannot be set individually for each pixel.
    Last edited by Eduardo-; Yesterday at 10:57 AM.

  17. #17
    Fanatic Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    963

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    . . . the translucently cannot be set individually for each pixel.
    It's the UpdateLayeredWindow API you are looking for.

    Quote Originally Posted by LaVolpe View Post
    . . . making the control a top level window and keeping it aligned with the form is an ugly solution but a possible one if still wanting to use layered window APIs.
    I did something similar in Poor man's slideshow submission but the problem is that in recent version the OS is animating the windows upon restore/maximize/minimize in an out-of-band fashion i.e. the API reports the hwnd is restored and re-positioned at certain rcWindow but the actual window is still animated for half a second. So syncing the position of the "manual child" top-level windows appears "ahead of time".

    cheers,
    </wqw>

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    Yes, I was reading that AC_SRC_ALPHA seems to be the flag, along with a bitmap with alpha-channel in the HDC parameter of the UpdateLayeredWindow API.

    Am I right?
    Last edited by Eduardo-; Yesterday at 11:37 AM.

  19. #19
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,013

    Re: [VB6] Windowed Shape Control

    Truth be told, LaVolpe, doesn't your Alpha Image Control get us about 90% of the way there?

    It seems that, all that's left is to draw an anti-aliased ellipse (done with the alpha channel) into it, and we're done. I haven't played around with the Alpha Image Control that much, but it seems to handle the alpha channel correctly (hence its name), which is what all the above blending discussions are really about.

    For the un-initiated, the alpha channel is another channel just like the Red, Green, and/or Blue channels. However, rather than indicating a color-per-pixel, it indicates the level of Opacity (or reverse Translucency) per-pixel. For any pixel, 0 indicates transparent (i.e., the background color, ignoring the RGB channels), and 255 indicates fully opaque (i.e., the color indicated by the RGB channels).

    I haven't really looked, but I suspect the GDI+ gives us some nice tool for producing a nice anti-aliased ellipse. Do that, throw it into LaVolpe's control, and call it done. Move it around, and the background should be appropriately adjusted.

    Y'all Take Care,
    Elroy


    EDIT1: For the anti-aliased ellipse, here's part of it. We'd still need to make a GDI+ Graphics object and also a Pen object.

    Code:
    
    Option Explicit
    
    Public Enum SmoothingModeEnum
        SmoothingModeDefault = 0&
        SmoothingModeHighSpeed = 1&
        SmoothingModeHighQuality = 2&
        SmoothingModeNone = 3&
        SmoothingModeAntiAlias8x4 = 4&
        SmoothingModeAntiAlias = 4&
        SmoothingModeAntiAlias8x8 = 5&
    End Enum
    
    Public Declare Function GdipSetSmoothingMode Lib "GdiPlus.dll" (ByVal GpGraphics As Long, ByVal SmoothingMode As SmoothingModeEnum) As Long
    Public Declare Function GdipDrawEllipseI Lib "GdiPlus.dll" (ByVal GpGraphics As Long, ByVal GpPen As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    
    
    
    Last edited by Elroy; Yesterday at 11:59 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    To draw the anti-aliased figures is not the problem, GDI+ does that.
    The issue is to set the apha transparency of a window to individual pixel level.
    I've never saw Windows doing that, but it seems possible according to what I've read.
    I'll look to laVolpe's apha image to see.

    Edit: no... the alpha image control is windowless.
    Last edited by Eduardo-; Yesterday at 12:04 PM.

  21. #21
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,013

    Re: [VB6] Windowed Shape Control

    @Eduardo: Hmmm, you're correct. I just tried the Alpha Image Control, tried turning off the WindowLess property, but it broke it. If he so desires, I'll let LaVolpe explain why that happened.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  22. #22
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    To draw the anti-aliased figures is not the problem, GDI+ does that.
    The issue is to set the apha transparency of a window to individual pixel level.
    I've never saw Windows doing that, but it seems possible according to what I've read.
    As mentioned by wqweto, It's the UpdateLayeredWindow API you are looking for. That API is passed a DC in which you will have a 32bpp premultiplied bitmap. This bitmap is drawn onto by GDI+ for example. I think there are examples on this site for its usage. The typical steps are:

    1) Create a memory DC, add a 32bpp DIB into it (same size as the target window), draw onto the DIB what the window should look like. Ensure 32bpp premultiplied format. GDI+ does that automatically when rendering to a GDI hDC with a 32bpp DIB selected into it.

    2) Call SetWindowLong to apply the WS_EX_LAYERED style bit to the target window

    3) Call UpdateLayeredWindow and assign the hDC and set optional blending/opacity values.

    4) When done with the window, destroy the memory DC & bitmap. If the window is resized, you'll need to repeat steps 1 & 3 above
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,338

    Re: [VB6] Windowed Shape Control

    I could not find anything more or less ready to run, the closest I found was this post form xxdoc123 and the Module1.bas file in the attachment of this post (Module1.bas is not loaded when the downloaded project is opened in the IDE) from LeandroA.
    Both seem to be more or less the same but for parent windows (for forms).

    Another issue will be to generate by code the 32 bits bitmap, mainly the alpha channel info with the data of the image generated by the GDI+ API calls that make the circle and whatebver other figure.

    But since I'm doing it for fun, I think I'll have to wait for another moment when I need to have more fun than now.

  24. #24
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    17,601

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    I could not find anything more or less ready to run, the closest I found was this post form xxdoc123...

    Both seem to be more or less the same but for parent windows (for forms).
    That was a good example to learn from. Though it deals with forms, in Win8 and higher, it can be applied to child windows too. It does not address resizing. Windows uses whatever hdc/bitmap you assign, so if you don't recreate the bitmap each time the window is resized, there will be no visual change.

    Quote Originally Posted by Eduardo- View Post
    Another issue will be to generate by code the 32 bits bitmap, mainly the alpha channel info with the data of the image generated by the GDI+ API calls that make the circle and whatebver other figure.
    If using GDI+ to draw the shape, likely with its various path functions but regardless which, the alpha channel is taken care of as long as you set up the rendering commands correctly: high quality rendering, optional smoothing modes, etc

    Quote Originally Posted by Eduardo- View Post
    But since I'm doing it for fun, I think I'll have to wait for another moment when I need to have more fun than now.
    Understandable
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  25. #25
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,953

    Re: [VB6] Windowed Shape Control

    Quote Originally Posted by Eduardo- View Post
    Another issue will be to generate by code the 32 bits bitmap, mainly the alpha channel info with the data of the image generated by the GDI+ API calls that make the circle and whatebver other figure.

    But since I'm doing it for fun, I think I'll have to wait for another moment when I need to have more fun than now.
    Until such a 32Bit Premultiplied GDI+ Surface-wrapper-class is implemented by someone,
    you can experiment with a Cairo-Surface instead (which wraps the same thing).

    Below is such a Cairo-based implementation of a windowed Shape-Control (which supports all Members of VBs ShapeConstants-Enum),
    in case you want to try out, how the rest of the implementation behaves with the 3 needed imports from User32.dll

    Into a VB-UserControl, named e.g ucShapeWin8Plus:

    Code:
    Option Explicit
    
    Private Declare Function SetWindowLongW Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLongW Lib "user32" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private  Declare Function UpdateLayeredWindow Lib "user32" (ByVal hWnd As Long,  ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long,  pptSrc As Any, ByVal crKey As Long, pblend As Any, ByVal dwFlags As  Long) As Long
    
    Private Srf As cCairoSurface
    Public BorderWidth As Double, BorderColor As Long, Shape As ShapeConstants, Radius As Double, Alpha As Double
    
    Private Sub UserControl_Initialize()
      Const GWL_EXSTYLE = -20, WS_EX_LAYERED = &H80000
      SetWindowLongW hWnd, GWL_EXSTYLE, GetWindowLongW(hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
      BorderWidth = 2 'ensure a few Property-defaults
      BorderColor = vbRed
      Shape = vbShapeOval
      Alpha = 1
    End Sub
    
    Private Sub UserControl_Resize()
      ScaleMode = vbPixels
      Set Srf = Cairo.CreateWin32Surface(ScaleWidth, ScaleHeight) 'recreate the backbuf-Srf on resize
      Refresh
    End Sub
    
    Public Sub Refresh()
      RedrawOn Srf.CreateContext
      LayerUpdate
    End Sub
    
    Private Sub RedrawOn(CC As cCairoContext)
      CC.Operator = CAIRO_OPERATOR_CLEAR: CC.Paint 'clear the previous contents
      CC.Operator = CAIRO_OPERATOR_OVER 'restore the default-blending-operator
      
      Dim w, h, x, y, dx, dy
      w = Srf.Width: h = Srf.Height
      If Shape Mod 2 Then Cairo.CalcAspectFit 1, w, h, x, y, dx, dy
      If Radius = 0 Then Radius = BorderWidth * 4
      
      CC.SetLineWidth BorderWidth
      Select Case Shape
        Case vbShapeRectangle:        CC.Rectangle 0, 0, w, h, True
        Case vbShapeSquare:           CC.Rectangle x, y, dx, dy, True
        Case vbShapeOval:             CC.Ellipse w / 2, h / 2, w, h, True
        Case vbShapeCircle:           CC.Ellipse w / 2, h / 2, dx, dy, True
        Case vbShapeRoundedRectangle: CC.RoundedRect 0, 0, w, h, Radius, True
        Case vbShapeRoundedSquare:    CC.RoundedRect x, y, dx, dy, Radius, True
      End Select
      
      CC.Stroke , Cairo.CreateSolidPatternLng(BorderColor)
    End Sub
    
    Private Function LayerUpdate()
      Const ULW_ALPHA = &H2
      Dim sz(0 To 1) As Long
          sz(0) = Srf.Width: sz(1) = Srf.Height
      UpdateLayeredWindow hWnd, hDC, ByVal 0&, sz(0), Srf.GetDC, 0@, 0, CLng(&H10000 * (256 + Alpha * 255)), ULW_ALPHA
    End Function
    HTH

    Olaf

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width