Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

987 lines
26 KiB

  1. //**********************************************************************
  2. // File name: app.cpp
  3. //
  4. // Implementation file for the CSimpSvrApp Class
  5. //
  6. // Functions:
  7. //
  8. // See app.h for a list of member functions.
  9. //
  10. // Copyright (c) 1993 Microsoft Corporation. All rights reserved.
  11. //**********************************************************************
  12. #include "pre.h"
  13. #include "obj.h"
  14. #include "app.h"
  15. #include "doc.h"
  16. #include "icf.h"
  17. #include <msgfiltr.h>
  18. #include "initguid.h"
  19. DEFINE_GUID(GUID_SIMPLE, 0xBCF6D4A0, 0xBE8C, 0x1068, 0xB6, 0xD4, 0x00, 0xDD, 0x01, 0x0C, 0x05, 0x09);
  20. #ifdef WIN32
  21. extern INT_PTR CALLBACK About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam);
  22. #endif
  23. //+-------------------------------------------------------------------------
  24. //
  25. // Function: SimpsvrMsgCallBack
  26. //
  27. // Synopsis: Tell Standard Message Filter not to toss windows messages
  28. //
  29. // Arguments: [pmsg] - first message in the queue
  30. //
  31. // History: dd-mmm-yy Author Comment
  32. // 19-May-94 ricksa author
  33. //
  34. //--------------------------------------------------------------------------
  35. BOOL CALLBACK SimpsvrMsgCallBack(MSG *pmsg)
  36. {
  37. // We don't care about any of the in particular. We simply care that
  38. // our messages are not tossed not matter what.
  39. return TRUE;
  40. }
  41. //**********************************************************************
  42. //
  43. // CSimpSvrApp::CSimpSvrApp()
  44. //
  45. // Purpose:
  46. //
  47. // Constructor for CSimpSvrApp
  48. //
  49. // Parameters:
  50. //
  51. // None
  52. //
  53. // Return Value:
  54. //
  55. // None
  56. //
  57. // Function Calls:
  58. // Function Location
  59. //
  60. // TestDebugOut Windows API
  61. // SetRectEmpty Windows API
  62. //
  63. // Comments:
  64. //
  65. //
  66. //********************************************************************
  67. CSimpSvrApp::CSimpSvrApp()
  68. {
  69. TestDebugOut(TEXT("In CSimpSvrApp's Constructor \r\n"));
  70. // Set Ref Count
  71. m_nCount = 0;
  72. // clear members
  73. m_hAppWnd = NULL;
  74. m_hInst = NULL;
  75. m_lpDoc = NULL;
  76. // clear flags
  77. m_fInitialized = FALSE;
  78. // used for inplace
  79. SetRectEmpty(&nullRect);
  80. }
  81. //**********************************************************************
  82. //
  83. // CSimpSvrApp::~CSimpSvrApp()
  84. //
  85. // Purpose:
  86. //
  87. // Destructor for CSimpSvrApp Class.
  88. //
  89. // Parameters:
  90. //
  91. // None
  92. //
  93. // Return Value:
  94. //
  95. // None
  96. //
  97. // Function Calls:
  98. // Function Location
  99. //
  100. // TestDebugOut Windows API
  101. // DestroyWindow Windows API
  102. // CSimpSvrApp::IsInitialized APP.H
  103. // OleUninitialize OLE API
  104. //
  105. //********************************************************************
  106. CSimpSvrApp::~CSimpSvrApp()
  107. {
  108. TestDebugOut(TEXT("In CSimpSvrApp's Destructor\r\n"));
  109. /* The Simple Server is structured so that SimpSvrApp is ALWAYS the
  110. * last one to be released, after all the SimpSvrDoc and SimpSvrObj are
  111. * released. So, we don't need to do any clean up to the SimpSvrDoc
  112. * and SimpSvrObj objects.
  113. */
  114. // Revoke our message filter as the last step.
  115. CoRegisterMessageFilter(NULL, NULL);
  116. // need to uninit the library...
  117. if (IsInitialized())
  118. OleUninitialize();
  119. DestroyWindow(m_hAppWnd);
  120. }
  121. //**********************************************************************
  122. //
  123. // CSimpSvrApp::QueryInterface
  124. //
  125. // Purpose:
  126. //
  127. // Used for interface negotiation at Application Level
  128. //
  129. // Parameters:
  130. //
  131. // REFIID riid - A reference to the interface that is
  132. // being queried.
  133. //
  134. // LPVOID FAR* ppvObj - An out parameter to return a pointer to
  135. // the interface.
  136. //
  137. // Return Value:
  138. //
  139. // S_OK - The interface is supported.
  140. // E_NOINTERFACE - The interface is not supported
  141. //
  142. // Function Calls:
  143. // Function Location
  144. //
  145. // TestDebugOut Windows API
  146. // ResultFromScode OLE API
  147. // IUnknown::AddRef APP.CPP
  148. //
  149. //
  150. //
  151. //********************************************************************
  152. STDMETHODIMP CSimpSvrApp::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  153. {
  154. TestDebugOut(TEXT("In CSimpSvrApp::QueryInterface\r\n"));
  155. SCODE sc = S_OK;
  156. if (IsEqualIID(riid, IID_IUnknown))
  157. *ppvObj = this;
  158. else
  159. {
  160. *ppvObj = NULL;
  161. sc = E_NOINTERFACE;
  162. }
  163. if (*ppvObj)
  164. ((LPUNKNOWN)*ppvObj)->AddRef();
  165. // asking for something we don't understand at this level.
  166. return ResultFromScode(sc);
  167. }
  168. //**********************************************************************
  169. //
  170. // CSimpSvrApp::AddRef
  171. //
  172. // Purpose:
  173. //
  174. // Adds to the reference count at the Application level.
  175. //
  176. // Parameters:
  177. //
  178. // None
  179. //
  180. // Return Value:
  181. //
  182. // ULONG - The new reference count of the application.
  183. //
  184. // Function Calls:
  185. // Function Location
  186. //
  187. // TestDebugOut Windows API
  188. //
  189. // Comments:
  190. //
  191. // Due to the reference counting model that is used in this
  192. // implementation, this reference count is the sum of the
  193. // reference counts on all interfaces of all objects open
  194. // in the application.
  195. //
  196. //********************************************************************
  197. STDMETHODIMP_(ULONG) CSimpSvrApp::AddRef()
  198. {
  199. TestDebugOut(TEXT("In CSimpSvrApp::AddRef\r\n"));
  200. return ++m_nCount;
  201. }
  202. //**********************************************************************
  203. //
  204. // CSimpSvrApp::Release
  205. //
  206. // Purpose:
  207. //
  208. // Decrements the reference count at this level
  209. //
  210. // Parameters:
  211. //
  212. // None
  213. //
  214. // Return Value:
  215. //
  216. // ULONG - The new reference count of the application.
  217. //
  218. // Function Calls:
  219. // Function Location
  220. //
  221. // TestDebugOut Windows API
  222. //
  223. // Comments:
  224. //
  225. // Due to the reference counting model that is used in this
  226. // implementation, this reference count is the sum of the
  227. // reference counts on all interfaces of all objects open
  228. // in the application.
  229. //
  230. //********************************************************************
  231. STDMETHODIMP_(ULONG) CSimpSvrApp::Release()
  232. {
  233. TestDebugOut(TEXT("In CSimpSvrApp::Release\r\n"));
  234. if (--m_nCount==0)
  235. {
  236. delete this;
  237. return(0);
  238. }
  239. return m_nCount;
  240. }
  241. //**********************************************************************
  242. //
  243. // CSimpSvrApp::fInitApplication
  244. //
  245. // Purpose:
  246. //
  247. // Initializes the application
  248. //
  249. // Parameters:
  250. //
  251. // HANDLE hInstance - Instance handle of the application.
  252. //
  253. // Return Value:
  254. //
  255. // TRUE - Application was successfully initialized.
  256. // FALSE - Application could not be initialized
  257. //
  258. // Function Calls:
  259. // Function Location
  260. //
  261. // LoadIcon Windows API
  262. // LoadCursor Windows API
  263. // GetStockObject Windows API
  264. // RegisterClass Windows API
  265. // RegisterHatchWindowClass OUTLUI.DLL
  266. //
  267. //
  268. //********************************************************************
  269. BOOL CSimpSvrApp::fInitApplication(HANDLE hInstance)
  270. {
  271. WNDCLASS wc;
  272. // Fill in window class structure with parameters that describe the
  273. // main window.
  274. wc.style = NULL; // Class style(s).
  275. wc.lpfnWndProc = MainWndProc; // Function to retrieve messages for
  276. // windows of this class.
  277. wc.cbClsExtra = 0; // No per-class extra data.
  278. wc.cbWndExtra = 0; // No per-window extra data.
  279. wc.hInstance = (HINSTANCE) hInstance; // Application that owns the class.
  280. wc.hIcon = LoadIcon((HINSTANCE) hInstance, TEXT("SimpSvr"));
  281. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  282. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  283. wc.lpszMenuName = TEXT("SimpSvrMENU"); // Name of menu resource in .RC file.
  284. wc.lpszClassName = TEXT("SimpSvrWClass"); // Name used in call to CreateWindow.
  285. if (!RegisterClass(&wc))
  286. return FALSE;
  287. wc.style = CS_VREDRAW | CS_HREDRAW; // Class style(s).
  288. wc.lpfnWndProc = DocWndProc; // Function to retrieve messages for
  289. // windows of this class.
  290. wc.cbClsExtra = 0; // No per-class extra data.
  291. wc.cbWndExtra = 0; // No per-window extra data.
  292. wc.hInstance = (HINSTANCE) hInstance; // Application that owns the class.
  293. wc.hIcon = NULL;
  294. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  295. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  296. wc.lpszMenuName = NULL;
  297. wc.lpszClassName = TEXT("DocWClass"); // Name used in call to CreateWindow.
  298. // Register the window class and return success/failure code.
  299. if (!RegisterClass(&wc))
  300. return FALSE;
  301. return (RegisterHatchWindowClass((HINSTANCE) hInstance));
  302. }
  303. //**********************************************************************
  304. //
  305. // CSimpSvrApp::fInitInstance
  306. //
  307. // Purpose:
  308. //
  309. // Instance initialization.
  310. //
  311. // Parameters:
  312. //
  313. // HANDLE hInstance - App. Instance Handle.
  314. //
  315. // int nCmdShow - Show parameter from WinMain
  316. //
  317. // Return Value:
  318. //
  319. // TRUE - Initialization Successful
  320. // FALSE - Initialization Failed.
  321. //
  322. //
  323. // Function Calls:
  324. // Function Location
  325. //
  326. // CreateWindow Windows API
  327. // InvalidateRect Windows API
  328. // ShowWindow Windows API
  329. // UpdateWindow Windows API
  330. // CoRegisterClassObject OLE API
  331. // OleBuildVersion OLE API
  332. // OleInitialize OLE API
  333. // CSimpSvrDoc::CreateObject DOC.CPP
  334. //
  335. // Comments:
  336. //
  337. // Note that successful Initalization of the OLE libraries
  338. // is remembered so the UnInit is only called if needed.
  339. //
  340. //********************************************************************
  341. BOOL CSimpSvrApp::fInitInstance (HANDLE hInstance, int nCmdShow,
  342. CClassFactory FAR * lpClassFactory)
  343. {
  344. m_hInst = (HINSTANCE) hInstance;
  345. #ifndef WIN32
  346. /* Since OLE is part of the operating system in Win32, we don't need to
  347. * check the version number in Win32.
  348. */
  349. DWORD dwVer = OleBuildVersion();
  350. // check to see if we are compatible with this version of the libraries
  351. if (HIWORD(dwVer) != rmm || LOWORD(dwVer) < rup)
  352. {
  353. #ifdef _DEBUG
  354. TestDebugOut("WARNING: Incompatible OLE library version\r\n");
  355. #else
  356. return FALSE;
  357. #endif
  358. }
  359. #endif // WIN32
  360. // initialize the libraries
  361. if (OleInitialize(NULL) == NOERROR)
  362. m_fInitialized = TRUE;
  363. // Load our accelerators
  364. if ((m_hAccel = LoadAccelerators(m_hInst, TEXT("SimpsvrAccel"))) == NULL)
  365. {
  366. // Load failed so abort
  367. TestDebugOut(TEXT("ERROR: Accelerator Table Load FAILED\r\n"));
  368. return FALSE;
  369. }
  370. // Create the "application" windows
  371. m_hAppWnd = CreateWindow (TEXT("SimpSvrWClass"),
  372. TEXT("Simple OLE 2.0 Server"),
  373. WS_OVERLAPPEDWINDOW,
  374. CW_USEDEFAULT,
  375. CW_USEDEFAULT,
  376. CW_USEDEFAULT,
  377. CW_USEDEFAULT,
  378. NULL,
  379. NULL,
  380. (HINSTANCE) hInstance,
  381. NULL);
  382. if (!m_hAppWnd)
  383. return FALSE;
  384. // Because there default call control behavior tosses messages
  385. // which cause intermittent failures of the test, we install a
  386. // message filter to get around the problem.
  387. IMessageFilter *pmf = OleStdMsgFilter_Create(m_hAppWnd,
  388. TEXT("Simple OLE 2.0 Server"), SimpsvrMsgCallBack, NULL);
  389. if (pmf == NULL)
  390. {
  391. // this call failed so we are hosed. So fail the whole thing
  392. TestDebugOut(
  393. TEXT("CSimpSvrApp::fInitInstance OleStdMsgFilter_Create fails\n"));
  394. return FALSE;
  395. }
  396. HRESULT hr = CoRegisterMessageFilter(pmf, NULL);
  397. if (FAILED(hr))
  398. {
  399. // this call failed so we are hosed. So fail the whole thing
  400. TestDebugOut(
  401. TEXT("CSimpSvrApp::fInitInstance CoRegisterMessageFilter fails\n"));
  402. return FALSE;
  403. }
  404. // The message filter keeps a reference to this object so we don't have
  405. // to remember anything about it -- except of course to deregister it.
  406. pmf->Release();
  407. // if not started by OLE, then show the Window, and create a "fake" object, else
  408. // Register a pointer to IClassFactory so that OLE can instruct us to make an
  409. // object at the appropriate time.
  410. if (!m_fStartByOle)
  411. {
  412. ShowAppWnd(nCmdShow);
  413. m_lpDoc->CreateObject(IID_IOleObject, (LPVOID FAR *)&m_OleObject);
  414. InvalidateRect(m_lpDoc->GethDocWnd(), NULL, TRUE);
  415. }
  416. else
  417. {
  418. lpClassFactory = new CClassFactory(this);
  419. if (!lpClassFactory)
  420. {
  421. /* Memory allocation fails
  422. */
  423. return(FALSE);
  424. }
  425. // shouldn't pass an API an object with a zero ref count
  426. lpClassFactory->AddRef();
  427. if (
  428. CoRegisterClassObject(GUID_SIMPLE,
  429. (IUnknown FAR *)lpClassFactory,
  430. CLSCTX_LOCAL_SERVER,
  431. REGCLS_SINGLEUSE,
  432. &m_dwRegisterClass) != S_OK
  433. )
  434. TestDebugOut(TEXT("CSimpSvrApp::fInitInstance \
  435. CoRegisterClassObject fails\n"));
  436. // remove artificial Ref. count
  437. lpClassFactory->Release();
  438. }
  439. return m_fInitialized;
  440. }
  441. //+-------------------------------------------------------------------------
  442. //
  443. // Member: CSimpSvrApp::HandleDrawItem (public)
  444. //
  445. // Synopsis: Handles the Draw Item message for the owner draw menu for color
  446. //
  447. // Arguments: [lpdis] -- pointer to draw item structure
  448. //
  449. // Algorithm: If the request is to draw the item, we create a solid brush
  450. // based on the color for the menu. Make a copy of the rectangle
  451. // input. Finally, we shrink the rectangle in size and then fill
  452. // it with the color.
  453. //
  454. // History: dd-mmm-yy Author Comment
  455. // 02-May-94 ricksa author
  456. //
  457. // Notes:
  458. //
  459. //--------------------------------------------------------------------------
  460. void CSimpSvrApp::HandleDrawItem(LPDRAWITEMSTRUCT lpdis)
  461. {
  462. HBRUSH hbr;
  463. RECT rc;
  464. if (lpdis->itemAction == ODA_DRAWENTIRE)
  465. {
  466. // Paint the color item in the color requested.
  467. hbr = CreateSolidBrush(lpdis->itemData);
  468. CopyRect((LPRECT)&rc, (LPRECT)&lpdis->rcItem);
  469. InflateRect((LPRECT)&rc, -10, -10);
  470. FillRect(lpdis->hDC, &rc, hbr);
  471. DeleteObject(hbr);
  472. }
  473. }
  474. //+-------------------------------------------------------------------------
  475. //
  476. // Member: CSimpSvrApp::HandleChangeColors (public)
  477. //
  478. // Synopsis: Handles change between owner draw and regular menu
  479. //
  480. // Algorithm: Reset the checked state of the menu item. If it is an owner
  481. // draw menu requested, then we reset all the menu items to that.
  482. // Otherwise, we set it to the reqular menu items.
  483. //
  484. // History: dd-mmm-yy Author Comment
  485. // 02-May-94 ricksa author
  486. //
  487. // Notes:
  488. //
  489. //--------------------------------------------------------------------------
  490. void CSimpSvrApp::HandleChangeColors(void)
  491. {
  492. // Get a handle to the Colors menu
  493. HMENU hMenu = m_lpDoc->GetColorMenu();
  494. // Get the current state of the item
  495. BOOL fOwnerDraw = GetMenuState(hMenu, IDM_COLOROWNERDR, MF_BYCOMMAND)
  496. & MF_CHECKED;
  497. // Toggle the state of the item.
  498. CheckMenuItem(hMenu, IDM_COLOROWNERDR,
  499. MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED));
  500. if (!fOwnerDraw)
  501. {
  502. // Change the items to owner-draw items. Pass the RGB value for the
  503. // color as the application-supplied data. This makes it easier for
  504. // us to draw the items.
  505. ModifyMenu(hMenu, IDM_RED, MF_OWNERDRAW | MF_BYCOMMAND, IDM_RED,
  506. (LPSTR) RGB (255,0,0));
  507. ModifyMenu(hMenu, IDM_GREEN, MF_OWNERDRAW | MF_BYCOMMAND, IDM_GREEN,
  508. (LPSTR)RGB (0,255,0));
  509. ModifyMenu(hMenu, IDM_BLUE, MF_OWNERDRAW | MF_BYCOMMAND, IDM_BLUE,
  510. (LPSTR)RGB (0,0,255));
  511. }
  512. else
  513. {
  514. // Change the items to normal text items. */
  515. ModifyMenu(hMenu, IDM_RED, MF_BYCOMMAND, IDM_RED, "Red");
  516. ModifyMenu(hMenu, IDM_GREEN, MF_BYCOMMAND, IDM_GREEN, "Green");
  517. ModifyMenu(hMenu, IDM_BLUE, MF_BYCOMMAND, IDM_BLUE, "Blue");
  518. }
  519. }
  520. //**********************************************************************
  521. //
  522. // CSimpSvrApp::lCommandHandler
  523. //
  524. // Purpose:
  525. //
  526. // Handles the processing of WM_COMMAND.
  527. //
  528. // Parameters:
  529. //
  530. // HWND hWnd - Handle to the application Window
  531. //
  532. // UINT message - message (always WM_COMMAND)
  533. //
  534. // WPARAM wParam - Same as passed to the WndProc
  535. //
  536. // LPARAM lParam - Same as passed to the WndProc
  537. //
  538. // Return Value:
  539. //
  540. // NULL
  541. //
  542. // Function Calls:
  543. // Function Location
  544. //
  545. // GetClientRect Windows API
  546. // MessageBox Windows API
  547. // DialogBox Windows API
  548. // MakeProcInstance Windows API
  549. // FreeProcInstance Windows API
  550. // SendMessage Windows API
  551. // DefWindowProc Windows API
  552. // InvalidateRect Windows API
  553. // CSimpSvrDoc::InsertObject DOC.CPP
  554. // CSimpSvrObj::SetColor OBJ.CPP
  555. // CSimpSvrObj::RotateColor OBJ.CPP
  556. //
  557. //
  558. //********************************************************************
  559. LRESULT CSimpSvrApp::lCommandHandler (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  560. {
  561. // In Win32, the upper word of wParam is the notify code. Since we
  562. // don't care about this code, we dump it.
  563. wParam = LOWORD(wParam);
  564. switch (wParam) {
  565. // bring up the About box
  566. case IDM_ABOUT:
  567. {
  568. #ifdef WIN32
  569. DialogBox(m_hInst, // current instance
  570. TEXT("AboutBox"), // resource to use
  571. m_hAppWnd, // parent handle
  572. About); // About() instance address
  573. #else
  574. FARPROC lpProcAbout = MakeProcInstance((FARPROC)About, m_hInst);
  575. DialogBox(m_hInst, // current instance
  576. TEXT("AboutBox"), // resource to use
  577. m_hAppWnd, // parent handle
  578. lpProcAbout); // About() instance address
  579. FreeProcInstance(lpProcAbout);
  580. #endif // WIN32
  581. break;
  582. }
  583. // exit the application
  584. case IDM_EXIT:
  585. SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L);
  586. break;
  587. case IDM_RED:
  588. m_lpDoc->GetObj()->SetColor (128, 0, 0);
  589. InvalidateRect(m_lpDoc->GethDocWnd(), NULL, TRUE);
  590. break;
  591. case IDM_GREEN:
  592. m_lpDoc->GetObj()->SetColor (0,128, 0);
  593. InvalidateRect(m_lpDoc->GethDocWnd(), NULL, TRUE);
  594. break;
  595. case IDM_BLUE:
  596. m_lpDoc->GetObj()->SetColor (0, 0, 128);
  597. InvalidateRect(m_lpDoc->GethDocWnd(), NULL, TRUE);
  598. break;
  599. case IDM_COLOROWNERDR:
  600. HandleChangeColors();
  601. break;
  602. default:
  603. return (DefWindowProc(hWnd, message, wParam, lParam));
  604. } // end of switch
  605. return NULL;
  606. }
  607. //**********************************************************************
  608. //
  609. // CSimpSvrApp::lSizeHandler
  610. //
  611. // Purpose:
  612. //
  613. // Handles the WM_SIZE message
  614. //
  615. // Parameters:
  616. //
  617. // HWND hWnd - Handle to the application Window
  618. //
  619. // UINT message - message (always WM_SIZE)
  620. //
  621. // WPARAM wParam - Same as passed to the WndProc
  622. //
  623. // LPARAM lParam - Same as passed to the WndProc
  624. //
  625. // Return Value:
  626. //
  627. // LONG - returned from the "document" resizing
  628. //
  629. // Function Calls:
  630. // Function Location
  631. //
  632. // GetClientRect Windows API
  633. // CSimpSvrDoc::lResizeDoc DOC.CPP
  634. //
  635. //
  636. //********************************************************************
  637. long CSimpSvrApp::lSizeHandler (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  638. {
  639. RECT rect;
  640. GetClientRect(m_hAppWnd, &rect);
  641. return m_lpDoc->lResizeDoc(&rect);
  642. }
  643. //**********************************************************************
  644. //
  645. // CSimpSvrApp::lCreateDoc
  646. //
  647. // Purpose:
  648. //
  649. // Handles the creation of a document.
  650. //
  651. // Parameters:
  652. //
  653. // HWND hWnd - Handle to the application Window
  654. //
  655. // UINT message - message (always WM_CREATE)
  656. //
  657. // WPARAM wParam - Same as passed to the WndProc
  658. //
  659. // LPARAM lParam - Same as passed to the WndProc
  660. //
  661. // Return Value:
  662. //
  663. // NULL
  664. //
  665. // Function Calls:
  666. // Function Location
  667. //
  668. // GetClientRect Windows API
  669. // CSimpSvrDoc::Create DOC.CPP
  670. //
  671. //
  672. //********************************************************************
  673. long CSimpSvrApp::lCreateDoc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  674. {
  675. RECT rect;
  676. GetClientRect(hWnd, &rect);
  677. m_lpDoc = CSimpSvrDoc::Create(this, &rect, hWnd);
  678. return NULL;
  679. }
  680. //**********************************************************************
  681. //
  682. // CSimpSvrApp::PaintApp
  683. //
  684. // Purpose:
  685. //
  686. // Handles the painting of the doc window.
  687. //
  688. //
  689. // Parameters:
  690. //
  691. // HDC hDC - hDC to the Doc Window.
  692. //
  693. // Return Value:
  694. //
  695. // None
  696. //
  697. // Function Calls:
  698. // Function Location
  699. //
  700. // CSimpSvrDoc::PaintDoc DOC.CPP
  701. //
  702. //
  703. //
  704. //********************************************************************
  705. void CSimpSvrApp::PaintApp (HDC hDC)
  706. {
  707. // if we supported multiple documents, we would enumerate
  708. // through each of the open documents and call paint.
  709. if (m_lpDoc)
  710. m_lpDoc->PaintDoc(hDC);
  711. }
  712. //**********************************************************************
  713. //
  714. // CSimpSvrApp::ParseCmdLine
  715. //
  716. // Purpose:
  717. //
  718. // Determines if the app was started by OLE
  719. //
  720. //
  721. // Parameters:
  722. //
  723. // LPSTR lpCmdLine - Pointer to the command line
  724. //
  725. // Return Value:
  726. //
  727. // None
  728. //
  729. // Function Calls:
  730. // Function Location
  731. //
  732. // lstrlen Windows API
  733. // lstrcmp Windows API
  734. //
  735. //
  736. // Comments:
  737. //
  738. // Parses the command line looking for the -Embedding or /Embedding
  739. // flag.
  740. //
  741. //********************************************************************
  742. void CSimpSvrApp::ParseCmdLine(LPSTR lpCmdLine)
  743. {
  744. CHAR szTemp[255];
  745. m_fStartByOle = TRUE;
  746. ::ParseCmdLine (lpCmdLine, &m_fStartByOle, szTemp);
  747. }
  748. //**********************************************************************
  749. //
  750. // CSimpSvrApp::SetStatusText
  751. //
  752. // Purpose:
  753. //
  754. // Blanks out the text in the status bar
  755. //
  756. //
  757. // Parameters:
  758. //
  759. // None
  760. //
  761. // Return Value:
  762. //
  763. // None
  764. //
  765. // Function Calls:
  766. // Function Location
  767. //
  768. // CSimpSvrDoc::SetStatusText DOC.CPP
  769. //
  770. //
  771. //********************************************************************
  772. void CSimpSvrApp::SetStatusText()
  773. {
  774. m_lpDoc->SetStatusText();
  775. }
  776. //**********************************************************************
  777. //
  778. // CSimpSvrApp::IsInPlaceActive
  779. //
  780. // Purpose:
  781. //
  782. // Safely determines from the app level if currently inplace active.
  783. //
  784. //
  785. // Parameters:
  786. //
  787. // None
  788. //
  789. // Return Value:
  790. //
  791. // TRUE - Inplace active
  792. // FALSE - Not Inplace active
  793. //
  794. // Function Calls:
  795. // Function Location
  796. //
  797. // CSimpSvrDoc::GetObject DOC.H
  798. // CSimpSvrObj:IsInPlaceActive OBJ.H
  799. //
  800. //
  801. //********************************************************************
  802. BOOL CSimpSvrApp::IsInPlaceActive()
  803. {
  804. BOOL retval = FALSE;
  805. if (m_lpDoc)
  806. if (m_lpDoc->GetObj())
  807. retval = m_lpDoc->GetObj()->IsInPlaceActive();
  808. return retval;
  809. }
  810. //**********************************************************************
  811. //
  812. // CSimpSvrApp::ShowAppWnd
  813. //
  814. // Purpose:
  815. //
  816. // Shows the Application Window
  817. //
  818. // Parameters:
  819. //
  820. // int nCmdShow - Window State
  821. //
  822. // Return Value:
  823. //
  824. // None
  825. //
  826. // Function Calls:
  827. // Function Location
  828. //
  829. // ShowWindow Windows API
  830. // UpdateWindow Windows API
  831. // CoLockObjectExternal OLE API
  832. //
  833. //********************************************************************
  834. void CSimpSvrApp::ShowAppWnd(int nCmdShow)
  835. {
  836. if (CoLockObjectExternal(this, TRUE, FALSE) != S_OK)
  837. TestDebugOut(TEXT("CSimpSvrApp::ShowAppWnd \
  838. CoLockObjectExternal fails\n"));
  839. ShowWindow (m_hAppWnd, nCmdShow);
  840. UpdateWindow (m_hAppWnd);
  841. }
  842. //**********************************************************************
  843. //
  844. // CSimpSvrApp::ShowAppWnd
  845. //
  846. // Purpose:
  847. //
  848. // Hides the Application Window
  849. //
  850. // Parameters:
  851. //
  852. // None
  853. //
  854. // Return Value:
  855. //
  856. // None
  857. //
  858. // Function Calls:
  859. // Function Location
  860. //
  861. // ShowWindow Windows API
  862. // CoLockObjectExternal OLE API
  863. //
  864. //********************************************************************
  865. void CSimpSvrApp::HideAppWnd()
  866. {
  867. if (CoLockObjectExternal(this, FALSE, TRUE) != S_OK)
  868. TestDebugOut(TEXT("CSimpSvrApp::HideAppWnd \
  869. CoLockObjectExternal fails\n"));
  870. ShowWindow (m_hAppWnd, SW_HIDE);
  871. }