blog community

Welcome to blog community Sign in | Join | Help
in Search

Wouter van Vugt

This blog is no longer maintained and has moved

an IPictureDisp implementation

Please note that this code is not entirelly mine :) I got it from a collegue who got it ... you know the story. (Thanks btw!)

using System;

using System.Drawing;

using System.Runtime.InteropServices;

using stdole;

 

public class RibbonImage : IPictureDisp, IPicture

{

    Bitmap _image = null;

    IntPtr _handle = IntPtr.Zero;

 

    public RibbonImage(Bitmap image)

    {

        _image = image;

    }

 

    ~RibbonImage()

    {

        if (_handle != IntPtr.Zero)

        {

            DeleteObject(_handle);

        }

    }

 

    [DllImport("gdi32.dll")]

    static extern void DeleteObject(IntPtr _handle);

 

    public int Width

    {

        get { return _image.Width; }

    }

 

    public int Height

    {

        get { return _image.Height; }

    }

 

    public short Type

    {

        get { return 1; }

    }

 

    public int Handle

    {

        get

        {

            if (_handle == IntPtr.Zero)

            {

                _handle = _image.GetHbitmap();

            }

            return _handle.ToInt32();

        }

    }

 

    public int hPal

    {

        get { return 0; }

        set { }

    }

 

    public void Render(int hdc, int x, int y,

int cx, int cy, int xSrc, int ySrc, int

cxSrc, int cySrc, IntPtr prcWBounds)

    {

        Graphics graphics = Graphics.FromHdc(new IntPtr(hdc));

        graphics.DrawImage(_image, new Rectangle(x, y, cx, cy),

xSrc, ySrc, cxSrc, cySrc, GraphicsUnit.Pixel);

    }

 

    #region IPicture Members

 

    public int Attributes

    {

        get { return 0; }

    }

 

    public int CurDC

    {

        get { return 0; }

    }

 

    public bool KeepOriginalFormat

    {

        get { return false; }

        set { }

    }

 

    public void PictureChanged()

    {

    }

 

    public void SaveAsFile(IntPtr pstm, bool fSaveMemCopy, out int pcbSize)

    {

        pcbSize = 0;

    }     

 

    public void SelectPicture(int hdcIn, out int phdcOut, out int phbmpOut)

    {

        phdcOut = 0;

        phbmpOut = 0;

    }

 

    public void SetHdc(int hdc)

    {

    }

 

    #endregion

}

Published Wednesday, June 07, 2006 2:12 PM by wouterv
Filed under: ,

Comments

No Comments
Anonymous comments are disabled

This Blog

Syndication

News


Add to Technorati Favorites
Powered by Community Server, by Telligent Systems