Visual Basic Tip: 11/20/95


Graphics.
- Separate the Red, Green, and Blue components from a long integer color value.

  clr& = BackColor
 
  r% = clr& And &HFF&                 'red
  g% = (clr& And &HFF00&) \ 256       'green
  b% = (clr& And &HFF0000) \ 65536    'blue


- Arrange the icons (minimized) on the desktop window.

  Declare Function ArrangeIconicWindows Lib "User" (ByVal hWnd As Integer) As Integer
  Declare Function GetDesktopWindow Lib "User" () As Integer

  desk% = GetDesktopWindow()
  x% = ArrangeIconicWindows(desk%)


- Draw lines using API.  Any of the Windows API line output functions can be used in a similar
  manner.  The advantage is increased drawing speed and the power of the various APIs.  This may
  be an advantage in a application where a great deal of line drawing is done OR sophisticated
  drawing techniques are needed. 
 
  Declare Function CreatePen Lib "GDI" (ByVal nPenStyle As Integer, ByVal nWidth As Integer, ByVal crColor As Long) As Integer
  Declare Function SelectObject Lib "GDI" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
  Declare Function MoveTo Lib "GDI" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer) As Long
  Declare Function LineTo Lib "GDI" (ByVal hDC As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
  Declare Sub DeleteObject Lib "GDI" (ByVal hObject As Integer)
 

  thehdc = form1.hDC
  hbr = CreatePen(0, 1, clrval&)
  oldpen = SelectObject(form1.hDC, hbr)
 
  dvr& = MoveTo(thehdc, xpixel, ypixel)
  xx = LineTo(thehdc, xpixdest, ypixdest)
 
  DeleteObject hbr
  xtmp = SelectObject(form1.hDC, oldpen)


- Create a rubber band box using VB code.  A rubber band box is a box that stretches 
  as you move the mouse.

  'Declare
  Dim Xval As Single, Yval As Single, Xold As Single, Yold As Single

  Sub Form_MouseDown (button As Integer, Shift As Integer, x As Single, y As Single)
   Xval = x
   Yval = y
   Xold = x
   Yold = y
  End Sub

  Sub Form_MouseMove (button As Integer, Shift As Integer, x As Single, y As Single)
   If button Then
    savemode% = drawmode
    drawmode = 6
    savestyle% = drawstyle
    drawstyle = 2
 
    Line (Xval, Yval)-(Xold, Yold), , B
    Line (Xval, Yval)-(x, y), , B
  
    Xold = x
    Yold = y
 
    drawmode = savemode%
    drawstyle = savestyle%
   End If
  End Sub

  Sub Form_MouseUp (button As Integer, Shift As Integer, x As Single, y As Single)
   savemode% = drawmode
   drawmode = 6
   savestyle% = drawstyle
   drawstyle = 2
 
   Line (Xval, Yval)-(Xold, Yold), , B
  
   drawmode = savemode%
   drawstyle = savestyle%
  End Sub
Return to Phil's Web Page

Created by: Philip