Click to See Complete Forum and Search --> : Paint


Steve Scott
October 15th, 2001, 09:56 AM
I need to findout how to create a eliptical button using VB, Im assuming I have to handle the Paint message, but thats about all I know.

Does anyone know if a tutorial exsits?

Thanks,
Steve

Clearcode
October 15th, 2001, 10:22 AM
You can alter the shape of any window, including a button, using the SetWindowRgn API call. To specify an elliptical region, use the CreateEllipticRgn


'\\ Declarations...
Declare Function CreateEllipticRgn Lib "gdi32" Alias "CreateEllipticRgn" (byval X1 as Long, byval Y1 as Long, byval X2 as Long, byval Y2 as Long) as Long

Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (byval hWnd as Long, byval hRgn as Long, byval bRedraw as Boolean) as Long




See http://www.merrioncomputing.com/vb_win_shape.htm for an example.



-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.

Cimperiali
October 15th, 2001, 10:45 AM
...already out of votes. Sorry, Guru.


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater

Steve Scott
October 20th, 2001, 05:01 PM
How do I obtain an handle to the Button in my AX Control to pass down to SetWindowRgn?

Is that what sets the shape, or do I have to have the button equal the function (cmdButton = SetWindowRgn(...) )?

Additionally should I even be doing this in Paint? Setting the Region should be done only once, correct?

Thanks,
Steve

Steve Scott
October 21st, 2001, 07:49 PM
Ok, Im trying to test this, but im not having any luck. I get no errors, but the form doesnt showup...The program showsup in the taskbar, but when it has the focus there isnt anything there (like its invisable)

Heres what I have...
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 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 Sub Form_Initialize()
Region = CreateEllipticRgn(0, 0, Form1.Width, Form1.Height)
lret = SetWindowRgn(Form1.hWnd, Region, True)
End Sub

Any ideas?
Thanks,
Steve

Clearcode
October 22nd, 2001, 02:20 AM
I don't think that you can call SetWindowRgn duroing the form_initialize() event as at that stage there is no graphical manifestation of the form.

Try moving the code to the form_load event, and also check that your region is valid before calling SetWindowRgn:


private Sub Form_Load()
Dim hRgn as Long
Dim lRet as Long

hRgn = CreateEllipticRgn(0,0,(Form.Width * Screen.TwipsPerPixelX),(Form.Height * Screen.TwipsPerPixelY))

If hRgn <> 0 then
lRet = SetWindowRgn(form1.hwnd, hRgn, true)
else
Debug.print Err.LastDllError
End If

End Sub




HTH,
D.

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.