Click here to Skip to main content
12,997,051 members (78,150 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 9 Feb 2000

OCX Snapshot

, 9 Feb 2000
Rate this:
Please Sign up or sign in to vote.
How to take a snapshot of an OCX without using HWNDs.
  • Download demo project - 33 Kb
  • Download source files - 27 Kb
  • Sample Image - ViewObjSnap.jpg

    Recently, the company I CO-OP for (Bradley Ward Systems) needed a way to show complex data reports over the web. We already have lots of custom OCXs that present these reports in graph or chart form. These OCXs are used in our custom applications - they were never intended to be embedded in web pages.

    Because we wanted to make the web reports as light-weight as possible, refitting the OCXs to also be embedded in web pages was simply not an option - we didn't want to impose stringent system requirements on the computers that would be used to view these reports. We decided that the best way to show these reports over the web was to take a "snapshot" of one of our OCXs and write it out to a JPEG for display on a web page.

    So, our biggest problem was how to get a picture of one of our OCXs... We tried various ways of getting the picture by using the HWND of a form our OCX was embedded on. There were two major problems with this: first, a visible form would have to appear on the screen of the webserver whenever we wanted to get a picture of an OCX; second, a user would always have to be logged onto the webserver in order to create the form that the OCX was embedded on. We simply didn't find a way around these problems.

    So, instead of using the HWND to trick the OCX into painting into a DC of our creation, we went a little deeper...

    Every OCX must implement the standard IViewObject interface - of which one of the methods is Draw(). Sounds perfect, right? Almost - we also have to determine the dimensions of the OCX, functionality which IViewObject does not expose. We used the IOleObject interface's GetExtents() for this. I wrote a small ActiveX control that makes these calls, and returns an IPicture object for embedding in a Picture control on a VB form.

    This ActiveX control I present here - called ViewObjSnap - is a scaled-down version of the one I wrote at work. It doesn't write the picture out to a JPG or anything like that, so you would need to modify it a little to be useful in a real world situation. It is only intended to demonstrate an interesting solution to our problem.

    The source code for the ViewObjSnap control is contained in the file. The source code and a demo VB project, along with the compiled EXE for those that don't own VB, are in <p>


    This article, along with any associated source code and files, is licensed under A Public Domain dedication


    About the Author

    Russell Morris
    Web Developer
    United States United States
    Programming in C++ (and various other languages) since 1993. Started with OWL, then went on to MFC, ATL, Java, etc...

    Graduated from Georgia Tech in December 2001.

    You may also be interested in...

    Comments and Discussions

    QuestionDoes anybody try with C++? Pin
    Jason_Huang@Acer3-Feb-04 23:06
    memberJason_Huang@Acer3-Feb-04 23:06 
    GeneralMissing Lib Pin
    Jose Cruz16-Oct-02 10:10
    memberJose Cruz16-Oct-02 10:10 
    GeneralRe: Missing Lib Pin
    Abhijeet Dev26-Oct-03 3:41
    memberAbhijeet Dev26-Oct-03 3:41 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web02 | 2.8.170622.1 | Last Updated 10 Feb 2000
    Article Copyright 2000 by Russell Morris
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid