home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK11 / MFC / SAMPLES / CTRLTEST / PAREDIT2.CP$ / paredit2
Encoding:
Text File  |  1992-03-17  |  4.1 KB  |  128 lines

  1. // paredit2.cpp : code needed to export CParsedEdit as a WndClass
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // QuickHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "ctrltest.h"
  14.  
  15. #include "paredit.h"
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // The C++ class CParsedEdit can be made visible to the dialog manager
  19. //   by registering a window class for it
  20. // The C++ class 'CParsedEditExported' is used to implement the
  21. //   creation and destruction of a C++ object as if it were just
  22. //   a normal Windows control.
  23. // In order to hook in the class creation we must provide a special
  24. //   WndProc to create the C++ object and override the PostNcDestroy
  25. //   message to destroy it
  26.  
  27. class CParsedEditExported : public CParsedEdit      // WNDCLASS exported class
  28. {
  29. public:
  30.     CParsedEditExported(HWND hWnd)
  31.         { VERIFY(Attach(hWnd)); }
  32.  
  33. // Implementation: (all is implementation since the public interface of
  34. //    this class is identical to CParsedEdit)
  35. protected:
  36.     virtual WNDPROC* GetSuperWndProcAddr();
  37.     static WNDPROC lpfnSuperWndProc;
  38.     afx_msg int OnNcCreate(LPCREATESTRUCT lpCreateStruct);
  39.     virtual void PostNcDestroy();
  40.     static LONG FAR PASCAL __export WndProcHook(HWND, UINT, UINT, LONG);
  41.     DECLARE_MESSAGE_MAP();
  42.  
  43.     friend class CParsedEdit;       // for RegisterControlClass
  44. };
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Special create hooks
  48.  
  49. LONG FAR PASCAL __export
  50. CParsedEditExported::WndProcHook(HWND hWnd, UINT msg, UINT wParam, LONG lParam)
  51. {
  52.     // create new item and attach it
  53.     CParsedEditExported* pEdit = new CParsedEditExported(hWnd);
  54.  
  55.     // set up wndproc to AFX one, and call it
  56.     ::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)AfxWndProc);
  57. #ifdef STRICT
  58.     return ::CallWindowProc(AfxWndProc, hWnd, msg, wParam, lParam);
  59. #else
  60.     return ::CallWindowProc((FARPROC)AfxWndProc, hWnd, msg, wParam, lParam);
  61. #endif
  62. }
  63.  
  64.  
  65. BEGIN_MESSAGE_MAP(CParsedEditExported, CParsedEdit)
  66.     ON_WM_NCCREATE()
  67. END_MESSAGE_MAP()
  68.  
  69. int CParsedEditExported::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
  70. {
  71.     // special create hook
  72.     // example of stripping the sub-style bits from the style specified
  73.     //   in the dialog template to use for some other reason
  74.     m_wParseStyle = LOWORD(lpCreateStruct->style);
  75.     DWORD dwEditStyle = MAKELONG(ES_LEFT, HIWORD(lpCreateStruct->style));
  76.  
  77.     ::SetWindowLong(m_hWnd, GWL_STYLE, dwEditStyle);
  78.     lpCreateStruct->style = dwEditStyle;
  79.     return CParsedEdit::OnNcCreate(lpCreateStruct);
  80. }
  81.  
  82. void CParsedEditExported::PostNcDestroy()
  83. {
  84.     // needed to clean up
  85.     delete this;
  86. }
  87.  
  88. WNDPROC CParsedEditExported::lpfnSuperWndProc = NULL;
  89. WNDPROC* CParsedEditExported::GetSuperWndProcAddr()
  90. {
  91.     return &lpfnSuperWndProc;
  92. }
  93.  
  94. /////////////////////////////////////////////////////////////////////////////
  95. // Routine to register the class
  96. BOOL CParsedEdit::RegisterControlClass()
  97. {
  98.     WNDCLASS wcls;
  99.  
  100.     // Always set the super class address
  101.     // since the second instance will not need to register the WndClass,
  102.     //  but will still need to set the super-proc address
  103.     if (!::GetClassInfo(NULL, "edit", &wcls))
  104.     {
  105.         return FALSE;
  106.     }
  107.  
  108.     // set appropriate super class address
  109.     CParsedEditExported::lpfnSuperWndProc = wcls.lpfnWndProc; // "EDIT" wnd proc
  110.  
  111.     // check to see if class already registered
  112.     static const char szClass[] = "paredit";
  113.     if (::GetClassInfo(AfxGetInstanceHandle(), szClass, &wcls))
  114.     {
  115.         // name already registered - ok if it was us
  116.         return (wcls.lpfnWndProc == CParsedEditExported::WndProcHook);
  117.     }
  118.  
  119.     // set new values
  120.     wcls.lpfnWndProc = CParsedEditExported::WndProcHook;
  121.     wcls.hInstance = AfxGetInstanceHandle();
  122.     wcls.lpszClassName = szClass;
  123.     return (RegisterClass(&wcls) != 0);
  124. }
  125.  
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128.