King's profile孤独的夜PhotosBlogLists Tools Help

Blog


    March 24

    RichEdit中显示GIF和其它图片

           网上有不少文章介绍了如何在RichEdit控件中显示Bmp,但是显示其它格式的却很难找到。当然像CodeProject的dTianx兄提供了一篇可以参考的文章:http://www.codeproject.com/richedit/AnimatedEmoticon.asp
    不过,美中不足的是里面用的是第三方(腾讯Tecent)的OLE库ImageOle.dll,该库只支持Bmp、Gif、Jpg格式的图片,没有办法扩展。所以我就打算写一个自己的OLE库,来支持我想要显示的图片。那么还等什么?现在就开始吧。
          首先,打开VC,新建一个DLL的ATL工程,然后Insert一个至少包含IViewObject、IOleObject、IOleControl的ALT对象,当然你也可以直接选Full的对象,名字你可以自己决定。添加一个接口LoadFromFile来读取图片到内存中。然后在ATL的OnDraw函数把图片画出来,至于怎么画,和用什么画可以看个人的喜好了。比如用第三方开源的库,或则GDI或GDI+都可以,不过这只是处理静态的图片。
          其次处理动态图片比如GIF文件,可以采用ATL对象拥有句柄,然后再句柄的OnTimer事件中处理,也可以不用定时器,开启一个线程,在线程中用等待事件的方式。
          最后,测试和修正其它的小问题。如果你有一定ATL功底的话,就会发现挺简单的吧。编译和注册了我们自己的OLE控件后,使用方法和上面提到的参考文章一样,就没什么问题了。
     

    Comments (6)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    templaryxhwrote:
    我在做的时候,如果拖动richedit滚动条到只显示gif一部分,gif将自动跳动到显示整个图片。你是怎么解决这个问题的。
    Sept. 24
    Ericwrote:
    有一个CPictureEx的类。可以把这类改造为一个OLE对象。不需要Timer, 只需要使用一个WaitForSingleObject停顿每个祯之间间隔就可以了。我写过,但是有的时候会Crash。所以没有放到CodeProject上面。
    Oct. 6
    Kingwrote:
    自己用CreateEvent创建一个事件用来控制线程正常退出,考虑很多动画图片的情况下,可以建立一个队列,检查队列中的动画图片是否到了切换动画帧的时候,切换后记得通知OLE组件重新绘图。
    June 5
    frankwrote:
    动态GIF文件中就有各个图片间隔时间,用OnTimer一般是相同的间隔,不太好;
     
    “不用定时器,开启一个线程,在线程中用等待事件的方式”
    ——请教等待什么事件?
     
     
    有没有考虑一个richedit中有很多动画图片的情况?
    June 2
    心志 刘wrote:
    我也学习,以后也把msn该成技术讨论
    May 16
    Newbiewrote:
    学习了
    Mar. 30

    Trackbacks

    The trackback URL for this entry is:
    http://jujoking.spaces.live.com/blog/cns!E7A2E14DD674BBB7!136.trak
    Weblogs that reference this entry
    • None