Unable to copy from clipboard

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • andrew

    Unable to copy from clipboard

    I have a MSchart object (COM Component) which I wish to
    insert as an image into a picture box so that I can print
    it out.

    'I call the chart controls's EditCopy to pass data to the
    clipboard.

    Dim Img As Image
    MyChart.EditCop y()
    'I then declare an IDataObject
    Dim data As IData = Clipboard.GetDa taObject()

    'I THen check to see whether emf data is present
    If (data.GetDataPr esent(DataForma ts.EnhancedMeta file)) Then
    '(Checking this statement in at debug evaluates to true)(I
    also am satisfied that the data is on the clipboard
    because I am able to Paste Special it into EXCEL)
    'I then try and recreate the emf as an image and have
    tried the following combinations
    'Img.FromFile(d ata.GetData(Dat aFormats.Enhanc edMetafile))
    'Img = CType(data.GetD ata(DataFormats .EnhancedMetafi le)),
    Image)
    UNFORTUNATELY THE ABOVE CODE SEEMS TO RETURN NOTHING FOR
    THE Img VARIABLE, AND INDICATES TO ME THAT I HAVE TO
    SOMEHOW INSTATIATE AND CONSTRUCT THE Img FROM THE METAFILE
    DATA, HOWEVER I HAVE NO IDEA HOW TO DO THIS.
    'I then hope to assign my Image to the PictureBox Control
    PictureBox1.Ima ge= Img
    End If

    I PRESUME IT IS POSSIBLE TO COPY IMAGES OF COM OBJECTS TO
    WIN FORM PICTURE BOXES (WITHOUT RESORTING TO PHOTOCOPYING
    AND SCANNING!), CAN ANYONE GIVE ME SOME POINTERS PLEASE.

    THANKS IN ADVANCE

    ANDREW


  • Ken Tucker [MVP]

    #2
    Re: Unable to copy from clipboard

    Hi,

    This procedure will create a bitmap from a form or control given its hwnd.
    You can print the bitmap.

    Private Structure RECT

    Public Left As Integer

    Public Top As Integer

    Public Right As Integer

    Public Bottom As Integer

    End Structure

    Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Integer,
    _

    ByRef lpRect As RECT) As Integer



    Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" _

    (ByVal hDestDC As Integer, ByVal x As Integer, _

    ByVal y As Integer, ByVal nWidth As Integer, _

    ByVal nHeight As Integer, ByVal hSrcDC As Integer, _

    ByVal xSrc As Integer, ByVal ySrc As Integer, _

    ByVal dwRop As Integer) As Integer



    Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowD C" _

    (ByVal hwnd As Integer) As Integer



    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Integer, _

    ByVal hObject As Integer) As Integer

    Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Integer, _

    ByVal hdc As Integer) As Integer



    Public Const SRCCOPY As Integer = &HCC0020

    Public Const SRCINVERT As Integer = &H660046

    Public Const MERGECOPY As Integer = &HC000CA

    Public Const MERGEPAINT As Integer = &HBB0226

    Private Function GetWindowPictur e(ByVal hWnd As Integer) As Bitmap

    Dim g As Graphics

    Dim hdcDest As IntPtr

    Dim hdcSrc As Integer

    Dim bm As Bitmap

    Dim r As New RECT()

    Dim w, h As Integer

    GetWindowRect(h Wnd, r)

    w = r.Right - r.Left

    h = r.Bottom - r.Top

    bm = New Bitmap(w, h)

    g = g.FromImage(bm)

    hdcSrc = GetWindowDC(hWn d)

    hdcDest = g.GetHdc



    BitBlt( _

    hdcDest.ToInt32 , 0, 0, w, h, hdcSrc, 0, 0, SRCCOPY)

    g.ReleaseHdc(hd cDest)

    ReleaseDC(hWnd, hdcSrc)

    Return bm

    End Function

    Ken

    ----------------------------

    "andrew" <anonymous@disc ussions.microso ft.com> wrote in message
    news:06f301c3b9 3e$35f363c0$a10 1280a@phx.gbl.. .[color=blue]
    > I have a MSchart object (COM Component) which I wish to
    > insert as an image into a picture box so that I can print
    > it out.
    >
    > 'I call the chart controls's EditCopy to pass data to the
    > clipboard.
    >
    > Dim Img As Image
    > MyChart.EditCop y()
    > 'I then declare an IDataObject
    > Dim data As IData = Clipboard.GetDa taObject()
    >
    > 'I THen check to see whether emf data is present
    > If (data.GetDataPr esent(DataForma ts.EnhancedMeta file)) Then
    > '(Checking this statement in at debug evaluates to true)(I
    > also am satisfied that the data is on the clipboard
    > because I am able to Paste Special it into EXCEL)
    > 'I then try and recreate the emf as an image and have
    > tried the following combinations
    > 'Img.FromFile(d ata.GetData(Dat aFormats.Enhanc edMetafile))
    > 'Img = CType(data.GetD ata(DataFormats .EnhancedMetafi le)),
    > Image)
    > UNFORTUNATELY THE ABOVE CODE SEEMS TO RETURN NOTHING FOR
    > THE Img VARIABLE, AND INDICATES TO ME THAT I HAVE TO
    > SOMEHOW INSTATIATE AND CONSTRUCT THE Img FROM THE METAFILE
    > DATA, HOWEVER I HAVE NO IDEA HOW TO DO THIS.
    > 'I then hope to assign my Image to the PictureBox Control
    > PictureBox1.Ima ge= Img
    > End If
    >
    > I PRESUME IT IS POSSIBLE TO COPY IMAGES OF COM OBJECTS TO
    > WIN FORM PICTURE BOXES (WITHOUT RESORTING TO PHOTOCOPYING
    > AND SCANNING!), CAN ANYONE GIVE ME SOME POINTERS PLEASE.
    >
    > THANKS IN ADVANCE
    >
    > ANDREW
    >
    >[/color]


    Comment

    Working...