Click here to Skip to main content
15,868,054 members
Articles / Desktop Programming / ATL
Article

Generic AutoFill

Rate me:
Please Sign up or sign in to vote.
3.91/5 (11 votes)
14 Apr 2006CPOL4 min read 132.9K   2.5K   54   34
Generic AutoFill can automatically fill a html based form using some PC-based stored data. it’s an application very similar to Google Autofill.

Generic AutoFill Sample Image

Introduction

AutoFill is implemented in ATL as a browser helper object (BHO).  A BHO is a DLL that will attach itself to every new instance of Internet Explorer.  In the BHO you can intercept Internet Explorer events, and access the browser window and document object model (DOM).  This gives you a great deal of flexibility in modifying Internet Explorer behavior as well as some added functionality to use your utility as an IE-plug-in.

There are several advantages to using a BHO over an application that continually scans open windows for keywords in the title.  The BHO is event driven and does not run in a loop or use a timer, so it doesn't use any CPU cycles if nothing is happening.  

 

AutoFill<o:p __designer:dtid="281474976710686">

<o:p __designer:dtid="281474976710689">             

The AutoFill option in mouse right click on Internet Explorer enables you to automatically complete forms on the web. Enter your information and it's stored securely on your own computer. When you want to fill a form with previously entered data for fields in the web page, simply right click on the page and select AutoFill then choose Fill Form. In the next step you can select a form data from previously saved form.

To save initial data fill the form right click the page and select AutoFill and then Save Form As option. It’ll ask a form name for saving entered data. AutoFill stores personal data where only you can access it - your own computer. None of this information is ever sent to me or to any other server.

After filling form if you see that the required data is not in the chosen form then either you can flush the entered data using AutoFill->Flush Form option or you can manually enter the data.

 

<o:p __designer:dtid="281474976710695">    

Better than Google AutoFill<o:p __designer:dtid="281474976710700">

It’s better than Google AutoFill. I am figuring out some good features.

 

 

Fields Independent

It doesn’t depend on the already hard-coded html fields as Google AutoFill restricts user to fill only those fields which Google have given in their AutoFill template form. In my AutoFill any type of html form with any type of html fields can be saved as a template form data with a particular name. In this way user is not restricted to use a certain data for form filling even every type you are using a new form you can create a template data for this particular form and can use it later.

 

BHO Implementation

A minimal BHO is a COM server DLL that implements IObjectWithSite.  Create a new ATL Project and accept the default settings (attributed, DLL).  Add an ATL Simple Object, give it a name and on the Options tab select Aggregation: No and Support: IObjectWithSite. 

The only method on IObjectWithSite that must be implemented is SetSite().  IE will call SetSite with a pointer to IUnknown which we can query for a pointer to IWebBrowser2, which gives us the keys to the house.

 

//
// IOleObjectWithSite Methods
//
STDMETHODIMP CPub::SetSite(IUnknown *pUnkSite)
{
    if (!pUnkSite)
    {
        ATLTRACE(_T("SetSite(): pUnkSite is NULL\n"));
    }
    else
    {
        // Query pUnkSite for the IWebBrowser2 interface.
        m_spWebBrowser2 = pUnkSite;
        if (m_spWebBrowser2)
        {
            // Connect to the browser in order to handle events.
            HRESULT hr = ManageBrowserConnection(ConnType_Advise);
            if (FAILED(hr))
                ATLTRACE(_T("Failure sinking events from IWebBrowser2\n"));
        }
        else
        {
            ATLTRACE(_T("QI for IWebBrowser2 failed\n"));
        }
    }
    
    return S_OK;
}

Once we have the pointer to IWebBrowser2 we can hook up to the DWebBrowserEvents2 connection point in order to receive the NewWindow2 event.  This event is sent every time a new window is about to.

To create the event handler we have to derive our class from IDispatchImpl.

       

Then add the Invoke method as follows:

//
// IDispatch Methods
//
STDMETHODIMP CPub::Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
    WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult,
    EXCEPINFO*  pExcepInfo,  UINT* puArgErr)
{
    if (!pDispParams)
        return E_INVALIDARG;
    
    switch (dispidMember)
    {
        //
        // The parameters for this DISPID are as follows:
        // [0]: Cancel flag  - VT_BYREF|VT_BOOL
        // [1]: IDispatch* - Pointer to an IDispatch interface. 
        //
        // If you cancel here, ALL popups will be blocked.
        //
    case DISPID_NEWWINDOW2:
        // Set the cancel flag to block popups
        pDispParams->rgvarg[0].pvarVal->vt = VT_BOOL;
        pDispParams->rgvarg[0].pvarVal->boolVal = VARIANT_TRUE;
        break;
    default:
        break;
   }
   
   return S_OK;
}

One problem which occurs with BHO is that even with no open browser windows the linker will sometimes fail because some process is using the BHO, forcing you to reboot the computer to release it. The reason is that Windows Explorer also uses IE for its GUI, and so also loads the BHO. Since we want our BHO to load only when we launch IE, so I am changing DllMain so that it doesn't get loaded by Windows Explorer. This should eliminate the linker problem.

