4.6.1 Changing the Window Title

Most full server applications that are able to open files display the name of the file somewhere in their title bar. For example, the Windows 3.1 Paintbrush application displays the filename of the currently loaded bitmap; otherwise, it uses the filename "(Untitled)."

The standard for filenames in the title bar of any application is:

<Application Name> - <Filename>

as shown in the following example for Paintbrush, if a bitmap with the filename CHESS.BMP were loaded:

Paintbrush - CHESS.BMP.

When a server is started for embedding, and only for embedding, the title bar should appear as:

<Application Name> - <Object Type> in <Client Document>

Embedded objects do not have filenames. The following title bar shows Paintbrush is editing an embedded object:

Paintbrush - Paintbrush Picture in CLIENT.DOC

SRVRDEMO.EXE uses the OLESERVERDOC SetHostNames callback function to set the window title bar:

/

* DocSetHostNames DOCUMENT "SetHostNames" METHOD

*

* The library uses this method to set the name of the

* document window. All this function does is change the

* title bar text. This function is only called for embedded

* objects; linked objects use their filenames for the title

* bar text.

*

* LPOLESERVERDOC lpoledoc - The server document

* LPSTR lpszClient - The name of the client

* LPSTR lpszDoc - The client's name for the document

*

* RETURNS: OLE_OK

*/

OLESTATUS FAR PASCAL DocSetHostNames (LPOLESERVERDOC lpoledoc, LPSTR

lpszClient, LPSTR lpszDoc)

{

SetTitle (lpszDoc, TRUE);

lstrcpy ((LPSTR) szClient, lpszClient);

lstrcpy ((LPSTR) szClientDoc, Abbrev(lpszDoc));

UpdateFileMenu (IDM_UPDATE);

return OLE_OK;

}

/* SetTitle

*

* Sets the main window's title bar. The format of the title bar is

* as follows:

*

* If embedded <Server App name> - <object type> in <client doc name>

* Example: "Server Demo - SrvrDemo Shape in OLECLI.DOC," where

* OLECLI.DOC is a Winword document; otherwise, <Server App name> -

* <server document name>

*

* Example: "Server Demo - OLESVR.SD"

* where OLESVR.SD is a Server demo document

*

* LPSTR lpszDoc - document name

* BOOL fEmbedded - If TRUE embedded document, else normal document

*

* RETURNS: OLE_OK

*/

void SetTitle (LPSTR lpszDoc, BOOL fEmbedded)

{

char szBuf[cchFilenameMax];

if (lpszDoc && lpszDoc[0])

{

// Change document name.

if (docMain.aName)

GlobalDeleteAtom (docMain.aName);

docMain.aName = GlobalAddAtom (lpszDoc);

}

if (fEmbedded)

{

//

if (lpszDoc && lpszDoc[0])

{

wsprintf (szBuf, "%s - SrvrDemo Shape in %s", (LPSTR)

szAppName, Abbrev (lpszDoc));

}

else

{

// Use name from docMain

char szDoc [cchFilenameMax];

GlobalGetAtomName (docMain.aName, szDoc, cchFilenameMax);

wsprintf (szBuf, "%s - SrvrDemo Shape in %s", (LPSTR)

szAppName, Abbrev (szDoc));

}

SetWindowText (hwndMain, (LPSTR)szBuf);

}

else if (lpszDoc && lpszDoc[0])

{

wsprintf (szBuf, "%s - %s", (LPSTR) szAppName, Abbrev(lpszDoc));

SetWindowText (hwndMain, szBuf);

}

}

/* UpdateFileMenu

*

* Updates the "Update <Client doc>" and "Exit & Return to

* <Client doc>" with the currently set client document name

*

*/

void UpdateFileMenu (int iSaveUpdateId)

{

char str[cchFilenameMax];

HMENU hMenu = GetMenu(hwndMain);

/* Change File menu so it contains "Update" instead of "Save". */

lstrcpy (str, "&Update ");

lstrcat (str, szClientDoc);

ModifyMenu(hMenu, iSaveUpdateId, MF_BYCOMMAND|MF_STRING,

IDM_UPDATE, str);

// Change File menu so it contains "Exit & Return to <client doc>"

// instead of just "Exit" */

lstrcpy (str, "E&xit && Return to ");

lstrcat (str, szClientDoc);

ModifyMenu(hMenu, IDM_EXIT, MF_BYCOMMAND|MF_STRING, IDM_EXIT, str);

}