| Tenouk C & C++ | MFC Home | ActiveX Doc Servers & Internet 2 | ActiveX Doc Servers & Internet 4 | Download | Site Index |


 

 

 

 

 

 

ActiveX Document Servers and the Internet Part 3

 

 

 

 

 

 

Program examples compiled using Visual C++ 6.0 compiler on Windows XP Pro machine with Service Pack 2 and some Figure screen snapshots have been taken on Windows 2000 server. The Internet Information Services version is IIS 4.x/5.x/6.x on Windows 2000 Server SP 4 and Windows XP Pro SP 2. The Internet Explorer is 6.x. Topics and sub topics for this tutorial are listed below. A complete information about IIS installation, configuration and testing a Web site is dumped HERE and how to setup FTP server also included HERE. Both Web and FTP servers were done on Windows 2000 Server SP4. Don’t forget to read Tenouk’s small disclaimer.

  1. The Story of MYEX35A Phase 2: Adding WinInet Calls

  2. Displaying Bitmaps on Buttons

  3. ActiveX Document Server Example MYEX35B

  4. MYEX35B From Scratch

 

 

 

The Story of MYEX35A Phase 2: Adding WinInet Calls

 

The completed MYEX35A example includes two dialog bar objects, one for the main frame window and another for the in-place frame window. Both are attached to the same resource template, IDD_DIALOGBAR, which contains an edit control that accepts a text file URL plus start and stop buttons that display green and red bitmaps. If you click the green button (handled by the OnStart() member function of the CMyex35aView class), you'll start a thread that reads the text file one line at a time. The thread code from the file UrlThread.cpp is shown here:

 

CString g_strURL = "http:// ";

volatile BOOL g_bThreadStarted = FALSE;

CEvent g_eKill;

 

UINT UrlThreadProc(LPVOID pParam)

