Click here to Skip to main content
Click here to Skip to main content

OCX Snapshot

, 9 Feb 2000 Public Domain
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 ViewObjSnap_src.zip file. The source code and a demo VB project, along with the compiled EXE for those that don't own VB, are in ViewObjSnap_demo.zip.

    License

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

    Share

    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.

    Comments and Discussions

     
    QuestionDoes anybody try with C++? PinmemberJason_Huang@Acer4-Feb-04 0:06 
    GeneralMissing Lib PinmemberJose Cruz16-Oct-02 11:10 
    GeneralRe: Missing Lib PinmemberAbhijeet Dev26-Oct-03 4:41 

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

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

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