|
|
1.1 ! root 1: // This is a part of the Microsoft Foundation Classes C++ library. ! 2: // Copyright (C) 1992 Microsoft Corporation ! 3: // All rights reserved. ! 4: // ! 5: // This source code is only intended as a supplement to the ! 6: // Microsoft Foundation Classes Reference and Microsoft ! 7: // QuickHelp documentation provided with the library. ! 8: // See these sources for detailed information regarding the ! 9: // Microsoft Foundation Classes product. ! 10: ! 11: #include "minsvrMI.h" ! 12: ! 13: // Main window and user interface parts ! 14: ! 15: ///////////////////////////////////////////////////////////////////////////// ! 16: ! 17: // message map since we are a window ! 18: BEGIN_MESSAGE_MAP(CMiApp, CFrameWnd) ! 19: // windows messages ! 20: ON_MESSAGE(WM_CLOSE, OnCloseWindow) ! 21: // Both CWnd and COleServer have an 'OnClose' member function but ! 22: // they differ only by the return type. ! 23: // Unfortunately C++ multiple inheritance rules prevent us from ! 24: // from overriding either of them. We use the more general ! 25: // form of message map entries to replace CWnd::OnClose with ! 26: // CMiApp::OnCloseWindow to get around this restriction of C++. ! 27: ! 28: // menu commands ! 29: ON_COMMAND(IDM_UPDATE, OnUpdateClient) ! 30: ON_COMMAND(IDM_EXIT, OnFileExit) ! 31: ON_COMMAND(IDM_CHANGESTRING, OnChangeString) ! 32: ON_COMMAND(IDM_ABOUT, OnAbout) ! 33: END_MESSAGE_MAP() ! 34: ! 35: ///////////////////////////////////////////////////////////////////////////// ! 36: // File menu commands ! 37: ! 38: void CMiApp::OnFileExit() ! 39: { ! 40: // to shut-down, just revoke the server, OLE will terminate the app ! 41: COleServer::BeginRevoke(); ! 42: } ! 43: ! 44: LONG CMiApp::OnCloseWindow(UINT, LONG) ! 45: { ! 46: OnFileExit(); ! 47: return 0; ! 48: } ! 49: ! 50: void CMiApp::PostNcDestroy() ! 51: { ! 52: // CFrameWnd::PostNcDestroy will 'delete this'. ! 53: // since the CMiApp is-a CFrameWnd we don't want PostNcDestroy ! 54: // to do anything - so we override it here to remove the default ! 55: // behaviour. ! 56: } ! 57: ! 58: ///////////////////////////////////////////////////////////////////////////// ! 59: ! 60: void CMiApp::OnUpdateClient() ! 61: { ! 62: TRY ! 63: { ! 64: NotifySaved(); ! 65: } ! 66: CATCH (CException, e) ! 67: { ! 68: MessageBox("Couldn't update client"); ! 69: } ! 70: END_CATCH ! 71: } ! 72: ! 73: // Help menu commands ! 74: void CMiApp::OnAbout() ! 75: { ! 76: CModalDialog dlg("AboutBox"); ! 77: dlg.DoModal(); ! 78: } ! 79: ! 80: ///////////////////////////////////////////////////////////////////////////// ! 81: // OLE Item UI ! 82: ! 83: OLESTATUS CMiApp::OnShow(BOOL /* bTakeFocus */) ! 84: { ! 85: // make sure server is the topmost window ! 86: BringWindowToTop(); ! 87: return OLE_OK; ! 88: } ! 89: ! 90: /////////////////////////////////////////// ! 91: // Simple dialog for changing the string ! 92: ! 93: class CChangeDlg : public CModalDialog ! 94: { ! 95: protected: ! 96: CString& m_rString; ! 97: ! 98: public: ! 99: CChangeDlg(CString& rString) ! 100: : CModalDialog("ChangeDlg"), m_rString(rString) ! 101: { } ! 102: ! 103: BOOL OnInitDialog() ! 104: { ! 105: GetDlgItem(IDC_EDIT1)->SetWindowText(m_rString); ! 106: return TRUE; ! 107: } ! 108: void OnOK() ! 109: { ! 110: GetDlgItem(IDC_EDIT1)->GetWindowText(m_rString); ! 111: EndDialog(IDOK); ! 112: } ! 113: }; ! 114: ! 115: ! 116: void CMiApp::OnChangeString() ! 117: { ! 118: CChangeDlg dlg(m_data); ! 119: if (dlg.DoModal() == IDOK && COleServerDoc::IsOpen()) ! 120: OnUpdateClient(); // example of immediately updating client ! 121: } ! 122: ! 123: ///////////////////////////////////////////////////////////////////////////// ! 124: // Drawing items into bitmap or metafile ! 125: ! 126: BOOL CMiApp::OnDraw(CMetaFileDC* pDC) ! 127: { ! 128: ASSERT_VALID(pDC); ! 129: CSize textSize; ! 130: ! 131: // first calculate the text size in MM_TEXT units ! 132: { ! 133: CWindowDC screenDC(NULL); ! 134: textSize = screenDC.GetTextExtent(m_data, m_data.GetLength()); ! 135: } ! 136: ! 137: // if you want the item to always be drawn in a specific mapping ! 138: // mode set it here. ! 139: ! 140: // Otherwise the OLE DLLs will scale the metafile to fit the ! 141: // client specified size. Setting the viewport size/extent ! 142: // determines the relative scale of everything. ! 143: ! 144: int cx = textSize.cx + 100; ! 145: int cy = (cx * 4) / 3; // nice aspect ratio ! 146: TRACE("Item drawing size is %d x %d\n", cx, cy); ! 147: pDC->SetWindowExt(cx, cy); ! 148: ! 149: // Draw a shaded circle ! 150: pDC->SelectStockObject(LTGRAY_BRUSH); ! 151: pDC->Ellipse(0, 0, cx, cy); ! 152: ! 153: // draw the text in the middle (as best we can) ! 154: pDC->SetBkMode(TRANSPARENT); ! 155: pDC->TextOut((cx - textSize.cx) / 2, (cy - textSize.cy) / 2, m_data); ! 156: ! 157: return TRUE; ! 158: } ! 159: ! 160: /////////////////////////////////////////////////////////////////////////////
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.