⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cpp

📁 将UCOS与UCGUI整合到一起,并在BORLAND C++上运行通过的源程序.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ObjectWindows - (C) Copyright 1992 by Borland International

/* implementation of class TOLEServer */

#include <owl.h>

#define SERVERONLY
#include <ole.h>
#include "shellapi.h"  // registration database

#include "olesrvr.h"

OLESERVERVTBL  TOLEServer::_vtbl;

/*
    WantsToRegister
    ---------------

    displays an action message prompting the user to see if they want to
    register szAppName with the system registration database

    return TRUE if user says YES and FALSE is users says NO

    if user says NO we terminate the app
*/
BOOL
TOLEServer::WantsToRegister ()
{
  char  buf[128];

  wsprintf (buf,
            "\"%s\" is not registered as an OLE server in the system registration \
database. Do you want to register it?",
            (LPSTR) szAppName);

  if (MessageBox (0, buf, szAppName, MB_YESNO | MB_ICONQUESTION) == IDYES)
    return TRUE;

  else {
    //
    // terminate the app
    //
    PostAppMessage (GetCurrentTask(), WM_QUIT, 0, 0);

    //
    // we also need to make sure that the main window doesn't get displayed
    //
    // we have a couple of choices: set "nCmdShow" to SW_HIDE or set "Status"
    // to non-zero. since the user electing not to register isn't really an
    // error, let's set "nCmdShow"
    //
    GetApplicationObject()->nCmdShow = SW_HIDE;
    return FALSE;
  }
}


/*
    RegisterWithDatabase
    --------------------

    register ourselves as an OLE server with the system registration database

    this would typically be done during *installation* of the app and not when
    the app runs...

    NOTE: we first prompt the user to see if they want us to register. if so we
          register and if not we terminate the app
*/
BOOL
TOLEServer::RegisterWithDatabase ()
{
  char  buf[128];
  char  path[MAXPATHLENGTH];
  int   pathLen;

  if (!WantsToRegister())
    return FALSE;

  else {
    wsprintf (buf, ".%s", (LPSTR) szFileExt);
    RegSetValue (HKEY_CLASSES_ROOT,
                 buf, REG_SZ,
                 szClassKey, sizeof (szClassKey) - 1);

    RegSetValue (HKEY_CLASSES_ROOT,
                 szClassKey, REG_SZ,
                 szClassValue, sizeof (szClassValue) - 1);

    //
    // register verb actions EDIT and PLAY with EDIT being the primary verb
    //
    wsprintf (buf, "%s\\protocol\\StdFileEditing\\verb\\0", (LPSTR) szClassKey);
    RegSetValue (HKEY_CLASSES_ROOT, buf, REG_SZ, "Edit", 4);

    wsprintf (buf, "%s\\protocol\\StdFileEditing\\verb\\1", (LPSTR) szClassKey);
    RegSetValue (HKEY_CLASSES_ROOT, buf, REG_SZ, "Play", 4);

    //
    // register a full pathname to the executable with the database
    //
    pathLen = GetModuleFileName (GetModuleHandle (szExeName), path, sizeof (path));
    wsprintf (buf, "%s\\protocol\\StdFileEditing\\server", (LPSTR) szClassKey);
    RegSetValue (HKEY_CLASSES_ROOT, buf, REG_SZ, path, pathLen);

    //
    // inform the user that we have registered as an OLE server by displaying
    // an information message
    //
    wsprintf (buf,
              "\"%s\" successfully registered as an OLE server with the system registration database.",
              (LPSTR) szAppName);

    MessageBox (0, buf, szAppName, MB_OK | MB_ICONINFORMATION);
    return TRUE;
  }
}


/*
    Init
    ----
*/
BOOL
TOLEServer::Init (TOLEApp &app)
{
  OLESTATUS   status;

  lpvtbl = &_vtbl;
  fRelease = FALSE;
  app.pServer = this;

  //
  // since we can't handle multiple documents (MDI), request that we use
  // multiple instances to support multiple objects
  //
	status = OleRegisterServer (szClassKey,
						                  this,
						                  &lhServer,
						                  app.hInstance,
						                  OLE_SERVER_MULTI);

  if (status == OLE_ERROR_CLASS) {
    if (RegisterWithDatabase())
  	  OleRegisterServer (szClassKey,
  						           this,
  						           &lhServer,
  						           app.hInstance,
  						           OLE_SERVER_MULTI);

    else
      return FALSE;
  }

  return TRUE;
}


/*
    constructor
    -----------

    creates an untitled OLE document
*/
TOLEServer::TOLEServer (TOLEApp &app, BOOL embedded)
{
  if (Init (app) && !embedded)
    pDocument = new TOLEDocument (*this);
}


/*
    constructor
    -----------

    creates an OLE document and initializes it from file "szPath"
*/
TOLEServer::TOLEServer (TOLEApp &app, LPSTR szPath)
{
  if (Init (app))
    pDocument = new TOLEDocument (*this, 0, szPath);
}


/*
    callback Create
    -------- ------

    called by the server library when a client application has created a
    new embedded object by calling OleCreate()

    WHAT TO DO:
      - create an *untitled* TOLEDocument of class "lpszClassName" (since we
        only have one class we can ignore the class name) and mark it as dirty
      - associate handle "lhDoc" with the document
      - store the pointer to the TOLEDocument in "lplpOleDoc"
      - return OLE_OK if successful, OLE_ERROR_NEW otherwise

    if your app is an MDI application then you would also allocate a window
    here, but since this app isn't the window is already created...

    "lpszDoc" is the name of the document as it appears in the client
    class. DON'T use this to change the title bar, use what you get when
    the document is sent message "SetHostNames"

    NOTE: since we only have one document we could have created it during
          initialization
*/
OLESTATUS FAR PASCAL _export
TOLEServer::Create (LPOLESERVER         lpOleSvr,
	                  LHSERVERDOC         lhDoc,
	                  LPSTR               /* lpszClassName */,
	                  LPSTR               /* lpszDoc */,
	                  LPOLESERVERDOC FAR *lplpOleDoc)
{
  TOLEServer    *pServer = (TOLEServer *) lpOleSvr;
	TOLEDocument  *pDoc = new TOLEDocument (*pServer, lhDoc, 0, TRUE);

	if (pDoc == NULL)
		return OLE_ERROR_NEW;

  else {
  	*lplpOleDoc = pDoc;
    ((TWindowServer *) GetApplicationObject()->MainWindow)->BeginEmbedding();
  	return OLE_OK;
  }
}


/*
    callback CreateFromTemplate
    -------- ------------------

    called by the server library when a client application has created a
    new linked object specifying a template by calling OleCreateFromTemplate()

    what this really means is that we need to create a document and initialize
    it with the contents of a file...

    "lpszDoc" is the name of the document as it appears in the client
    class. DON'T use this to change the title bar, use what you get when
    the document is sent message "SetHostNames"

    WHAT TO DO:
      - create a TOLEDocument of class "lpszClassName" (since we only have one
        class we can ignore the class name)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -