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

📄 server.cpp

📁 将UCOS与UCGUI整合到一起,并在BORLAND C++上运行通过的源程序.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
      - initialize the document with the contents of file "lpszTemplate"
      - associate handle "lhDoc" with the document
      - store the pointer to the TOLEDocument in "lplpOleDoc"
      - return OLE_OK if successful, OLE_ERROR_TEMPLATE 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...

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

	if (pDoc == NULL)
		return OLE_ERROR_NEW;

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


/*
    callback Edit
    -------- ----

    called by the server library when a client application has activated
    an embedded object for editing

    this is exactly like "Create" except that the document will receive a
    "GetData" message to create the object and the object will receive a
    "SetData" message to initialize itself

    "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)
      - associate handle "lhDoc" with the document
      - store the pointer to the TOLEDocument in "lplpOleDoc"
      - return OLE_OK if successful, OLE_ERROR_EDIT otherwise
*/
OLESTATUS FAR PASCAL _export
TOLEServer::Edit (LPOLESERVER         lpOleSvr,
	                LHSERVERDOC         lhDoc,
	                LPSTR               /* lpszClassName */,
	                LPSTR               /* lpszDoc */,
	                LPOLESERVERDOC FAR *lplpOleDoc)
{
  TOLEServer    *pServer = (TOLEServer *) lpOleSvr;
  TOLEDocument  *pDoc = new TOLEDocument (*pServer, lhDoc);

  if (pDoc == NULL)
    return OLE_ERROR_EDIT;

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


/*
    callback Exit
    -------- ----

    we have been instructed by the library to exit immediately because of a
    fatal error

    WHAT TO DO:
      - hide the window to prevent user interaction
      - call OleRevokeServer() and ignore a return of OLE_WAIT_FOR_RELEASE
      - terminate the application immediately
      - return OLE_OK if successful, OLE_ERROR_GENERIC otherwise
*/
OLESTATUS FAR PASCAL _export
TOLEServer::Exit (LPOLESERVER lpOleSvr)
{
  GetApplicationObject()->MainWindow->Show (SW_HIDE);
	OleRevokeServer (((TOLEServer *) lpOleSvr)->lhServer);
  PostAppMessage (GetCurrentTask(), WM_QUIT, 0, 0);
  return OLE_OK;
}


/*
    callback Open
    -------- ----

    user has activated a linked object in an OLE client by calling OleActivate()

    similar to CreateFromTemplate in that we need to create a document,
    initialize it with the contents of file "lpszDoc", and save the file name
    for later use...

    WHAT TO DO:
      - create a TOLEDocument of class "lpszClassName" (since we only have one
        class we can ignore the class name)
      - initialize the document with the contents of file "lpszDoc"
      - associate handle "lhDoc" with the document
      - store the pointer to the TOLEDocument in "lplpOleDoc"
      - save file name "lpszDoc"
      - return OLE_OK if successful, OLE_ERROR_OPEN otherwise
*/
OLESTATUS FAR PASCAL _export
TOLEServer::Open (LPOLESERVER         lpOleSvr,
	                LHSERVERDOC         lhDoc,
	                LPSTR               lpszDoc,
	                LPOLESERVERDOC FAR *lplpOleDoc)
{
  TOLEServer    *pServer = (TOLEServer *) lpOleSvr;
  TOLEDocument  *pDoc = new TOLEDocument (*pServer, lhDoc, lpszDoc);

  if (pDoc == NULL)
    return OLE_ERROR_EDIT;

  else {
    *lplpOleDoc = pDoc;
    return OLE_OK;
  }
}


/*
    callback Release
    -------- -------

    this routine gets called by the server library after the server has
    called OleRevokeServer() and when the DDE conversation with the client has
    been successfully closed

    this tells us that there are no connections to the server, its documents,
    or their objects and that we are free to terminate

    WHAT TO DO:
      - set a flag to indicate that "Release" has been called
      - if the application is hidden and we *haven't* called OleRevokeServer()
        then we *must* terminate by posting a WM_CLOSE message
      - free any resources allocated including documents, but *not* the
        OLESERVER structure
      - return OLE_OK if successful, OLE_ERROR_GENERIC otherwise

    NOTE: this routine is tricky because it is invoked under different
          circumstances

      - user brought up the server and then closes it, which causes us
        to call OleRevokeServer() which means the server will eventually
        receive a "Release" message

      - the server was started to perform an invisible update for a client (i.e.
        the server has always been hidden). in this case the server will receive
        a "Release" message and we must tell ourselves to close because there
        is no user interaction...
*/
OLESTATUS FAR PASCAL _export
TOLEServer::Release (LPOLESERVER lpOleSvr)
{
  //
  // if we haven't been sent a "Release" message yet and our main window is
  // hidden then we post a quit message
  //
  // NOTE: call PostMessage (hWnd, WM_CLOSE, 0, 0) and not PostQuitMessage (0)
  //       because PostQuitMessage() might bypass your application's necessary
  //       cleanup procedures
  //
  TOLEApp     *pApp = (TOLEApp *) GetApplicationObject();
  TOLEServer  *pServer = (TOLEServer *) lpOleSvr;
  BOOL         embedded = pServer->pDocument->type == doctypeEmbedded;

  if (!pServer->fRelease &&
      (embedded || !IsWindowVisible (pApp->MainWindow->HWindow)))
    PostMessage (pApp->MainWindow->HWindow, WM_CLOSE, 0, 0);

  pServer->fRelease = TRUE;
	return OLE_OK;
}


/*
    callback Execute
    -------- -------

    if your app supports DDE execution commands then you would handle this
    event

    since we don't we return OLE_ERROR_COMMAND
*/
OLESTATUS FAR PASCAL _export
TOLEServer::Execute (LPOLESERVER /*lpOleSvr */,
	                   HANDLE      /* hCommands */)
{
	return OLE_ERROR_COMMAND;
}



typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVRCREATE)(LPOLESERVER, LHSERVERDOC, const char far *, const char far *, LPOLESERVERDOC FAR *);
typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVRCREATEFROMTEMPL)(LPOLESERVER,LHSERVERDOC,const char far *, const char far *, const char far *, LPOLESERVERDOC FAR *);
typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVREDIT)(LPOLESERVER,LHSERVERDOC,const char far *, const char far *, LPOLESERVERDOC FAR *);
typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVROPEN)(LPOLESERVER,LHSERVERDOC, const char far *, LPOLESERVERDOC FAR *);
typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVREXECUTE)(LPOLESERVER, HANDLE);
typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVREXIT)(LPOLESERVER);
typedef OLESTATUS FAR PASCAL _export (FAR *LPSRVRRELEASE)(LPOLESERVER);


