Results 1 to 32 of 32

Thread: [RESOLVED] Need some help with obscure shaped forms API

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Resolved [RESOLVED] Need some help with obscure shaped forms API

    Hey guys,

    The API here: http://www.vbforums.com/showpost.php...27&postcount=5 allows you to do custom shaped forms, namely rectangular with rounded edges. It works well, it's easy and lightweight and I use it often.

    When you [uncomment] and apply your needed parameters to one of the hRgn lines, it will round the corners based off of your given values

    Code:
    hRgn = CreateRoundRectRgn(0, 0, w, h, 9, 9)
    Imagine you have a form with rounded corners like this; http://img507.imageshack.us/img507/2479/form1sp2.jpg - A result of something using the code I just pasted above.

    My question is, how can I tell it to crop my form like this as well: http://img53.imageshack.us/img53/8035/form2tv5.jpg

    My natural assumption was to modify the above code to something like this:

    hRgn = CreateRoundRectRgn(0, 120, w, h, 9, 9)
    But by doing this it cropped off the top portion. Then it looked like this, http://img132.imageshack.us/img132/9818/form3qo5.jpg

    Again, the way I want it to look is like this: http://img53.imageshack.us/img53/8035/form2tv5.jpg

    I understand thats not how this API is supposed to work, and it is only doing what it thinks it should by giving me undesired effects, but I was wondering what I can do to modify or add this ability.

    Sorry if I didn't explain well, I tried to make it easy to understand with basic pictures and stuff. Any responses would be great and much appreciated!

    Thanks!!

    David

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    You probably have to make two API calls. Remember that your first 4 arguments are the coordinates of the rectangle area to "round" So figure out the coords for the center 1/2 up and create two 1/4 rounds, once for each side of the form.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    You mean like:

    Code:
        hRgn = CreateRoundRectRgn(0, 0, w, 125, 9, 9)
        hRgn = CreateRoundRectRgn(0, 125, w, h, 9, 9)
    That produces this effect: http://img132.imageshack.us/img132/9818/form3qo5.jpg

    It only applies the second line.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    You would also need to call the calls on #67 and 68 inbetween each CreateRectanglregion or use separate return vars as you dont want to be working on the same regions or you will clear the first region with teh second.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Something like this? (Same effect is happening still)

    Code:
        hRgn = CreateRoundRectRgn(0, 0, w, 125, 9, 9)
        
        Call SetWindowRgn(Me.hwnd, hRgn, True)
        Call DeleteObject(hRgn)
        
        hRgn2 = CreateRoundRectRgn(0, 125, w, h, 9, 9)
        
            Call SetWindowRgn(Me.hwnd, hRgn2, True)
        Call DeleteObject(hRgn2)

  6. #6
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Need some help with obscure shaped forms API

    I think you might want to play with CombineRgn

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    What i've been doing has worked well, is there any way we can continue on with what Rob was talking about? I get the idea my above code was just done incorrectly, but would work otherwise?

    Thanks

  8. #8
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Need some help with obscure shaped forms API

    Actually the only easy way to combine two regions is CombineRgn so use what you have learned with Rob with that and you are sorted. It's an easy API.

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    @Milk, yea its probably about the same difficulity but thats another API for him to learn.

    We could use two separate regions to get the desired effect and it wouldnt be a combation either. If you look at the design its basically two horizontal rounded rectangles. so two calls with the proper coords and done
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Lol I really don't mean to bother you guys, as I've stated before I know that the point of a forum is to learn, not have things done. So I definitely try before I run in and say "Can you all fix and code this for me?" or "Yes! / No!!!" twenty times in a row (sound familiar? :P)

    In conclusion, could you help me a bit more with how I could combine the two rounded rectangles? :P

    Thanks, I really do appreciate it.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    This is what Im trying to get you to see. Its just two calls to create two separate rounded regions.

    I'm not 100% sure if it will need to be combined after (in case of dragging a form type functionality etc) but either way this is your regions. If you need to combine them or not.
    (Sorry the picture cut off 1 pixel too short at the top and left sides lol
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Lol okay, but I dont understand why this, with its own separate calls to the API, won't work;

    Code:
        hRgn = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        
        Call SetWindowRgn(Me.hwnd, hRgn, True)
        Call DeleteObject(hRgn)
        
        hRgn = CreateRoundRectRgn(0, 140, w, h, 9, 9)
        
        Call SetWindowRgn(Me.hwnd, hRgn, True)
        Call DeleteObject(hRgn)

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    Maybe it doesnt allow more then one region thus the CombinRegn call I guess. Seems lame that it would restrict you to have only one region
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    I keep getting an Argument Not Optional error.

    Code:
    Private Sub Form_Resize()
    Dim hRgn As Long, w As Long, h As Long, hRgn2 As Long
    Dim retval As Long  ' return value
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
    
        'Square Window
        'hRgn = CreateRectRgn(0, 0, w \ 2, h \ 2)
        
        'Elliptical Window
        'hRgn = CreateEllipticRgn(0, 0, w, h)
        
        'Square Window with round corners
        hRgn = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        
        Call SetWindowRgn(Me.hwnd, hRgn, True)
        Call DeleteObject(hRgn)
        
        hRgn2 = CreateRoundRectRgn(0, 140, w, h, 9, 9)
        
        Call SetWindowRgn(Me.hwnd, hRgn2, True)
        Call DeleteObject(hRgn2)
        
        retval = CombineRgn(hRgn1, hRgn2, RGN_XOR)
        retval = CombineRgn(hRgn1, hRgn2, RGN_AND)
        
        retval = DeleteObject(hRgn1)
        retval = DeleteObject(hRgn2)
        
        'Polygon shaped window
        'p(0).x = w / 2
        'p(0).y = 0
        'p(1).x = w
        'p(1).y = h / 2
        'p(2).x = w / 2
        'p(2).y = h
        'p(3).x = 0
        'p(3).y = h / 2
        
        'hRgn = CreatePolygonRgn(p(0), 4, 1)
        
    
    
    End Sub

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Heres a version I think might be less screwed up. :-p But with this, I get no errors, but after my splashscreen the main form only flashes for a second but disappears:

    Code:
    Private Sub Form_Resize()
    Dim hRgn As Long, w As Long, h As Long, hRgn2 As Long
    Dim retval As Long  ' return value
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
    
        'Square Window
        'hRgn = CreateRectRgn(0, 0, w \ 2, h \ 2)
        
        'Elliptical Window
        'hRgn = CreateEllipticRgn(0, 0, w, h)
        
        'Square Window with round corners
        
        hRgn = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        hRgn2 = CreateRoundRectRgn(0, 140, w, h, 9, 9)
    
        hAndRgn = CreateRectRgn(0, 0, 0, 0)  ' meaningless initialization
    
        Call CombineRgn(hAndRgn, hRgn1, hRgn2, RGN_AND)
         
        Call SetWindowRgn(Me.hwnd, hAndRgn, True)
        
        Call DeleteObject(hRgn1)
        Call DeleteObject(hRgn2)
        
        'Polygon shaped window
        'p(0).x = w / 2
        'p(0).y = 0
        'p(1).x = w
        'p(1).y = h / 2
        'p(2).x = w / 2
        'p(2).y = h
        'p(3).x = 0
        'p(3).y = h / 2
        
        'hRgn = CreatePolygonRgn(p(0), 4, 1)
        
    
    
    End Sub

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    Your missing arguments in the combine api.
    Code:
    Option Explicit
    
    Private Declare Function CreateRectRgn Lib "gdi32" ( _
                        ByVal X1 As Long, _
                        ByVal Y1 As Long, _
                        ByVal X2 As Long, _
                        ByVal Y2 As Long) As Long
    
    Private Declare Function CreateRoundRectRgn Lib "gdi32" ( _
                        ByVal X1 As Long, _
                        ByVal Y1 As Long, _
                        ByVal X2 As Long, _
                        ByVal Y2 As Long, _
                        ByVal X3 As Long, _
                        ByVal Y3 As Long) As Long
                                                             
    Private Declare Function SetWindowRgn Lib "user32" ( _
                        ByVal hWnd As Long, _
                        ByVal hRgn As Long, _
                        ByVal bRedraw As Boolean) As Long
                        
    Private Declare Function CreatePolygonRgn Lib "gdi32" ( _
                        lpPoint As POINT, _
                        ByVal nCount As Long, _
                        ByVal nPolyFillMode As Long) As Long
                        
    Private Declare Function DeleteObject Lib "gdi32" ( _
                        ByVal hObject As Long) As Long
    
    Private Declare Function CombineRgn Lib "gdi32.dll" ( _
                        ByVal hDestRgn As Long, _
                        ByVal hSrcRgn1 As Long, _
                        ByVal hSrcRgn2 As Long, _
                        ByVal nCombineMode As Long) As Long
    
    Private Type POINT
        x As Long
        y As Long
    End Type
    
    Private Const ALTERNATE = 1
    Private Const WINDING = 2
    Private Const RGN_AND As Long = 1
    Private Const RGN_XOR As Long = 3
    
    Private Sub Form_Resize()
    Dim hRgn1 As Long, w As Long, h As Long, hRgn2 As Long
    Dim retval As Long  ' return value
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
        
        'Square Window with round corners
        hRgn1 = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        
        Call SetWindowRgn(Me.hWnd, hRgn1, True)
        Call DeleteObject(hRgn1)
        
        hRgn2 = CreateRoundRectRgn(0, 140, w, h, 9, 9)
        
        Call SetWindowRgn(Me.hWnd, hRgn2, True)
        Call DeleteObject(hRgn2)
        
        retval = CombineRgn(YouNeedAhRgnDestinationVariableHere, hRgn1, hRgn2, RGN_XOR)
        retval = CombineRgn(YouNeedAhRgnDestinationVariableHere, hRgn1, hRgn2, RGN_AND)
        
        retval = DeleteObject(hRgn1)
        retval = DeleteObject(hRgn2)
        
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Lol What a mess... Ok heres what I have now.. I did have the arguments up there, btw... Now I'm back to only getting the bottom half showing up:

    Code:
    Private Sub Form_Resize()
    Dim hRgn1 As Long, w As Long, h As Long, hRgn2 As Long
    Dim retval As Long  ' return value
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
        
        'Square Window with round corners
        
        hXorRgn = CreateRectRgn(0, 0, 0, 0)
        hAndRgn = CreateRectRgn(0, 0, 0, 0)
      
        hRgn1 = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        hRgn2 = CreateRoundRectRgn(0, 140, w, h, 9, 9)
        
        Call SetWindowRgn(Me.hWnd, hRgn2, True)
        
        Call CombineRgn(hXorRgn, hRgn1, hRgn2, RGN_XOR)
        Call CombineRgn(hAndRgn, hRgn1, hRgn2, RGN_AND)
        
        Call DeleteObject(hRgn1)
        Call DeleteObject(hRgn2)
        Call DeleteObject(hXorRgn)
        Call DeleteObject(hAndRgn)
        
    End Sub

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    You may be needing to call the SetWindowRgn on the combined region and not just the one
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Ok I just tried multiple variations but none seemed to do the trick, all of them in fact just result in the form flashing for a split second then hiding upon load. I appreciate all your help, you're probably wondering how I get out of bed in the morning by now! :-p

    Code:
    Private Sub Form_Resize()
    Dim hRgn1 As Long, w As Long, h As Long, hRgn2 As Long
    Dim retval As Long  ' return value
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
        
        'Square Window with round corners
        
        hXorRgn = CreateRectRgn(0, 0, 0, 0)
        hAndRgn = CreateRectRgn(0, 0, 0, 0)
      
        hRgn1 = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        hRgn2 = CreateRoundRectRgn(0, 140, w, h, 9, 9)
        
        Call SetWindowRgn(Me.hWnd, hRgn1, True)
        Call SetWindowRgn(Me.hWnd, hRgn2, True)
        Call SetWindowRgn(Me.hWnd, hXorRgn, True)
        Call SetWindowRgn(Me.hWnd, hAndRgn, True)
        
        Call CombineRgn(hXorRgn, hRgn1, hRgn2, RGN_XOR)
        Call CombineRgn(hAndRgn, hRgn1, hRgn2, RGN_AND)
        
        Call DeleteObject(hRgn1)
        Call DeleteObject(hRgn2)
        Call DeleteObject(hXorRgn)
        Call DeleteObject(hAndRgn)
        
    End Sub

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Need some help with obscure shaped forms API

    Not really as I dont do much of this type of stuff either.

    You have variables that are not efined. Always use Option Explicit


    hXorRgn and hAndRgn
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Defined the variables, still didn't work.

    4 instances of "SetWindowRgn" seems like a lot to me, but I have no idea what I'm doing here, on the other hand. :-p

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Ok I've been sitting here trying to get this work for hours straight, lol. I'm just going to post everything I've got that pertains to this, and someone who is knowledgeable on this will hopefully be able to go through it with a fine-tooth comb

    I would like hRgn1 to be the first source to be merged, hRgn2 being the second - hAndRgn is the target, or destination source.

    Declarations; A few are unrelated to this issue and used for other things.
    VB6 Code:
    1. Private Const ERROR = 0
    2. Private Const NULLREGION = 1
    3. Private Const SIMPLEREGION = 2
    4. Private Const COMPLEXREGION = 3
    5. Private Const RGN_AND = 1
    6. Private Const RGN_OR = 2
    7. Private Const RGN_XOR = 3
    8. Private Const RGN_DIFF = 4
    9. Private Const RGN_COPY = 5
    10. Private Const GWL_STYLE = (-16)
    11. Private Const WS_MINIMIZEBOX = &H20000
    12. Private Declare Function CreateRectRgn Lib "gdi32" ( _
    13.                     ByVal X1 As Long, _
    14.                     ByVal Y1 As Long, _
    15.                     ByVal X2 As Long, _
    16.                     ByVal Y2 As Long) As Long
    17.  
    18. Private Declare Function CreateRoundRectRgn Lib "gdi32" ( _
    19.                     ByVal X1 As Long, _
    20.                     ByVal Y1 As Long, _
    21.                     ByVal X2 As Long, _
    22.                     ByVal Y2 As Long, _
    23.                     ByVal X3 As Long, _
    24.                     ByVal Y3 As Long) As Long
    25.                                                          
    26. Private Declare Function SetWindowRgn Lib "user32" ( _
    27.                     ByVal hWnd As Long, _
    28.                     ByVal hRgn As Long, _
    29.                     ByVal bRedraw As Boolean) As Long
    30.                    
    31. Private Declare Function CreatePolygonRgn Lib "gdi32" ( _
    32.                     lpPoint As POINT, _
    33.                     ByVal nCount As Long, _
    34.                     ByVal nPolyFillMode As Long) As Long
    35.                    
    36. Private Declare Function DeleteObject Lib "gdi32" ( _
    37.                     ByVal hObject As Long) As Long
    38.  
    39. Private Declare Function CombineRgn Lib "gdi32.dll" ( _
    40.                     ByVal hAndRgn As Long, _
    41.                     ByVal hRgn1 As Long, _
    42.                     ByVal hRgn2 As Long, _
    43.                     ByVal RGN_AND As Long) As Long
    44.  
    45.  
    46. Private Type POINT
    47.     x As Long
    48.     y As Long
    49. End Type
    50.  
    51. Private Const ALTERNATE = 1
    52. Private Const WINDING = 2

    Form_Resize()

    I've commented out a few of the Call SetWindowRgn lines, because I don't know which to use, none of them seem to work, in any combination.

    Code:
    Dim hRgn1 As Long, hRgn2 As Long
    Dim w As Long, h As Long
    Dim hXorRgn As Long, hAndRgn As Long
    
    Dim p(0 To 3) As POINT
    
        w = ScaleX(Me.Width, Me.ScaleMode, vbPixels) - 1
        h = ScaleY(Me.Height, Me.ScaleMode, vbPixels) - 1
        
        'Square Window with round corners
            
        hAndRgn = CreateRoundRectRgn(0, 0, 0, 0, 9, 9)
        hRgn1 = CreateRoundRectRgn(0, 0, w, 145, 9, 9)
        hRgn2 = CreateRoundRectRgn(0, 140, w, h, 9, 9)
        
        'Call SetWindowRgn(Me.hWnd, hRgn1, True)
        'Call SetWindowRgn(Me.hWnd, hRgn2, True)
        'Call SetWindowRgn(Me.hWnd, hXorRgn, True)
        Call SetWindowRgn(Me.hWnd, hAndRgn, True)
        
        Call CombineRgn(hAndRgn, hRgn1, hRgn2, RGN_AND)  ' intersection
        
        Call DeleteObject(hRgn1)
        Call DeleteObject(hRgn2)
        Call DeleteObject(hAndRgn)

  23. #23
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Need some help with obscure shaped forms API

    I think this is what you need. There is a small mistake in Crptcblades code, once set to a window regions should not be deleted. An exception to the usual GDI delete all your objects when finished with rule.
    Code:
    Option Explicit
    Private Const RGN_OR = 2
    
    Private Declare Function CreateRoundRectRgn Lib "gdi32" ( _
                        ByVal X1 As Long, _
                        ByVal Y1 As Long, _
                        ByVal X2 As Long, _
                        ByVal Y2 As Long, _
                        ByVal X3 As Long, _
                        ByVal Y3 As Long) As Long
                                                             
    Private Declare Function SetWindowRgn Lib "user32" ( _
                        ByVal hWnd As Long, _
                        ByVal hRgn As Long, _
                        ByVal bRedraw As Boolean) As Long
                        
    Private Declare Function DeleteObject Lib "gdi32" ( _
                        ByVal hObject As Long) As Long
    
    Private Declare Function CombineRgn Lib "gdi32.dll" ( _
                        ByVal hDestRgn As Long, _
                        ByVal hRgnSrc1 As Long, _
                        ByVal hRgnSrc2 As Long, _
                        ByVal nCombineMode As Long) As Long
    
    
    Private Sub Form_Load()
    Dim hRgn As Long, hRgnTmp As Long
    Dim w As Long, h As Long
    Const CORNERSZ = 16
    
       w = ScaleX(Width, ScaleMode, vbPixels)
       h = ScaleY(Height, ScaleMode, vbPixels)
       
       'Two rectangular regions with round corners
       hRgn = CreateRoundRectRgn(0, 0, w, h \ 2, CORNERSZ, CORNERSZ) 'Create the top region
       If hRgn Then
          hRgnTmp = CreateRoundRectRgn(0, h \ 2, w, h, CORNERSZ, CORNERSZ) 'Create the bottom region
          If hRgnTmp Then
             CombineRgn hRgn, hRgn, hRgnTmp, RGN_OR 'Combine using Or (union) into the first region
             SetWindowRgn hWnd, hRgn, True 'Apply the new combined region
             DeleteObject hRgnTmp 'Delete the unused region
             'Don't delete the used region (it won't error, it just won't work, it's now owned by the system not the program)
          Else
             DeleteObject hRgn 'something has failed, delete the unused region
          End If
       End If
    
    End Sub

  24. #24

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: Need some help with obscure shaped forms API

    Ah that's great!!! Thanks a ton. I'll be messing with this more tomorrow, I've done so much programming today in Javascript and PHP, (and struggling with VB the past couple hours), that I've seemed to have lost any depth perception in my sight. :P I can only take so much staring at syntax highlights in a day. Lol, thanks a bunch.

    I appreciate it guys!

    David

  25. #25
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Need some help with obscure shaped forms API

    Good job Milk

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  26. #26

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: [RESOLVED] Need some help with obscure shaped forms API

    Just wondering, it appears there are not enough supplied arguments to use combineRgn for anymore than three (or two sources) at a time, is that true?

    So to add more I'd have to do two separate combineRgn's, then combineRgn those? Just wanting to make sure, before I make a huge mess of this project for nothing. :P

  27. #27
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Need some help with obscure shaped forms API

    To me it looks like you would be appending one region as your main source with each new region with the combignregn api. So separate calls appending one to the main. I could be wrong as graphics are not my main area.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  28. #28
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: [RESOLVED] Need some help with obscure shaped forms API

    That sounds right.

    There are a few more region GDI API's that enable creation of more complex regions with one call...
    CreatePolygonRgn
    CreatePolyPolygonRgn
    ExtCreateRegion

    ExtCreateRegion is arguably the most powerful (and the hardest to use)

    If you only want to combine a handful of regions CombineRgn is probably still the best way to go.

    Just in case you did not know you can apply regions to any windowed control (one with a hWnd.)

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: [RESOLVED] Need some help with obscure shaped forms API

    Thanks again.

    VB6 is pretty sweet. I am head of the development department at a company which is predominantly web-based development. I sit and do PHP, javascript, but most of all graphic design all day. So when I was assigned this VB6 project for a new brand we're doing, I got overwhelmed a bit, and although I've had my fair share of trouble, it's really been fun and great, and very powerful!

    Thanks guys

  30. #30
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Need some help with obscure shaped forms API

    Small off topic question: Why didnt they do it in VB.NET?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  31. #31

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2008
    Posts
    268

    Re: [RESOLVED] Need some help with obscure shaped forms API

    That was my initial question, I guess its because the biggest demographic for this software will likely not have .NET 2.0 or above. I've messed with VS.net 2008 a good amount on my own time, and it seems some of these things I've had to learn quite a bit about to do in VB6 are easily done in .NET

  32. #32
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Need some help with obscure shaped forms API

    Yea like using the GDI+ classes to do this would have been alot easier. But anyways thanks for answering my question
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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