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!
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.
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.
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?
@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.
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
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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
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.
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
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
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:
Private Const ERROR = 0
Private Const NULLREGION = 1
Private Const SIMPLEREGION = 2
Private Const COMPLEXREGION = 3
Private Const RGN_AND = 1
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Const RGN_DIFF = 4
Private Const RGN_COPY = 5
Private Const GWL_STYLE = (-16)
Private Const WS_MINIMIZEBOX = &H20000
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 hAndRgn As Long, _
ByVal hRgn1 As Long, _
ByVal hRgn2 As Long, _
ByVal RGN_AND As Long) As Long
Private Type POINT
x As Long
y As Long
End Type
Private Const ALTERNATE = 1
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)
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
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.
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
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.
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!
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