Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay tips in a rounded popup form
DescriptionThis example shows how to display tips in a rounded popup form in Visual Basic 6. It uses the CreateRoundRectRgn API function to make a rounded rectangle region for the form and then uses the SetWindowRgn API function to restrict the form to that region.
Keywordsform, help, tip, rounded rectangle, region, SetWindowRgn
CategoriesControls, Software Engineering, API
 
Thanks to Norm LaBine.

The program uses the CreateRoundRectRgn API function to make a rounded rectangle region for the form and then uses the SetWindowRgn API function to restrict the form to that region.

 
Private Sub Form_Load()
    Me.AlwaysOnTop = True
    Dim lRet As Long
    ' DrawText is a Normal Integer Call, not a Long.
    Dim iDrawTxt As Integer, sHelp As String
    ' Region dimensions X1/X2, Y1/Y2
    Dim lTipWidth As Long, lTipHeight As Long
    ' Corner Radius for the round rectangle.
    Dim lCorner As Long

    ' All the tip and form parameters, have
    ' been set in the SetHelpText function, so
    ' we can say the loading is happening.
    gbTipLoaded = True
    frmMain.sbWizard.Caption = "Double-Click the Tip window " & _
        "to close it."

    ' Corner radius in Points. Its a rounded rectangle
    ' so the API wants this factor, adjust to suit.
    ' It could also be adjusted, depending on Screen
    ' Metrics.
    lCorner = 36

    Me.Left = Screen.Width - Me.Width
    Me.Top = Screen.Height - (Me.Height + 400)
    lTipWidth = Me.ScaleWidth
    lTipHeight = Me.ScaleHeight

    ' System colors can't be set at Design time, so let the
    ' OS tell us.
    Me.BackColor = vbInfoBackground
    Me.ForeColor = vbInfoText

    ' Set up the Text drawing rectangle.
    tipRC.Top = lCorner / 2
    tipRC.Left = lCorner / 2
    tipRC.Right = Me.ScaleWidth - lCorner / 2
    tipRC.Bottom = Me.ScaleHeight - lCorner / 2

    mlTipBox = CreateRoundRectRgn(0, 0, lTipWidth, _
        lTipHeight, lCorner, lCorner)

    hBrush = CreateSolidBrush(vbDesktop)
    lRet = FrameRgn(Me.hDC, mlTipBox, hBrush, 3, 3)
    lRet = SetWindowRgn(Me.hWnd, mlTipBox, True)
    'LoadFormMsgs
    ' Get the help text for this call.
    sHelp = gsHelp(TipID)

    ' If the text string is Null Terminated, this -1
    ' version is ok.
    ' Check the SDK or Dan Appleman's 32-bit API Guide for
    ' other DT_variations.
    'iDrawTxt = DrawText(hDC, sHelp, -1, tipRC,
    ' DT_WORDBREAK)

    ' If its from a file or other, better use its length
    ' (Len(sHelp).
    ' This first call sets up to calculate the drawn size.
    ' DT_CALCRECT constant.
    iDrawTxt = DrawText(hDC, sHelp, Len(sHelp), tipRC, _
        DT_LEFT Or DT_CALCRECT Or DT_WORDBREAK)
    Me.Refresh ' This clears the drawing area of any e-junk
        ' from this above.

    ' This second one draws it.
    iDrawTxt = DrawText(hDC, sHelp, Len(sHelp), tipRC, _
        DT_LEFT Or DT_WORDBREAK)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated