Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double Buffer GDI Graphics 5

Status
Not open for further replies.

gmmastros

Programmer
Feb 15, 2005
14,909
US
I am trying to use a double buffer technique for drawing shapes, and I just can't seem to get it right. Can someone please help me figure this out.

Currently, this will draw a single line on a form.

Code:
Option Explicit

Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
 
Private Declare Function LineTo Lib "gdi32" (ByVal hDc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hDc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As Any) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long

Private Const PS_SOLID = 0

Private Sub Command1_Click()
    
    Dim redPen As Long
    
    redPen = CreatePen(PS_SOLID, 15, vbRed)
    DeleteObject SelectObject(Me.hDc, redPen)
    MoveToEx Me.hDc, 10, 10, 0
    LineTo Me.hDc, 210, 210
    
    Me.Refresh

End Sub

Private Sub Form_Load()
    
    Me.AutoRedraw = True

End Sub

I've read that double buffering the drawing surface will speed up the drawing process, which is my ultimate goal here. So, if there is another technique that is faster than this, I'd be interested in that too.



-George

"the screen with the little boxes in the window." - Moron
 
Does anyone know if any of these smiley thingies does bowing & general worship?

It seems to be the only fit response to strongm posts.
 
:) Might I suggest something like:

EveryDay_Animated_5.gif
 
strongm,

I cannot say enough how thankful I am. You are truly amazing, not only for your technical abilities, but also for your willingness to share with others. When I grow up, I want to be just like you.

jumping.gif
jumping.gif
jumping.gif

jumping.gif
jumping.gif
jumping.gif


-George

"the screen with the little boxes in the window." - Moron
 
I kind of had the feeling that strongm would have an improvement on this. Very impressive...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top