• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 683
  • Last Modified:

save MSCHART as a gif or bmp

I would like to know the best way to save an MSChart in VB6 as a gif or bmp file?
0
ginag
Asked:
ginag
  • 3
1 Solution
 
Richie_SimonettiIT OperationsCommented:
in a form:


Option Explicit
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 GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Form_Click()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Me.AutoRedraw = True
    EnumChildWindows Me.hwnd, AddressOf EnumChildProc, ByVal 0&
    With Picture1
        .Width = MSChart1.Width
        .Height = MSChart1.Height
        BitBlt .hDC, 0, 0, .Width, .Height, GetWindowDC(hwndChart), 0, 0, vbSrcCopy
        SavePicture .Image, "c:\mychart.bmp"
    End With
End Sub


'In a module:
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public hwndChart As Long
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim sSave As String, ret As Long
    'Get the windowtext length
    sSave = Space$(255)
    ret = GetClassName(hwnd, sSave, 255)
    'remove the last Chr$(0)
    sSave = Left$(sSave, InStr(1, sSave, Chr$(0), vbTextCompare) - 1)
    Debug.Print Chr$(34) & sSave & Chr$(34)
    If sSave = "MSChart20WndClass" Then hwndChart = hwnd
    'continue enumeration
    EnumChildProc = 1
End Function
0
 
Richie_SimonettiIT OperationsCommented:
better:

Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
   Dim sSave As String, ret As Long
      sSave = Space$(255)
   ret = GetClassName(hwnd, sSave, 255)
   'remove the last Chr$(0)
   sSave = Left$(sSave, ret)
   If sSave = "MSChart20WndClass" Then hwndChart = hwnd
   'continue enumeration
   EnumChildProc = 1
End Function
0
 
ginagAuthor Commented:
Thanks very much for the complete input.
0
 
Richie_SimonettiIT OperationsCommented:
Glad to Help.Thanks for "A" grade.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now