Custom UI creator: similar to a browser, but no HTML - ideas?

Posted on 2007-10-08
Last Modified: 2013-12-04
Ah hello.

Most of us are at least aware that we can write a COM object and interact with that object via HTML/JavaScript.  For example, a simple web page could call a COM object in a DLL that may, say, write to or read from the registry.  The writing and reading would use the C++ registry API, whereas the call into the C++ would be triggered via JavaScript and HTML.

I currently have this scenario.  A web page runs in a dialog hosting a browser control (IE), and any user interaction is dealt with in a DLL via JavaScript interacting with a COM object.  

All of this is quite nice, until you realise that a lot is beyond our control.  Apart from having no control over the the layout and presentation of the page, apart from via HTML, (IE does it all, which is not a bad thing) it is not future proof: MS could decide that COM objects running via a web page are a security risk (true), so could stop it happening full stop.  Indeed, in Vista, this is becoming a real issue.

Hence, I want to do away with a browser control altogether.

It would not be too difficult to have an app read some "file" that contains information about what a "page" should look like.  Where in HTML I would specify page backgrounds, and control locations, I would do exactly the same, except I would have to construct the controls myself.  Whereas I might have

<input type = "button" value = "Button">

in HTML, I would have to call CButton::Create myself to "add the button to the page" as it were.  Any page "background" would have to be blitted to the window, etc etc...

None of this is really difficult.

But now the issue.  Look again at the button HTML, but this time add a handler in:

<input type = "button" value = "Button" onclick="JavaScript:Function()">

with the corresponding JavaScript function

<script language = "JavaScript">

function Function()
      // Do stuff here


all nicely packed away in the HTML.

My question is simple: *how on earth could I have a button handler containing the code to be executed serialised away into my "file"?* Message maps are out of the question since they have to be compiled into the exe at build time...?!

Any advice or hints on this please?

Question by:mrwad99
    LVL 4

    Assisted Solution

    I think the best solution for this would be to basically write your own simple web browser. You can create the effect of a "button" just by drawing it on the screen and handling the OnMouseMove, OnLButtonDown, OnLButtonUp, ect events by drawing the different objects acordingly.

    First you would have to create an HTML (provided you want to use HTML, you could come up with somthing simpler) parser, which would create objects as it hits them. Each object would link to it's child objects. So you would start out with a main Document object that has children. Once you have created all the objects then create a drawing routine that "knows" how to draw each object onto an HDC based on it's tag and attribues. Then just recursivly call the drawing routine of each object and you will have yourself a very simple web browser. If you look at programs such as iTunes or even web browsers with Spy++, you will notice they do not use actual Windows to create buttons or even text boxes. They are basically one large window with these "controls" drawn directly onto the divice context that look and act like child window controls.

    If this is something you are not comfortable with attempting (maybe you don't have enough time) then try using the Mozilla layout engine (which is open source) to acomplish your exact needs.

    If you are liking the idea of writing your own web browser let me know what other questions you have about it and I'll try to help to the best of my knowledge.

    Good luck,
    LVL 22

    Assisted Solution

    As said you need to parse your source file, look for controls and execute event code present in those files.....
    For example...If you need to create buttons dynamically, the usual method is to create them within a known range of values such as IDC_BUTTON_BASE=1100 to IDC_BUTTON_LIMIT=2200 and use ON_CONTROL_RANGE to route them all to the same handler.

    To add the button click message handler you put ON_CONTROL_RANGE into the message map.


    Now your OnClickedDButton handler will be called for every one of them, and it will be passed the ID of the clicked button.


    LVL 39

    Accepted Solution

    >>>> how on earth could I have a button handler containing the
    >>>> code to be executed serialised away into my "file"?
    I wouldn't do it that way for two reasons. First, if you execute code that maybe could be manipulated by someone, you are opening a big security hole. You may argue that your program needs low rights but you can't go for sure that anyone who is using your prog actually isn't logged in as an adminstrator. The second reason is that the possibilities what a button handler can do normally are limited so that the full spectrum of javascript is an overkill. Assume your button handler wants to switch to a different page or wants to check the contenst of other controls. How should it do this? You would need to provide a 'handle' to your app so that the handler function can retireve further information together with a bundle of 'get' method  *or* you have to pass *all* information to the handler function in advance. If doing so, you most likely will find out that writing a handler isn't an easy thing and if different programmers are involved you will get an inconsistent and bad designed UI.

    A different approach - though it means more work for you - is to write the handlers yourself and make them configurable. The configuration can be passed in the same input file as the form. You even could offer 'open' interfaces where someone can provide functions in a dll that were called to check inputs or make evaluations. The difference to serialising arbitrary code from a text file is that the provider has to actively install a dll on a system - you additionally can request for registering it -  and that the interfaces were predefined, i. e. the foreign code has no direct access to the app and the gui handling.

    Regards, Alex
    LVL 19

    Author Comment


    Thanks for the comment.  I don't really want to create my own HTML parser, no: that would be a little too much.  In fact,  I am steering away from scripting now altogether, as you will discover when you read below.


    Thanks.  Good point about the command range; I had not thought of that.


    Thanks for participating.  Excellent point about serialising away code and writing my own handlers being a bad idea; again, just things I had not considered.

    After reading all of these comments I am realising that having my own "script" to display a "page" would be a bad idea.  Instead, I plan to have each series of pages packed away in their own DLL, which can be read and displayed by the main app.  Complete turnaround, I know, but if it is the least troublesome way then so be it.

    >> A different approach - though it means more work for you - is to write the handlers yourself and make them configurable.

    I have read this a few times and am not entirely sure what you mean.  Do you mean something similar to what I now plan to do?  If not, could you clarify please Alex?

    Thanks all.
    LVL 19

    Author Comment

    Alex, could you clarify what you meant in your last comment regarding "configurable handlers", please?  It might be a more viable option than what I plan to do...
    LVL 19

    Author Comment

    OK, thanks very much all.
    LVL 39

    Expert Comment

    >>>> A different approach - though it means more work for you -
    >>>> is to write the handlers yourself and make them configurable.

    Configuration, opposite to programming means that the functionality a handler function provides can only be configured but not enhanced with own code. In case of a button handler a configuration may allow to add the URL where the handler jumps to after check of the current page. Or you can change the text and image of a button (customizing).  

    >>>> Do you mean something similar to what I now plan to do?
    Not in particular but the main idea is the same. You wouldn't provide a programming framework where the user needs to make own programming to get the whole thing running but a bunch of pages each of them was running with a well-defined functionality. I don't know whether your app allows to omit whole pages or what kind of 'customizing' features you want to offer. You also have to consider that using a browser for the GUI not necessarily means that you give up control. You can make it work for different browsers and/or use the browser for the GUI handling only. With a strict separation of application logic and GUI logic you may sooner or later decide using your own GUI by simple exchanging the GUI part only.

    Regards, Alex
    LVL 19

    Author Comment

    I see.  Thank you for clarifying.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now