home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / DLLHUSK / TESTDLL1.CP_ / TESTDLL1.CP
Encoding:
Text File  |  1993-02-08  |  4.7 KB  |  168 lines

  1.  
  2. // This is a part of the Microsoft Foundation Classes C++ library.
  3. // Copyright (C) 1992 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // This source code is only intended as a supplement to the
  7. // Microsoft Foundation Classes Reference and Microsoft
  8. // QuickHelp and/or WinHelp documentation provided with the library.
  9. // See these sources for detailed information regarding the
  10. // Microsoft Foundation Classes product.
  11.  
  12.  
  13. #include "stdafx.h"
  14.  
  15. #include "resource.h"       // main symbols
  16. #include "testres1.h"       // symbols unique to this DLL
  17.  
  18. #include "testdll1.h"
  19.  
  20. #ifdef _DEBUG
  21. #undef THIS_FILE
  22. static char BASED_CODE THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Initialization of MFC Extension DLL
  27.  
  28. #include "afxdllx.h"    // standard MFC Extension DLL routines
  29.  
  30. static AFX_EXTENSION_MODULE NEAR extensionDLL = { NULL, NULL };
  31.  
  32. extern "C" int CALLBACK LibMain(HINSTANCE hInstance, WORD, WORD, LPSTR)
  33. {
  34.     // Extension DLL one-time initialization - do not allocate memory here,
  35.     //   use the TRACE or ASSERT macros or call MessageBox
  36.     AfxInitExtensionModule(extensionDLL, hInstance);
  37.     return 1;   // ok
  38. }
  39.  
  40. // Exported DLL initialization is run in context of running application
  41. extern "C" extern void WINAPI InitTestDLL1()
  42. {
  43.     // create a new CDynLinkLibrary for this app
  44.     new CDynLinkLibrary(extensionDLL);
  45.  
  46.     // Register the doc templates we provide to the app
  47.     CWinApp* pApp = AfxGetApp();
  48.     ASSERT(pApp != NULL);
  49.     pApp->AddDocTemplate(new CMultiDocTemplate(IDR_TEXTTYPE,
  50.             RUNTIME_CLASS(CTextDoc),
  51.             RUNTIME_CLASS(CMDIChildWnd),
  52.             RUNTIME_CLASS(CEditView)));
  53.     pApp->AddDocTemplate(new CMultiDocTemplate(IDR_HELLOTYPE,
  54.             RUNTIME_CLASS(CDummyDoc),
  55.             RUNTIME_CLASS(CMDIChildWnd),
  56.             RUNTIME_CLASS(CHelloView)));
  57.     // add other initialization here
  58. }
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Example of a Simple CEditView (taken from MultiPad)
  62.  
  63. IMPLEMENT_DYNCREATE(CTextDoc, CDocument)
  64.  
  65. BEGIN_MESSAGE_MAP(CTextDoc, CDocument)
  66.     //{{AFX_MSG_MAP(CTextDoc)
  67.     //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69.  
  70. void CTextDoc::Serialize(CArchive& ar)
  71. {
  72.     CEditView* pView = (CEditView*)m_viewList.GetHead();
  73.     ASSERT(pView->IsKindOf(RUNTIME_CLASS(CEditView)));
  74.     pView->SerializeRaw(ar);
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CHelloView : example of a simple output only document and view
  79. //      (taken from Hello/MDI)
  80.  
  81. IMPLEMENT_DYNCREATE(CHelloView, CView)
  82.  
  83. BEGIN_MESSAGE_MAP(CHelloView, CView)
  84.     //{{AFX_MSG_MAP(CHelloView)
  85.     ON_WM_PAINT()
  86.     ON_COMMAND(IDM_BLACK, OnColor)
  87.     ON_COMMAND(IDM_CUSTOM, OnCustomColor)
  88.     ON_COMMAND(IDM_RED, OnColor)
  89.     ON_COMMAND(IDM_GREEN, OnColor)
  90.     ON_COMMAND(IDM_BLUE, OnColor)
  91.     ON_COMMAND(IDM_WHITE, OnColor)
  92.     ON_UPDATE_COMMAND_UI(IDM_BLACK, OnUpdateColor)
  93.     ON_UPDATE_COMMAND_UI(IDM_BLUE, OnUpdateColor)
  94.     ON_UPDATE_COMMAND_UI(IDM_GREEN, OnUpdateColor)
  95.     ON_UPDATE_COMMAND_UI(IDM_RED, OnUpdateColor)
  96.     ON_UPDATE_COMMAND_UI(IDM_WHITE, OnUpdateColor)
  97.     ON_UPDATE_COMMAND_UI(IDM_CUSTOM, OnUpdateColor)
  98.     //}}AFX_MSG_MAP
  99. END_MESSAGE_MAP()
  100.  
  101. CHelloView::CHelloView()
  102. {
  103.     m_nIDColor = IDM_BLACK;
  104.     m_clrText = RGB(0, 0, 0);
  105. }
  106.  
  107. // OnDraw: Draw a string in the center of the client area.
  108. void CHelloView::OnDraw(CDC* pDC)
  109. {
  110.     CRect rect;
  111.  
  112.     pDC->SetTextColor(m_clrText);
  113.     pDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
  114.     GetClientRect(rect);
  115.     pDC->DrawText("Hello, World!", -1, rect,
  116.         DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  117. }
  118.  
  119. /////////////////////////////////////////////////////////////////////////////
  120. // CHelloView command
  121.  
  122. void CHelloView::OnUpdateColor(CCmdUI* pCmdUI)
  123. {
  124.     pCmdUI->SetCheck(pCmdUI->m_nID == m_nIDColor);
  125. }
  126.  
  127. // Color array maps to order of the Color menu
  128. static COLORREF NEAR colorArray[] =
  129. {
  130.     RGB (0, 0, 0),
  131.     RGB (255, 0, 0),
  132.     RGB (0, 255, 0),
  133.     RGB (0, 0, 255),
  134.     RGB (255, 255, 255)
  135. };
  136.  
  137. void CHelloView::OnColor()
  138. {
  139.     m_nIDColor = LOWORD(GetCurrentMessage()->wParam);
  140.     m_clrText = colorArray[m_nIDColor - IDM_BLACK];
  141.  
  142.     // Force the client area text to be repainted in the new color
  143.     Invalidate();
  144. }
  145.  
  146. void CHelloView::OnCustomColor()
  147. {
  148.     CColorDialog dlgColor(m_clrText);
  149.     if (dlgColor.DoModal() == IDOK)
  150.     {
  151.         m_clrText = dlgColor.GetColor();
  152.         m_nIDColor = IDM_CUSTOM;
  153.         Invalidate();
  154.     }
  155. }
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CDummyDoc : a do-nothing document that can be used with non-data views
  159.  
  160. IMPLEMENT_DYNCREATE(CDummyDoc, CDocument)
  161.  
  162. BEGIN_MESSAGE_MAP(CDummyDoc, CDocument)
  163.     //{{AFX_MSG_MAP(CDummyDoc)
  164.     //}}AFX_MSG_MAP
  165. END_MESSAGE_MAP()
  166.  
  167. /////////////////////////////////////////////////////////////////////////////
  168.