home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK11 / MFC / SAMPLES / MINSVR / MINITEM.CP$ / minitem
Encoding:
Text File  |  1992-03-16  |  2.8 KB  |  122 lines

  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 "minsvr.h"
  12.  
  13. /////////////////////////////////////////////////////////////////////////////
  14.  
  15. CMinItem::CMinItem()
  16. {
  17.     m_data = "example string";
  18. }
  19.  
  20. void CMinItem::Serialize(CArchive& ar)
  21. {
  22.     // Customize this to store real data
  23.     if (ar.IsStoring())
  24.     {
  25.         ar << m_data;
  26.     }
  27.     else
  28.     {
  29.         ar >> m_data;
  30.     }
  31. }
  32.  
  33.  
  34. OLESTATUS CMinItem::OnShow(BOOL /* bTakeFocus */)
  35. {
  36.     // make sure server is the topmost window
  37.     AfxGetApp()->m_pMainWnd->BringWindowToTop();
  38.     return OLE_OK;
  39. }
  40.  
  41.  
  42. BOOL CMinItem::OnGetTextData(CString& rStringReturn)
  43. {
  44.     rStringReturn = m_data;
  45.     return TRUE;
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // Simple dialog for changing the string
  50.  
  51. class CChangeDlg : public CModalDialog
  52. {
  53. protected:
  54.     CString&    m_rString;
  55.  
  56. public:
  57.     CChangeDlg(CString& rString)
  58.         : CModalDialog("ChangeDlg"), m_rString(rString)
  59.             { }
  60.  
  61.     BOOL OnInitDialog();
  62.     void OnOK();
  63. };
  64.  
  65. BOOL CChangeDlg::OnInitDialog()
  66. {
  67.     GetDlgItem(IDC_EDIT1)->SetWindowText(m_rString);
  68.     return TRUE;
  69. };
  70.  
  71. void CChangeDlg::OnOK()
  72. {
  73.     GetDlgItem(IDC_EDIT1)->GetWindowText(m_rString);
  74.     EndDialog(IDOK);
  75. }
  76.  
  77.  
  78. BOOL CMinItem::PromptChangeString()
  79. {
  80.     CChangeDlg dlg(m_data);
  81.     return (dlg.DoModal() == IDOK);
  82. }
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Drawing items into bitmap or metafile
  86.  
  87. BOOL CMinItem::OnDraw(CMetaFileDC* pDC)
  88. {
  89.     ASSERT_VALID(pDC);
  90.     CSize textSize;
  91.  
  92.     // first calculate the text size in MM_TEXT units
  93.     {
  94.         CWindowDC screenDC(NULL);
  95.         textSize = screenDC.GetTextExtent(m_data, m_data.GetLength());
  96.     }
  97.  
  98.     // if you want the item to always be drawn in a specific mapping
  99.     //  mode set it here.
  100.  
  101.     // Otherwise the OLE DLLs will scale the metafile to fit the
  102.     //  client specified size.  Setting the viewport size/extent
  103.     //  determines the relative scale of everything.
  104.  
  105.     int cx = textSize.cx + 100;
  106.     int cy = (cx * 4) / 3;      // nice aspect ratio
  107.     TRACE("Item drawing size is %d x %d\n", cx, cy);
  108.     pDC->SetWindowExt(cx, cy);
  109.  
  110.     // Draw a shaded circle
  111.     pDC->SelectStockObject(LTGRAY_BRUSH);
  112.     pDC->Ellipse(0, 0, cx, cy);
  113.  
  114.     // draw the text in the middle (as best we can)
  115.     pDC->SetBkMode(TRANSPARENT);
  116.     pDC->TextOut((cx - textSize.cx) / 2, (cy - textSize.cy) / 2, m_data);
  117.  
  118.     return TRUE;
  119. }
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122.