avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Wednesday April 14, 2021, 7:04 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - relipse [ switch to compact view ]

Pages: prev1 2 3 [4]
Thanks to the tons of articles and open source code, this would not be possible.
Well, lets say we want to add Scripting support -- specifically JavaScript support, in other words, the user can install a script to customize your application, the key is having a language, and an engine to parse it.
Well, because the TCppWebBrowser component is just an activex control that puts an Internet Explorer control on your app, we can use the scripting engine embedded within IE to do all our dirty work.

Once you drop a TCppWebBrowser on your form, and hide it away behind some other components, name it WebScripter or something.

Well, now we will need some basic utilities, number one, is a way to execute scripts, which you can use a few methods to do it,
one is to load an html page with that script included in the html, or just have a <script>my script</script>, or my favorite, after the TCppWebBrowser component loads and navigates to its first page, we can use the function below to execute javascript inside the currently loaded document (it must exist, do a Web->Navigate(L"about:blank"); if you need to)
bool TCppWebBrowserUtils::ExecJs(TCppWebBrowser *Web, WideString cmd)
 IHTMLDocument2  *doc = NULL;
 IHTMLWindow2 *win;
 if (!Web->Document){ return false; }
 bool success_status = false;
 if(SUCCEEDED(Web->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&doc)))  {
   HRESULT hr = doc->get_parentWindow(&win);
   if (SUCCEEDED(hr))  {
     VARIANT v;
     success_status = true;
 return success_status;

Ok, now that we got that, we are ready to execute custom scripts, load it from a file, drag and drop, or whatever, then pass it to the function above.

But you may be wondering, what is so special about this? We get all the cool things that JavaScript comes with such as regular expressions, substrings, the tons of functions on the internet that we can add.

Now, how can the user control our application?
The key is, window.external, which is what we are going to implement next.

At this time, you can compile your application, and execute some javascript, but we still need to add an implementation for window.external

The idea of window.external , is to be able to call non-script code, so that the user can execute C++ code by using a method of window.external.YourAppDoSomethingCool();

Well, how exactly do we get functions attached?
First of all, we need our own IDocHostUIHandler to attach to the WebBrowser component.
We can do this by adding a new class as below:

 //The below class lets you replace the right click menu, as well as attach functionality to window.external (SetExternal())
  // Simple implementation for IDocHostUIHandler and IUnknown interfaces
  // Implementation returns E_NOTIMPL for all IDocHostUIHandler methods except
  // ShowContextMenu. See comment block preceeding that ShowContxtMenu for
  // further information.
  class MyDocHandler :public IDocHostUIHandler
    long refcount;
    IDispatch* External;
    TPopupMenu* PopupMenu;
    bool ShowIEPopup;
    void SetExternal(IDispatch* Ext)

        External = Ext;


    IDispatch* GetExternal()
        return External;


    MyDocHandler() :refcount(1), External(NULL), PopupMenu(NULL), ShowIEPopup(true){ }

    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID classid, void** intf) {
      if (classid == IID_IUnknown)
        *intf = (IUnknown*)this;
      else if (classid == IID_IDocHostUIHandler)
        *intf = (IDocHostUIHandler*)this;
        return E_NOINTERFACE;
      return S_OK;

      return refcount;

    virtual ULONG STDMETHODCALLTYPE Release() {
      if (refcount == 0)
        delete this;
      return refcount;

    // Returning S_OK tells the web browser that it need not display its
    // own context menu, presumably because the application hosting it has
    // displayed its own menu to replace it.
    // Since our host does not display any, no context menu is shown.
    virtual HRESULT STDMETHODCALLTYPE ShowContextMenu(
      /* [in] */ DWORD dwID,
      /* [in] */ POINT __RPC_FAR *ppt,
      /* [in] */ IUnknown __RPC_FAR *pcmdtReserved,
      /* [in] */ IDispatch __RPC_FAR *pdispReserved) {

          if (PopupMenu)
             PopupMenu->Popup(ppt->x, ppt->y);
             return S_OK;
          else if (!ShowIEPopup)
          { //don't show one at all
            return S_OK;
          else{  //if there is no pop up menu, just use the default ie one
            return E_NOTIMPL;


      /* [out][in] */ DOCHOSTUIINFO __RPC_FAR *pInfo) {
          return E_NOTIMPL;

      /* [in] */ DWORD dwID,
      /* [in] */ IOleInPlaceActiveObject __RPC_FAR *pActiveObject,
      /* [in] */ IOleCommandTarget __RPC_FAR *pCommandTarget,
      /* [in] */ IOleInPlaceFrame __RPC_FAR *pFrame,
      /* [in] */ IOleInPlaceUIWindow __RPC_FAR *pDoc) {
          return E_NOTIMPL;

          return E_NOTIMPL;

    virtual HRESULT STDMETHODCALLTYPE UpdateUI( void) {
          return E_NOTIMPL;

    virtual HRESULT STDMETHODCALLTYPE EnableModeless(
      /* [in] */ BOOL fEnable) {
          return E_NOTIMPL;

    virtual HRESULT STDMETHODCALLTYPE OnDocWindowActivate(
      /* [in] */ BOOL fActivate) {
          return E_NOTIMPL;

    virtual HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(
      /* [in] */ BOOL fActivate) {
          return E_NOTIMPL;

      /* [in] */ LPCRECT prcBorder,
      /* [in] */ IOleInPlaceUIWindow __RPC_FAR *pUIWindow,
      /* [in] */ BOOL fRameWindow) {
          return E_NOTIMPL;

    virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator(
      /* [in] */ LPMSG lpMsg,
      /* [in] */ const GUID __RPC_FAR *pguidCmdGroup,
      /* [in] */ DWORD nCmdID) {
          return E_NOTIMPL;

      /* [out] */ LPOLESTR __RPC_FAR *pchKey,
      /* [in] */ DWORD dw) {
          return E_NOTIMPL;

      /* [in] */ IDropTarget __RPC_FAR *pDropTarget,
      /* [out] */ IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget) {
          return E_NOTIMPL;

      /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch) {
        if(ppDispatch == NULL)
            return E_POINTER;

        // make sure currently loaded doc is safe
        //    return E_NOTIMPL;

        if(External) {
            *ppDispatch = External;
            return S_OK;
        return E_NOTIMPL;

      /* [in] */ DWORD dwTranslate,
      /* [in] */ OLECHAR __RPC_FAR *pchURLIn,
      /* [out] */ OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut) {
          return E_NOTIMPL;

    virtual HRESULT STDMETHODCALLTYPE FilterDataObject(
      /* [in] */ IDataObject __RPC_FAR *pDO,
      /* [out] */ IDataObject __RPC_FAR *__RPC_FAR *ppDORet) {
          return E_NOTIMPL;

The trick is, that this inherits from IDocHostUIHandler, and thus implements the virtual functions,
each function can return a few different types, E_NOTIMPL means you did not change anything, and you want the default behavior, whereas S_OK means you handled it -- like the popup menu
You really don't need to know much more if you want to see it in action, we still have to add our own interface:

#ifndef CppScripterH
#define CppScripterH
#include <OleCtrls.hpp>
#include <SHDocVw_OCX.h>
#include <mshtml.h>
#include <mshtmhst.h>
#include "TCppWebBrowserUtils.h"

//This actually contains the functions that will be added to
class IBrowserExternal
    TStringList* GlobalVariables;  //initalized and freed outside of this class
    ~IBrowserExternal() {};

    //currently the only functions are window.external.SetVar() and window.external.GetVar() as implemented below
    virtual void STDMETHODCALLTYPE SetVar(BSTR key, BSTR val)
        GlobalVariables->Values[AnsiString(key)] = val;
        return (WideString)GlobalVariables->Values[key];

The above code is important, it is the class that will be used to store all the methods you want inside of window.external,
the above code only has 2 methods, GetVar() and SetVar(), a useful way to pass information between the script and your app.
Notice how it returns BSTR, and accepts BSTR, that is a string type in javascript, or a WideString() in BCB. Get used to it, you can cast between WideString() and AnsiString() to do string manipulation.

We also need the below code to basically attach the method invocation directly to our methods (i put the above and below code in the same .h file),

class TExternalDispatch : public IDispatch
    // IUnknown
    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID classid, void** intf);
    virtual ULONG STDMETHODCALLTYPE Release();

    virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT* pctinfo);

    virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(/* [in] */ UINT iTInfo,
        /* [in] */ LCID lcid,
        /* [out] */ ITypeInfo** ppTInfo);

        /* [in] */ REFIID riid,
        /* [size_is][in] */ LPOLESTR *rgszNames,
        /* [in] */ UINT cNames,
        /* [in] */ LCID lcid,
        /* [size_is][out] */ DISPID *rgDispId);

        /* [in] */ DISPID dispIdMember,
        /* [in] */ REFIID riid,
        /* [in] */ LCID lcid,
        /* [in] */ WORD wFlags,
        /* [out][in] */ DISPPARAMS  *pDispParams,
        /* [out] */ VARIANT  *pVarResult,
        /* [out] */ EXCEPINFO *pExcepInfo,
        /* [out] */ UINT *puArgErr);

    long refcount;
    IBrowserExternal* BrowserExternal;
    ITypeInfo* TypeInfo;
    IBrowserExternal* getBrowserExternal(){ return BrowserExternal; }


We will also need more code in the .cpp file
Notice, this is extremely important, we must define all of the type information about our new methods:

//put this in the .cpp file to add window.external.SetVar() and GetVar()

//this describes the parameters SetVar() takes 2 string parameters, a key and value
static PARAMDATA rgpSetVar[] =
    { OLESTR("key"), VT_BSTR},
    { OLESTR("val"), VT_BSTR}

//GetVar() only takes 1 string, the key
static PARAMDATA rgpGetVar[] =
    { OLESTR("key"), VT_BSTR}

//for each function, weneed to add the code below
enum IMETH_ExtDisp
    IMETH_SetVar = 0,

//likewise for this also
enum IDMEMBER_ExtDisp

//now, see if you can figure this out -- this is the method data -- how it figures out how to call our member functions
//Get used to copying and pasting for each member function, the # represents the number of parameters
//the last item represents the return type VT_BSTR for string, VT_EMPTY for void, VT_INT for int, etc,
//look on the documentation
static METHODDATA rgmdataExtDisp[] =
    { OLESTR("SetVar"),           rgpSetVar,          IDMEMBER_SetVar,           IMETH_SetVar,         CC_CDECL, 2, DISPATCH_METHOD, VT_EMPTY },
    { OLESTR("GetVar"),           rgpGetVar,          IDMEMBER_GetVar,           IMETH_GetVar,         CC_CDECL, 1, DISPATCH_METHOD, VT_BSTR }

/* IDispatch class for our interface */

:   refcount(1),
    BrowserExternal = new IBrowserExternal();
    CreateDispTypeInfo(&idataExtDisp, LOCALE_SYSTEM_DEFAULT, &TypeInfo);


    delete BrowserExternal;

/* IUnknown */

HRESULT STDMETHODCALLTYPE TExternalDispatch::QueryInterface(REFIID classid, void** intf)
    if(intf == NULL)
        return E_INVALIDARG;

    if (classid == IID_IDispatch || classid == IID_IUnknown) {
        *intf = this;
        return S_OK;

    *intf = NULL;
    return E_NOINTERFACE;

    return refcount;

ULONG STDMETHODCALLTYPE TExternalDispatch::Release()
    if (refcount == 0) {
        delete this;
        return 0;
    return refcount;

/* IDispatch */

HRESULT STDMETHODCALLTYPE TExternalDispatch::GetTypeInfoCount(
    UINT* pctinfo)
    if(TypeInfo == NULL)
        return E_NOTIMPL; // shouldn't happen

    if(pctinfo == NULL)
        return E_INVALIDARG;

    *pctinfo = 1;

return S_OK;

    /* [in] */ UINT iTInfo,
    /* [in] */ LCID lcid,
    /* [out] */ ITypeInfo** ppTInfo)
    if(TypeInfo == NULL)
        return E_NOTIMPL; // shouldn't happen

    if(iTInfo != 0)
        return DISP_E_BADINDEX;

    if(ppTInfo == NULL)
        return E_INVALIDARG;

    *ppTInfo = TypeInfo;

return S_OK;

    /* [in] */ REFIID riid,
    /* [size_is][in] */ OLECHAR** rgszNames,
    /* [in] */ UINT cNames,
    /* [in] */ LCID lcid,
    /* [size_is][out] */ DISPID* rgDispId)
    if(TypeInfo == NULL)
        return E_NOTIMPL; // shouldn't happen

    return TypeInfo->GetIDsOfNames(rgszNames, cNames, rgDispId);

    /* [in] */ DISPID dispIdMember,
    /* [in] */ REFIID /*riid*/,
    /* [in] */ LCID /*lcid*/,
    /* [in] */ WORD wFlags,
    /* [out][in] */ DISPPARAMS* pDispParams,
    /* [out] */ VARIANT* pVarResult,
    /* [out] */ EXCEPINFO* pExcepInfo,
    /* [out] */ UINT* puArgErr)
    if(TypeInfo == NULL)
        return E_NOTIMPL; // shouldn't happen

    return TypeInfo->Invoke(BrowserExternal, dispIdMember, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);

Ok and finally we actually have to connect the pieces, note this is not complete code, you have to copy each part into the designated section
#include "External.h"
#include "TCppWebBrowserUtils.h"

//form variables:
MyDocHandler* scriptdochandler;
TExternalDispatch* webscripter_external;
THashedStringList* GlobalVariables;

//now add in constructor
webscripter_external = new TExternalDispatch();
scriptdochandler = new MyDocHandler();
GlobalVariables = new THashedStringList();

now find a good place to do the below, after of course we've ensured that Document exists and Navigate(L"about:blank"); or something

//after we load the first document CppWebBrowser1->Document will be NULL until we do a Navigate()

ICustomDoc *custdoc;

//change the popupmenu
//dochandler->PopupMenu = PopupMenu;

//enable Global Variables
webscripter_external->getBrowserExternal()->GlobalVariables = GlobalVariables;

//allow pages to call window.external. (this might be a security flaw)

if (custdoc)

put this in the destructor, or OnClose() or whatever
//now don't forget to free memory
delete webscripter_external;
delete scriptdochandler;
delete GlobalVariables; //perhaps let them persist? -- save to file?

Wala!!, now go ahead and try it out:
String js = "window.external.SetVar('foo','bar');";
ExecJs(WebScripter, js);
ExecJs(WebScripter, L"alert(window.external.GetVar('foo'));");

You can add more methods that take integers and strings and boolean

We should!!!

FARR Plugins and Aliases / Re: KlipKeeper (A FARR2 Plugin by hamradio)
« on: September 17, 2009, 04:51 PM »
thanks for the plugin,
I really like it, the ding makes me feel special when i copy to clipboard knowing it is saved!

open source, we can easily make a mod for donationcoders =)

i tried it out, much fun, but how exactly do you turn key board keys into clicks?

Living Room / Re: The 150 Best Online Flash Games
« on: October 09, 2008, 01:49 AM »
that programming light game is fun, thanks!

i tried all these games and they are all somewhat challenging fun fun

funny you mention hedgewars, i just got done with Wormux, an open source worms clone with network play,
check it out

i downloaded hedgewars and got a white screen behind all of the hedgehogs when trying to play, not sure why =(

pretty much unplayable, anyone else have the same problems?

Living Room / Re: One answered question before you died
« on: October 08, 2008, 11:56 PM »
why didn't i turn to God earlier in my life?

Borland C++ Builder Contest / Re: FlashCard Pro
« on: September 09, 2006, 08:48 AM »
Yeah thanks for the help,
it is only a firefox problem..
I contacted the programmer of HTML Helpmatic pro and told him how to fix it
in the mean time, i am going to use regex buddy to regex replace all the files


Borland C++ Builder Contest / FlashCard Pro
« on: August 14, 2006, 07:21 PM »
FlashCard Pro
FlashCard Pro is a tool to help you study.

Works great for high school and college students. I used it for my Spanish class last semester!


Download (includes 6 free flash card sets)

Borland C++ Builder Contest / Trandesk Multiple Desktops
« on: August 14, 2006, 02:54 AM »
Trandesk Multiple Desktops
A Multiple Desktop Manager

Well, have you ever tried XP's powertoys, Microsoft coded a multiple desktop app, but I found many improvements and started working on Trandesk.

I think the best part is doing Ctrl-Alt-D and pressing left right up or down to switch desktops... <-- documentation


Hello, i am a student of University Maryland Baltimore County ( I am about to graduate with a BS in COMP SCI in Dec. 2006
I submitted Pandemic List and Oracle SQLPlusPlus. I love coding in C++Builder
and I am ready to submit more apps, but I don't have a lot of time working 9 and 10 hour days for Lockheed Martin...

I have a webpage at
I also am a chess expert according to USCF ratings.

Sorry it took me so long to say something
Thanks a lot mouser!

Borland C++ Builder Contest / Oracle SQL PlusPlus
« on: July 25, 2006, 08:38 AM »
Oracle SQL*PlusPlus
Because SQLPlus wasn't good enough....

If anyone uses ORACLE for a database server, then you'll love SQLPlusPlus.
Syntax highlighting, a nice Grid to view your queries.
A command history.
Support for running scripts.
I was sick and tired of SQLPlus, so I coded my own and now I use it all the time for complex queries and for simple ones...
Here is a screenshot of the latest version, with options to view your data how you want it.


You can download a demo below, you will need oracle server (or some connection that allows you to connect remotely)

what about a network-multiplayer version?

Absolutely great game!!!
now it just needs a multiplayer version

I definitely need everyone's suggestions, it is hard to make such a program that works exactly with the goals I had in mind...

My goals for this program were
  - Light Weight, Not to use any Hooking or hard API calls
  - Not to make it obtrusive, but rather a helping aid
  - Extremely fast to write notes, (instead of opening notepad and saving the file on your desktop, you have this method)
  - Ability to keep track of completed history ....Using the green completed items, it lets you know that you have accomplished something
  - To make it feel as if it were a part of the program it was used for (an IDE or something), enough that it could replace the existing to-do lists


Pandemic List
A self-customizing to-do list

The problem that I had was that not every program has a to-do list, furthermore, I was working on a project that consisted of multiple sub-projects using different IDEs, and I would use a to-do list in one, and then switch to the other app and i lost track of all my items.

My solution was to create a self-customized todo list. One that does the job, looks simple. I got part of my layout idea from Frontpage's todo list, which was very easy to add items, and was not complicated.

Also C++Builder 6 had a todo list which was very useful, but it is slow, and item completion is a little ok.

There are 4 different views for the todo list, my most recent view I added today was the TrayIcon popup view.
When you switch applications and a new todo item happens, the tray icon animates.

Screenshot of Pandemic-List Popup

Screenshot of Pandemic-List Floating View
SECONDS LATER, it looks like this!!! What happens when I start browsing the internet with internet explorer?
notice under "associated application" i have it customized to "Internet Research", which uses a regular expression to match all Internet Explorer windows. As soon as Internet explorer is focused, the to-do list items appear (this can be disabled when "Show All Items" is checked).

Also we can dock it to the right side of the screen so we ALWAYS know what to do

Docked to the Top of the screen
Notice you can copy/cut and paste items to and from text!!!

below is my items pasted (in INI format), in the future, i'm thinking about rich text version so we can paste directly in WORD!

Task=send in rebates
DateModified=7/23/2006 7:03:52 PM
DateCreated=7/23/2006 7:03:52 PM

Task=OCR research
Application=Internet Research
DateModified=7/23/2006 7:31:58 PM
DateCreated=7/23/2006 7:31:58 PM

Task=submit pandemic list
DateModified=7/23/2006 7:04:04 PM
DateCreated=7/23/2006 7:04:04 PM

Finished Programs / Re: DONE - Idea: Movie Cache Viewer
« on: December 15, 2005, 01:46 AM »
GREAT JOB!!! I Love this app!
In fact I love all of your apps.... How did you learn to be so good in that small scripting AutoHotkey language?
That is really cool.

I was wondering if you could make a tool to lock every window EXCEPT a particular one. Like if i have to work on a paper, I would ONLY be able to use Microsoft Word until i am done the paper (prevent distractions).


General Software Discussion / Eingame spikes??
« on: November 07, 2005, 10:46 AM »
 :D I was thinking about that! But i think if anything I will improve the 2d version so its easy to make maps

one thing that I want to improve is the spike walls. Ein runs into them and the box pops up where you have to guess a number.  Most people HATE doing the math and trying to figure out the number. But my question is what else can you do that is effective in guarding an area?

Download Eingame 0.9

Eingame Web page

General Software Discussion / Re: A few new programs
« on: November 07, 2005, 05:23 AM »
i really want to continue eingame!

seems to be a "programmer's favorite"

what are the shareware ones?

General Software Discussion / A few new programs
« on: November 07, 2005, 03:34 AM »
Hey I have a ton of small apps at
can you tell me what you guys think
(just added the SignupRecordTracker and the PowerNamer


Pages: prev1 2 3 [4]