if (dwReason == DLL_PROCESS_ATTACH)
    {
        // Don't attach to Windows Explorer
        TCHAR pszLoader[MAX_PATH];
        GetModuleFileName(NULL, pszLoader, MAX_PATH);
        CString sLoader = pszLoader;
        sLoader.MakeLower();
        if (sLoader.Find(_T("explorer.exe")) >= 0)
            return FALSE;

        g_hinstPub = _AtlBaseModule.m_hInst;
    }

Now not going in more details of BHO, I am continuing with Form Handler.

I have created three menu option with mouse right click.

 

1. Save Form As<o:p>

This option supports an event handler which saves template data for a particular form at a pre-defined location which you can later use for AutoFilling the form.

 

Save Form As

 

2. AutoFill<o:p __designer:dtid="281474976710900">

This option supports actual AutoFill functionality. On choosing this option it opens a dialog where user can select a template data file from previously saved data.

AutoFill

3 Flush Form <o:p __designer:dtid="281474976710911">

If you don’t want to submit the auto filled form then you can flush the form by choosing this option

Support Taken:

I am taking support of article Popup Window Blocker by John Osborn. Thank you John thanx for your article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralFrame compatible Pin
antonello14-Mar-08 3:37
antonello14-Mar-08 3:37 
GeneralHowTo install Pin
antonello14-Mar-08 3:35
antonello14-Mar-08 3:35 
GeneralIE7 cannot open new page Pin
fifth811823-Jan-08 16:58
fifth811823-Jan-08 16:58 
Generalcrashing(has Just-In-Time debugger) Pin
brad b27-Dec-07 5:40
brad b27-Dec-07 5:40 
GeneralRe: crashing(has Just-In-Time debugger) Pin
Vishal Swarankar28-Dec-07 0:56
Vishal Swarankar28-Dec-07 0:56 
GeneralRe: crashing(has Just-In-Time debugger) Pin
brad b3-Jan-08 1:47
brad b3-Jan-08 1:47 
QuestionHow to install the toolbar on Internet Explorer ? Pin
DumitruC3-Nov-07 6:31
DumitruC3-Nov-07 6:31 
GeneralRe: How to install the toolbar on Internet Explorer ? Pin
Vishal Swarankar28-Dec-07 0:58
Vishal Swarankar28-Dec-07 0:58 
GeneralCross domain iframe Pin
rixwan23-Sep-07 21:35
rixwan23-Sep-07 21:35 
GeneralRe: Cross domain iframe Pin
Vishal Swarankar13-Oct-07 20:25
Vishal Swarankar13-Oct-07 20:25 
QuestionIE hangs when auto-fill is called Pin
kobelakers7616-Jul-07 9:25
kobelakers7616-Jul-07 9:25 
AnswerRe: IE hangs when auto-fill is called Pin
Vishal Swarankar13-Oct-07 20:20
Vishal Swarankar13-Oct-07 20:20 
Questionusing AutoFill Pin
vijay_sagi8-Apr-07 23:32
vijay_sagi8-Apr-07 23:32 
AnswerRe: using AutoFill Pin
1scouser12-Jun-07 12:03
1scouser12-Jun-07 12:03 
GeneralRe: using AutoFill Pin
Vishal Swarankar13-Oct-07 20:18
Vishal Swarankar13-Oct-07 20:18 
QuestionCan Javascript be embedded instead ? Pin
Andyzyx9-Feb-07 8:37
Andyzyx9-Feb-07 8:37 
AnswerRe: Can Javascript be embedded instead ? Pin
Vishal Swarankar13-Oct-07 20:16
Vishal Swarankar13-Oct-07 20:16 
GeneralSource for Generic Autofill Pin
jimmyy22-Dec-06 0:24
jimmyy22-Dec-06 0:24 
AnswerRe: Source for Generic Autofill Pin
Vishal Swarankar15-Jan-07 17:11
Vishal Swarankar15-Jan-07 17:11 
Questionfatal error LNK1250 when I link with an MFC app Pin
ibrahim.dina15-Nov-06 12:49
ibrahim.dina15-Nov-06 12:49 
AnswerRe: fatal error LNK1250 when I link with an MFC app Pin
Vishal Swarankar15-Nov-06 17:18
Vishal Swarankar15-Nov-06 17:18 
Questionjavascript pages Pin
ibrahim.dina7-Nov-06 13:31
ibrahim.dina7-Nov-06 13:31 
AnswerRe: javascript pages Pin
Vishal Swarankar7-Nov-06 17:32
Vishal Swarankar7-Nov-06 17:32 
Question2 forms on the same website Pin
ibrahim.dina7-Nov-06 13:28
ibrahim.dina7-Nov-06 13:28 
AnswerRe: 2 forms on the same website Pin
Vishal Swarankar7-Nov-06 17:29
Vishal Swarankar7-Nov-06 17:29 

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.