{

    g_bThreadStarted = TRUE;

    CString strLine;

    CInternetSession session;

    CStdioFile* pFile1 = NULL;

 

    try {

        pFile1 = session.OpenURL(g_strURL, 0, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_KEEP_CONNECTION); // needed for Windows NT c/r authentication

        // Keep displaying text from the URL until the Kill event is

        //  received

        while(::WaitForSingleObject(g_eKill.m_hObject, 0) != WAIT_OBJECT_0) {

            // one line at a time

            if(pFile1->ReadString(strLine) == FALSE) break;

            strLine += `\n';

            ::SendMessage((HWND) pParam, EM_SETSEL, (WPARAM) 999999, 1000000);

            ::SendMessage((HWND) pParam, EM_REPLACESEL, (WPARAM) 0, (LPARAM) (const char*) strLine);

            Sleep(250); // Deliberately slow down the transfer

        }

    }

    catch(CInternetException* e) {

        LogInternetException(pParam, e);

        e->Delete();

    }

    if(pFile1 != NULL) delete pFile1; // closes the file—prints a warning

    g_bThreadStarted = FALSE;

    // Post any message to update the toolbar buttons

    ::PostMessage((HWND) pParam, EM_SETSEL, (WPARAM) 999999, 1000000);

    TRACE("Post thread exiting normally\n");

    return 0;

}

 

This code uses the CStdioFile pointer to pFile1 returned from OpenURL(). The ReadString member function reads one line at a time, and each line is sent to the rich edit view window. When the main thread sets the "kill" event (the red button), the URL thread exits. Before you test MYEX35A, make sure that the server (MYEX34A or IIS) is running and that you have a text file in the server's home directory. Test the MYEX35A program first in stand-alone mode by entering the text file URL in the dialog bar. Next try running the program in server mode from Internet Explorer. Enter test.35a (the document you created when you ran MYEX35A in stand-alone mode) in Internet Explorer's Address field to load the server.

We considered using the CAsyncMonikerFile class instead of the MFC WinInet classes to read the text file. We stuck with WinInet, however, because the program could use the CStdioFile class ReadString() member function to "pull" individual text lines from the server when it wanted them. The CAsyncMonikerFile class would have "pushed" arbitrary blocks of characters into the program (by calling the overridden OnDataAvailable() function) as soon as the characters had been received.

 

Displaying Bitmaps on Buttons

 

Module 21 describes the CBitmapButton class for associating a group of bitmaps with a pushbutton. Microsoft Windows 95, Microsoft Windows 98, and Microsoft Windows NT 4.0 above support an alternative technique that associates a single bitmap with a button. First you apply the Bitmap style (on the button's property sheet) to the button, and then you declare a variable of class CBitmap that will last at least as long as the button is enabled. Then you make sure that the CButton::SetBitmap function is called just after the button is created. Here is the code for associating a bitmap with a button, from the MYEX35A MainFrm.cpp and IpFrame.cpp files:

m_bitmapGreen.LoadBitmap(IDB_GREEN);

HBITMAP hBitmap = (HBITMAP) m_bitmapGreen.GetSafeHandle();

((CButton*) m_wndDialogBar.GetDlgItem(IDC_START))->SetBitmap(hBitmap);

If your button was in a dialog, you could put similar code in the OnInitDialog() member function and declares a CBitmap member in the class derived from CDialog.

 

ActiveX Document Server Project Example: MYEX35B

 

Look at the pizza form example from Module 33 (MYEX34A). Note that the server (the ISAPI DLL) processes the order only when the customer clicks the Submit Order Now button. This is okay for ordering pizzas because you're probably happy to accept money from anyone, no matter what kind of browser is used.

For a form-based intranet application, however, you can be more selective. You can dictate what browser your clients have, and you can distribute your own client software on the net. In that environment, you can make data entry more sophisticated, allowing, for example, the client computer to validate each entry as the user types it. That's exactly what's happening in MYEX35B, which is another ActiveX document server, of course. MYEX35B is a form-based employee time-sheet entry program that works inside Internet Explorer (as shown in Figure 45) or works as a stand-alone application. Looks like a regular HTML form, doesn't it? It's actually an MFC form view, but the average user probably won't know the difference. The Name field is a drop-down combo box, however, which is different from the select field you would see in an HTML form, because the user can type in a value if necessary. The Job Number field has a spin button control that helps the user select the value. These aren't necessarily the ideal controls for time-sheet entry, but the point here is that you can use any Windows controls you want, including tree controls, list controls, trackbars, and ActiveX controls, and you can make them interact any way you want.

 

ActiveX document and Internet - Figure 45: Employee time-sheet entry form.

 

Figure 45: Employee time-sheet entry form.

 

MYEX35B From Scratch

 

Let build MYEX35B from scratch. This is an SDI application program. Follow the shown steps.

 

ActiveX document and Internet - Figure 46: MYEX35B – MFC AppWizard new project dialog.

 

Figure 46: MYEX35B – MFC AppWizard new project dialog.

 

ActiveX document and Internet - Figure 47: MYEX35B – MFC AppWizard step 1 of 6.

 

Figure 47: MYEX35B – MFC AppWizard step 1 of 6.

 

ActiveX document and Internet - Figure 48: MYEX35B – MFC AppWizard step 2 of 6.

 

Figure 48: MYEX35B – MFC AppWizard step 2 of 6.

 

ActiveX document and Internet - Figure 49: MYEX35B – MFC AppWizard step 3 of 6, selecting the compound document and deselecting the Automation and ActiveX Controls.

 

Figure 49: MYEX35B – MFC AppWizard step 3 of 6, selecting the compound document and deselecting the Automation and ActiveX Controls.

 

ActiveX document and Internet - Figure 50: MYEX35B – MFC AppWizard step 4 of 6.

 

Figure 50: MYEX35B – MFC AppWizard step 4 of 6.

 

Click the Advanced button. Enter the File Extension as shown below.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ActiveX document and Internet - Figure 51: MYEX35B – entering a file extension.

 

Figure 51: MYEX35B – entering a file extension.

 

ActiveX document and Internet - Figure 52:  MYEX35B – MFC AppWizard step 5 of 6.

 

Figure 52:  MYEX35B – MFC AppWizard step 5 of 6.

 

ActiveX document and Internet - Figure 53: MYEX35B – MFC AppWizard step 6 of 6, Selecting CFormView as the base class.

 

Figure 53: MYEX35B – MFC AppWizard step 6 of 6, Selecting CFormView as the base class.

 

ActiveX document and Internet - Figure 54: MYEX35B project summary.

 

Figure 54: MYEX35B project summary.

 

Insert a dialog and controls. Use the following information and Figures for the dialog and controls.

 

Resource

ID

Caption/text

Dialog

IDD_ADDRDIALOG

Internet Address Dialog

Static text

-

Server Name:

Static text

-

File:

Edit control

IDC_SERVERNAME

-

Edit control

IDC_FILE

-

 

Table 3.

 

ActiveX document and Internet - Figure 55: IDD_ADDRDIALOG property page.

 

Figure 55: IDD_ADDRDIALOG property page.

 

ActiveX document and Internet - Figure 56: IDC_SERVERNAME, an edit control property page.

 

Figure 56: IDC_SERVERNAME, an edit control property page.

 

ActiveX document and Internet - Figure 57: IDC_FILE property page.

 

Figure 57: IDC_FILE property page.

 

 

Insert another dialog with the following information.

 

Resource

ID

Caption/text/other

Dialog

IDD_MYEX35B_FORM

Styles – Style: Child, Border: None, deselect Title bar

 

Table 4.

 

 

ActiveX document and Internet - Figure 58: IDD_MYEX35B_FORM dialog property page.

 

Figure 58: IDD_MYEX35B_FORM dialog property page.

 

ActiveX document and Internet - Figure 59: Styles dialog property page.

 

Figure 59: Styles dialog property page.

 

Resource

ID

Caption/text/other

Static texts

-

Employee time-sheet entry:    Period

Static texts

-

Name:

Static texts

-

Hours:

Static texts

-

Job Number:

Edit control

IDC_PERIOD

Styles - Left, Number, Auto HScroll, Border, Read-only.

Combo box

IDC_EMPLOYEE

Data – Kurt, Cobain, Jeremy, Matt Cutt, William, Dunkel, Diana, Major, Masterjee, Stallman (separate the name with Ctrl + Enter)

Edit control

IDC_HOURS

-

Edit control

IDC_JOB

Styles - Number

Spin control

IDC_SPIN1

Styles - Vertical, Unattached, Auto buddy, Set buddy integer, Arrow keys.

Button control

IDC_SUBMIT

Submit

Button control

IDCANCEL

Reset

 

Table 5.

 

ActiveX document and Internet - Figure 60: IDC_PERIOD property page.

 

Figure 60: IDC_PERIOD property page.

 

ActiveX document and Internet - Figure 61:  IDC_PERIOD Styles property page.

 

Figure 61:  IDC_PERIOD Styles property page.

 

ActiveX document and Internet - Figure 62: IDC_EMPLOYEE property page.

 

Figure 62: IDC_EMPLOYEE property page.

 

ActiveX document and Internet - Figure 63: IDC_EMPLOYEE sample data.

 

Figure 63: IDC_EMPLOYEE sample data.

 

ActiveX document and Internet - Figure 64: IDC_HOURS property page.

 

Figure 64: IDC_HOURS property page.

 

ActiveX document and Internet - Figure 65: IDC_JOB property page.

 

Figure 65: IDC_JOB property page.

 

ActiveX document and Internet - Figure 66: IDC_JOB Styles property page.

 

Figure 66: IDC_JOB Styles property page.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

------------------------------------------------------------------------------------

ActiveX document and Internet - Figure 67: IDC_SPIN1 property job.

 

Figure 67: IDC_SPIN1 property job.

 

ActiveX document and Internet - Figure 68: IDC_SPIN1 Styles property job.

 

Figure 68: IDC_SPIN1 Styles property job.

 

ActiveX document and Internet - Figure 69: IDC_SUBMIT property page.

 

Figure 69: IDC_SUBMIT property page.

 

ActiveX document and Internet - Figure 70: IDC_SUBMIT Styles property page.

 

Figure 70: IDC_SUBMIT Styles property page.

 

ActiveX document and Internet - Figure 71: IDCANCEL property page.

 

Figure 71: IDCANCEL property page.

 

Add menu and item in IDR_MAINFRAME, IDR_ SRVR_EMBEDDED and IDR_SRVR_INPLACE.

 

Resource

ID

Caption/text/other

Menu

-

Server

Menu item

ID_SERVER_ADDRESS

Address

 

Table 6.

 

ActiveX document and Internet - Figure 72: Adding menu and menu item to IDR_MAINFRAME.

 

Figure 72: Adding menu and menu item to IDR_MAINFRAME.

 

ActiveX document and Internet - Figure 73: Adding menu and menu item to IDR_SRVR_EMBEDDED.

 

Figure 73: Adding menu and menu item to IDR_SRVR_EMBEDDED.

 

ActiveX document and Internet - Figure 74: Adding menu and menu item to IDR_SRVR_INPLACE.

 

Figure 74: Adding menu and menu item to IDR_SRVR_INPLACE.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Further reading and digging:

  1. DCOM at MSDN.

  2. COM+ at MSDN.

  3. COM at MSDN.

  4. Win32 process, thread and synchronization story can be found starting from Module R.

  5. MSDN MFC 7.0 class library online documentation.

  6. MSDN MFC 9.0 class library online documentation - latest version.

  7. MSDN Library

  8. Windows data type.

  9. Win32 programming Tutorial.

  10. The best of C/C++, MFC, Windows and other related books.

  11. Unicode and Multibyte character set: Story and program examples.

 

 


 

| Tenouk C & C++ | MFC Home | ActiveX Doc Servers & Internet 2 | ActiveX Doc Servers & Internet 4 | Download | Site Index |