4.7.5 File Save As

The File Save As command saves an untitled or existing file under a new name and operates differently for embedding and linking.

If the document contains an embedded object, the server application should prompt the user to update the objects before breaking the connection.

Retrieve the new filename.

Create and write the file.

Call OleSavedServerDoc, informing the server DLL that the document has been saved.

Call OleRenameServerDoc, informing the server DLL that the document has a new name.

Change the window title bar to reflect the new filename. If the object was embedded, reconfigure the user-interface for a stand-alone server application.

The following code examples shows how SRVRDEMO.EXE implements the File Save As command:

case IDM_SAVEAS:

if (!SaveDocAs ())

break;

if (docMain.doctype != doctypeEmbedded)

EmbeddingModeOff();

break;

/*

* SaveDocAs

* Prompts for a filename, and saves the document under that filename

*

* RETURNS: TRUE if successful or user chose CANCEL

* FALSE if SaveDocIntoFile fails

*/

BOOL SaveDocAs (void)

{

char szDoc[cchFilenameMax];

char szDocOld[cchFilenameMax];

BOOL fUpdateLater = FALSE;

// If document is embedded, give the user a chance to update.

// Save old document name in case the save fails.

if (!GlobalGetAtomName (docMain.aName, szDocOld, cchFilenameMax))

ErrorBox ("Fatal Error: Document name is invalid.");

//Prompt user for filename

if (GetFileSaveFilename (szDoc))

{

//Is it an embedded object?

if (docMain.doctype == doctypeEmbedded)

return SaveDocIntoFile(szDoc);

if (fUpdateLater)

{

// The non-standard OLE client did not accept the update

// when we requested it, so we are sending the client

// OLE_CLOSED now that we are closing the document.

SendDocMsg (OLE_CLOSED);

}

// Set the window title bar.

SetTitle (szDoc, FALSE);

OleRenameServerDoc(docMain.lhdoc, szDoc); //Alert DLL of change

if (SaveDocIntoFile(szDoc))

return TRUE;

else

{ // Restore old name

SetTitle (szDocOld, FALSE);

OleRenameServerDoc(docMain.lhdoc, szDocOld);

return FALSE;

}

}

else // user chose Cancel

return FALSE;

// The user chose the "Yes, Update" button but the File Open

// dialog box failed for some reason perhaps the user chose

// Cancel). Even though the user chose "Yes, Update", there

// is no way to update a non-standard OLE client that does

// not accept updates except when the document is closed.

}