/*
    InitVTBL
    --------

    create thunks for OLESERVER method callback tables
*/
BOOL
TOLEServer::InitVTBL (HINSTANCE hInstance)
{
	_vtbl.Create = (LPSRVRCREATE) MakeProcInstance ((FARPROC) Create, hInstance);
	_vtbl.CreateFromTemplate = (LPSRVRCREATEFROMTEMPL) MakeProcInstance ((FARPROC) CreateFromTemplate,
                                                                       hInstance);
	_vtbl.Edit = (LPSRVREDIT) MakeProcInstance ((FARPROC) Edit, hInstance);
	_vtbl.Exit = (LPSRVREXIT) MakeProcInstance ((FARPROC) Exit, hInstance);
	_vtbl.Execute = (LPSRVREXECUTE) MakeProcInstance ((FARPROC) Execute, hInstance);
	_vtbl.Open = (LPSRVROPEN) MakeProcInstance ((FARPROC) Open, hInstance);
	_vtbl.Release = (LPSRVRRELEASE) MakeProcInstance ((FARPROC) Release, hInstance);

  return _vtbl.Create != NULL &&
         _vtbl.CreateFromTemplate != NULL &&
         _vtbl.Edit != NULL &&
         _vtbl.Execute != NULL &&
         _vtbl.Open != NULL &&
         _vtbl.Release != NULL;
}

⌨️ 快捷键说明

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