Results 1 to 2 of 2

Thread: MsChart Error :(

  1. #1

    Thread Starter
    Addicted Member Geoff Gunson's Avatar
    Join Date
    Jun 1999
    Posts
    241

    Post

    Hi

    I am printing a graph that I produced on a form using the code:

    Me.PrintForm

    The code attempts to print the graph then I get a MsChart error : "VtDsGdi2 ReleaseDc called with null hDc".

    Does anyone know whats causing this?

    Cheers

    Geoff

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try this as an alternative method for Printing your Chart(s)..

    Add a Picturebox to your Form and set it's Visible Property to False..
    Code:
    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 GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    
    Private Const SRCCOPY = &HCC0020
    
    Private Sub Command1_Click()
        Dim lDC As Long
        Dim W As Integer
        Dim H As Integer
        W = ScaleX(MSChart1.Width, vbTwips, vbPixels)
        H = ScaleY(MSChart1.Height, vbTwips, vbPixels)
        lDC = GetDC(MSChart1.hwnd)
        Picture1.AutoRedraw = True
        Picture1.Move 0, 0, MSChart1.Width, MSChart1.Height
        BitBlt Picture1.hdc, 0, 0, W, H, lDC, 0, 0, SRCCOPY
        Call ReleaseDC(MSChart1.hwnd, lDC)
        Picture1 = Picture1.Image
        Printer.PaintPicture Picture1, 0, 0
        Printer.EndDoc
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width