Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


Have you ever tried to fill shapes which are drawn by Polyline or PolyBezier which doesn't draw closed figures. The problem is its not closed figure so you cannot fill using regular fill method which works very well with closed figures. The solution to this problem is BeginPath and EndPath apis

You can draw whatever you want using GDI drawing function between BeginPath and EndPath api. By doing this it captures the path but dont display it.

Step-By-Step Example

- Create a standard exe project, form1 is added by default
- Place one picture box on form1
- Copy/Paste the following code in form1 code window

Click here to copy the following block
Private Declare Function PolyBezier Lib "gdi32" (ByVal hDC As Long, _
  ByRef lppt As PointAPI, ByVal cPoints As Long) As Long
  
Private Declare Function BeginPath Lib "gdi32" ( _
  ByVal hDC As Long) As Long
  
Private Declare Function EndPath Lib "gdi32" ( _
  ByVal hDC As Long) As Long
  
Private Declare Function FillPath Lib "gdi32" ( _
  ByVal hDC As Long) As Long
  
Private Declare Function StrokeAndFillPath Lib "gdi32" ( _
  ByVal hDC As Long) As Long

Private Declare Function StrokePath Lib "gdi32" Alias "StrokePath" ( _
  ByVal hdc As Long) As Long
  
Private Declare Function GetStockObject Lib "gdi32" ( _
  ByVal nIndex As Long) As Long
  
Private Declare Function SelectObject Lib "gdi32" ( _
  ByVal hDC As Long, ByVal hObject As Long) As Long

Private Type PointAPI
  X As Long
  Y As Long
End Type

Private Const WHITE_BRUSH = 0
Private Const BLACK_PEN = 7

Private Sub Form_Load()
  Dim Pts(3) As PointAPI, LoopPts As Long
  Dim OldPen As Long, OldBrush As Long
  
  Picture1.AutoRedraw = True
  
  Pts(0).X = 10: Pts(0).Y = 10
  Pts(1).X = 10: Pts(1).Y = 100
  Pts(2).X = 100: Pts(2).Y = 10
  Pts(3).X = 100: Pts(3).Y = 100

  OldPen = SelectObject(Picture1.hDC, GetStockObject(BLACK_PEN))
  OldBrush = SelectObject(Picture1.hDC, GetStockObject(WHITE_BRUSH))
  '//////////////////////////////
  ' Edge entire shape
  '//////////////////////////////
  Call BeginPath(Picture1.hDC)
  Call PolyBezier(Picture1.hDC, Pts(0), 4)
  Call EndPath(Picture1.hDC)

  'Call StrokePath(Picture1.hDC)
  Call StrokeAndFillPath(Picture1.hDC)

  For LoopPts = 0 To 3 ' Offset points
    Pts(LoopPts).X = Pts(LoopPts).X + 100
  Next LoopPts
  
  '//////////////////////////////
  ' Edge only curve
  Call BeginPath(Picture1.hDC)
  Call PolyBezier(Picture1.hDC, Pts(0), 4)
  Call EndPath(Picture1.hDC)
  
  Call FillPath(Picture1.hDC)
  Call PolyBezier(Picture1.hDC, Pts(0), 4)
  '//////////////////////////////
  Call SelectObject(Picture1.hDC, OldPen)
  Call SelectObject(Picture1.hDC, OldBrush)
End Sub

- Press F5 to run the project


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.