How to Use DrawFrameControl API in Visual Basic 4.0

Last reviewed: May 16, 1996
Article ID: Q141999
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0

SUMMARY

The Win32 API includes a handy function called DrawFrameControl. This function is useful for drawing many of the standard Windows 95 3D controls as graphic objects on your forms. The function only draws the controls on your form. To make these drawings behave like controls, you must add code to provide this functionality.

MORE INFORMATION

This sample demonstrates how to use the DrawFrameControl function. You create a module that declares the necessary constants and the DrawFrameControl function. The form contains code to call the function and draw the controls on your form. When you run the program, control drawings appear on the form.

  1. Start the 32-bit version of Visual Basic 4.0, or if it is already running, click New Project on the File menu.

  2. Use the following steps to create a module called DrawFram.bas.

    a. On the Insert menu, click Module. b. Copy the following code to the Module1 code window:

          '*****************************************************************
          ' DrawFram.bas - Contains API declarations and constants for the
    
          '                DrawFrameControl API function.
          '*****************************************************************
          Option Explicit
    
          Public Type RECT
             Left As Long
             Top As Long
             Right As Long
             Bottom As Long
          End Type
    
          '  flags for DrawFrameControl
    
          Public Const DFC_CAPTION = 1            'Title bar
          Public Const DFC_MENU = 2               'Menu
          Public Const DFC_SCROLL = 3             'Scroll bar
          Public Const DFC_BUTTON = 4             'Standard button
    
          Public Const DFCS_CAPTIONCLOSE = &H0    'Close button
          Public Const DFCS_CAPTIONMIN = &H1      'Minimize button
          Public Const DFCS_CAPTIONMAX = &H2      'Maximize button
          Public Const DFCS_CAPTIONRESTORE = &H3  'Restore button
          Public Const DFCS_CAPTIONHELP = &H4     'Windows 95 only:
                                                  'Help button
    
          Public Const DFCS_MENUARROW = &H0       'Submenu arrow
          Public Const DFCS_MENUCHECK = &H1       'Check mark
          Public Const DFCS_MENUBULLET = &H2      'Bullet
          Public Const DFCS_MENUARROWRIGHT = &H4
    
          Public Const DFCS_SCROLLUP = &H0               'Up arrow of scroll
                                                         'bar
          Public Const DFCS_SCROLLDOWN = &H1             'Down arrow of
                                                         'scroll bar
          Public Const DFCS_SCROLLLEFT = &H2             'Left arrow of
                                                         'scroll bar
          Public Const DFCS_SCROLLRIGHT = &H3            'Right arrow of
                                                         'scroll bar
          Public Const DFCS_SCROLLCOMBOBOX = &H5         'Combo box scroll
                                                         'bar
          Public Const DFCS_SCROLLSIZEGRIP = &H8         'Size grip
          Public Const DFCS_SCROLLSIZEGRIPRIGHT = &H10   'Size grip in
                                                         'bottom-right
                                                         'corner of window
    
          Public Const DFCS_BUTTONCHECK = &H0      'Check box
    
          Public Const DFCS_BUTTONRADIO = &H4     'Radio button
          Public Const DFCS_BUTTON3STATE = &H8    'Three-state button
          Public Const DFCS_BUTTONPUSH = &H10     'Push button
    
          Public Const DFCS_INACTIVE = &H100      'Button is inactive
                                                  '(grayed)
          Public Const DFCS_PUSHED = &H200        'Button is pushed
          Public Const DFCS_CHECKED = &H400       'Button is checked
    
          Public Const DFCS_ADJUSTRECT = &H2000   'Bounding rectangle is
                                                  'adjusted to exclude the
                                                  'surrounding edge of the
                                                  'push button
    
          Public Const DFCS_FLAT = &H4000         'Button has a flat border
          Public Const DFCS_MONO = &H8000         'Button has a monochrome
                                                  'border
    
          Public Declare Function DrawFrameControl Lib "user32" (ByVal _
             hDC&, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) _
             As Boolean
    
       c. On the File menu, click Save File and save the file as DrawFram.bas
          for the file name.
    
    

  3. Copy the following code to the Form1 Code Window:

          '********************************************************************
          ' DrawFram.frm - Demonstrates how to use DrawFrameControl
          '********************************************************************
          Option Explicit
    

          '********************************************************************
          ' Helper function that allows a you to load a rect on one line
          '********************************************************************
          Private Function MakeRect(l As Long, t As Long, w As Long, _
    
                                    h As Long) As RECT
             With MakeRect
                .Left = l
                .Top = t
                .Right = l + w
                .Bottom = t + h
             End With
    
          End Function
    
          Private Sub Form_Load()
             ScaleMode = vbPixels
             AutoRedraw = True
    
          'Captions
          DrawFrameControl hDC, MakeRect(10, 10, 15, 15), DFC_CAPTION, _
             DFCS_CAPTIONCLOSE
    
          DrawFrameControl hDC, MakeRect(10, 30, 15, 15), DFC_CAPTION, _
             DFCS_CAPTIONRESTORE
    
          DrawFrameControl hDC, MakeRect(10, 50, 15, 15), DFC_CAPTION, _
             DFCS_CAPTIONMAX Or DFCS_INACTIVE
    
          ' Menus
          DrawFrameControl hDC, MakeRect(30, 10, 15, 15), DFC_MENU, _
             DFCS_MENUARROW
    
          DrawFrameControl hDC, MakeRect(30, 30, 15, 15), DFC_MENU, _
             DFCS_MENUCHECK
    
          DrawFrameControl hDC, MakeRect(30, 50, 15, 15), DFC_MENU, _
             DFCS_MENUBULLET
    
          ' Scrollbars
          DrawFrameControl hDC, MakeRect(50, 10, 15, 15), DFC_SCROLL, _
             DFCS_SCROLLUP
    
          DrawFrameControl hDC, MakeRect(50, 30, 15, 15), DFC_SCROLL, _
             DFCS_SCROLLSIZEGRIP
    
          DrawFrameControl hDC, MakeRect(50, 50, 15, 15), DFC_SCROLL, _
             DFCS_SCROLLRIGHT Or DFCS_INACTIVE
    
          ' Checkboxes
          DrawFrameControl hDC, MakeRect(70, 10, 15, 15), DFC_BUTTON, _
             DFCS_BUTTONCHECK
    
          DrawFrameControl hDC, MakeRect(70, 30, 15, 15), DFC_BUTTON, _
             DFCS_BUTTONCHECK Or DFCS_CHECKED
    
          DrawFrameControl hDC, MakeRect(70, 50, 15, 15), DFC_BUTTON, _
             DFCS_BUTTONCHECK Or DFCS_CHECKED Or DFCS_BUTTON3STATE
    
          ' Option Buttons
          DrawFrameControl hDC, MakeRect(90, 10, 15, 15), DFC_BUTTON, _
             DFCS_BUTTONRADIO
    
          DrawFrameControl hDC, MakeRect(90, 30, 15, 15), DFC_BUTTON, _
             DFCS_BUTTONRADIO Or DFCS_CHECKED
    
          DrawFrameControl hDC, MakeRect(90, 50, 15, 15), DFC_BUTTON, _
             DFCS_BUTTONRADIO Or DFCS_CHECKED Or DFCS_FLAT
    
          ' Push Button
          DrawFrameControl hDC, MakeRect(110, 10, 50, 20), DFC_BUTTON, _
             DFCS_BUTTONPUSH
    
          DrawFrameControl hDC, MakeRect(110, 40, 50, 20), DFC_BUTTON, _
             DFCS_BUTTONPUSH Or DFCS_PUSHED
    
          End Sub
    
    

  4. On the File menu, click Save File and save the file as DrawFram.frm for the file name.

  5. On the Run menu, click Start or press the F5 key to start the program. The form appears with drawings of the controls.


Additional reference words: 4.00 vb4win vb432 THREED DRAWFRAMECONTROL
DRAWEDGE WIN95
KBCategory: kbprg
KBSubCategory: APrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 16, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.