|
-
February 4th, 2000, 11:41 AM
#1
Custom shaped forms
Is it possible to create a form of an other shape then rectangular?
eg. I want to make a round form, or triangle
I have seen this once using API's, but I haven't got the smallest clue on how to do this.
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
-
February 9th, 2000, 11:50 AM
#2
Re: Custom shaped forms
Yes - create a region and then use the SetWindowRegion to reshape it. For example, the following will make any window (vb or other) christmas tree shaped:
public Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint as POINTAPI, byval nCount as Long, byval nPolyFillMode as Long) as Long
public Declare Function SetWindowRgn Lib "user32" (byval hwnd as Long, byval hRgn as Long, byval bRedraw as Boolean) as Long
public Type POINTAPI
X as Long
Y as Long
End Type
private m_Hwnd as Long
private mWndRect as RECT
private mRegion as Long
'\\ --[RefreshRect]--------------------------------------------------
'\\ Refreshes the window rectangle, as size can change....
'\\ -----------------------------------------------------------------
private Sub RefreshRect()
Dim lret as Long
lret = GetWindowRect(m_Hwnd, mWndRect)
End Sub
'\\ --[MakeTreeShaped]------------------------------------
'\\ Makes the window tree shapes and forces it to repaint
'\\ itself
'\\ ------------------------------------------------------
public Sub MakeTreeShaped()
Dim XMasTree() as POINTAPI
Dim wndWidth as Long
Dim wndHeight as Long
Dim hRegion as Long
If m_Hwnd > 0 then
Call RefreshRect
ReDim XMasTree(0 to 11) as POINTAPI
wndWidth = mWndRect.Right - mWndRect.Left
wndHeight = mWndRect.Bottom - mWndRect.Top
'\\ Start at top...
XMasTree(0).X = wndWidth / 2
XMasTree(0).Y = 0
XMasTree(1).X = 0
XMasTree(1).Y = wndHeight / 3
XMasTree(2).X = wndWidth / 3
XMasTree(2).Y = wndHeight / 3
XMasTree(3).X = 0
XMasTree(3).Y = 2 * (wndHeight / 3)
XMasTree(4).X = wndWidth / 3
XMasTree(4).Y = 2 * (wndHeight / 3)
XMasTree(5).X = wndWidth / 3
XMasTree(5).Y = wndHeight
XMasTree(6).X = 2 * (wndWidth / 3)
XMasTree(6).Y = wndHeight
XMasTree(7).X = 2 * (wndWidth / 3)
XMasTree(7).Y = 2 * (wndHeight / 3)
XMasTree(8).X = wndWidth
XMasTree(8).Y = 2 * (wndHeight / 3)
XMasTree(9).X = 2 * (wndWidth / 3)
XMasTree(9).Y = wndHeight / 3
XMasTree(10).X = wndWidth
XMasTree(10).Y = wndHeight / 3
XMasTree(11).X = wndWidth / 2
XMasTree(11).Y = 0
'\\ Create this polygon region
mRegion = CreatePolygonRgn(XMasTree(0), 12, 1)
If mRegion > 0 then
lret = SetWindowRgn(m_Hwnd, mRegion, true)
If lret = 0 then
Debug.print "SetWindowRgn failed"
End If
IsTreeShaped = true
else
Debug.print "Failed to make region!"
End If
End If
End Sub
I can send you the full code to the project if you wish - also features some smart subclassing examples....
HTH,
Duncan Jones
ClearCode Developments Ltd
-
February 9th, 2000, 01:49 PM
#3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|