CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Paint

  1. #1
    Join Date
    Jun 2001
    Location
    Newcastle Ontario, Canada
    Posts
    118

    Paint

    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


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Paint

    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.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    As usual...

    ...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
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    Jun 2001
    Location
    Newcastle Ontario, Canada
    Posts
    118

    Re: Paint

    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


  5. #5
    Join Date
    Jun 2001
    Location
    Newcastle Ontario, Canada
    Posts
    118

    Re: Paint

    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


  6. #6
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Paint

    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 &lt;&gt; 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.
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured