home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / CTRLTS.PAK / PAREDIT2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.4 KB  |  135 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-1995 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 related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "ctrltest.h"
  15.  
  16. #include "paredit.h"
  17. #include <ctl3d.h>
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // The C++ class CParsedEdit can be made visible to the dialog manager
  21. //   by registering a window class for it
  22. // The C++ class 'CParsedEditExported' is used to implement the
  23. //   creation and destruction of a C++ object as if it were just
  24. //   a normal Windows control.
  25. // In order to hook in the class creation we must provide a special
  26. //   WndProc to create the C++ object and override the PostNcDestroy
  27. //   message to destroy it
  28.  
  29. class CParsedEditExported : public CParsedEdit      // WNDCLASS exported class
  30. {
  31. public:
  32.     CParsedEditExported() { };
  33.     BOOL RegisterControlClass();
  34.  
  35. // Implementation: (all is implementation since the public interface of
  36. //    this class is identical to CParsedEdit)
  37. protected:
  38.     virtual void PostNcDestroy();
  39.     static LRESULT CALLBACK EXPORT WndProcHook(HWND, UINT, WPARAM, LPARAM);
  40.     static WNDPROC lpfnSuperEdit;
  41.  
  42.     friend class CParsedEdit;       // for RegisterControlClass
  43.  
  44.     //{{AFX_MSG(CParsedEditExported)
  45.     afx_msg int OnNcCreate(LPCREATESTRUCT lpCreateStruct);
  46.     //}}AFX_MSG
  47.     DECLARE_MESSAGE_MAP();
  48. };
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Special create hooks
  52.  
  53. LRESULT CALLBACK EXPORT
  54. CParsedEditExported::WndProcHook(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  55. {
  56.     // create new item and attach it
  57.     CParsedEditExported* pEdit = new CParsedEditExported();
  58.     pEdit->Attach(hWnd);
  59.  
  60.     // set up wndproc to AFX one, and call it
  61.     pEdit->m_pfnSuper = CParsedEditExported::lpfnSuperEdit;
  62.     ::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)AfxWndProc);
  63.  
  64. #ifndef _MAC
  65.     // Since this window is really an edit control but does not
  66.     //  have "edit" as its class name, to make it work correctly
  67.     //  with CTL3D, we have to tell CTL3D that is "really is" an
  68.     //  edit control.  This uses a relatively new API in CTL3D
  69.     //  called Ctl3dSubclassCtlEx.
  70.     pEdit->SubclassCtl3d(CTL3D_EDIT_CTL);
  71. #endif
  72.  
  73.     // then call it for this first message
  74. #ifdef STRICT
  75.     return ::CallWindowProc(AfxWndProc, hWnd, msg, wParam, lParam);
  76. #else
  77.     return ::CallWindowProc((FARPROC)AfxWndProc, hWnd, msg, wParam, lParam);
  78. #endif
  79. }
  80.  
  81. BEGIN_MESSAGE_MAP(CParsedEditExported, CParsedEdit)
  82.     //{{AFX_MSG_MAP(CParsedEditExported)
  83.     ON_WM_NCCREATE()
  84.     //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86.  
  87. int CParsedEditExported::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
  88. {
  89.     // special create hook
  90.     // example of stripping the sub-style bits from the style specified
  91.     //   in the dialog template to use for some other reason
  92.     m_wParseStyle = LOWORD(lpCreateStruct->style);
  93.     DWORD dwEditStyle = MAKELONG(ES_LEFT, HIWORD(lpCreateStruct->style));
  94.  
  95.     ::SetWindowLong(m_hWnd, GWL_STYLE, dwEditStyle);
  96.     lpCreateStruct->style = dwEditStyle;
  97.     return CParsedEdit::OnNcCreate(lpCreateStruct);
  98. }
  99.  
  100. void CParsedEditExported::PostNcDestroy()
  101. {
  102.     // needed to clean up the C++ CWnd object
  103.     delete this;
  104. }
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // Routine to register the class
  108.  
  109. WNDPROC CParsedEditExported::lpfnSuperEdit = NULL;
  110.  
  111. BOOL CParsedEdit::RegisterControlClass()
  112. {
  113.     WNDCLASS wcls;
  114.  
  115.     // check to see if class already registered
  116.     static const TCHAR szClass[] = _T("paredit");
  117.     if (::GetClassInfo(AfxGetInstanceHandle(), szClass, &wcls))
  118.     {
  119.         // name already registered - ok if it was us
  120.         return (wcls.lpfnWndProc == (WNDPROC)CParsedEditExported::WndProcHook);
  121.     }
  122.  
  123.     // Use standard "edit" control as a template.
  124.     VERIFY(::GetClassInfo(NULL, _T("edit"), &wcls));
  125.     CParsedEditExported::lpfnSuperEdit = wcls.lpfnWndProc;
  126.  
  127.     // set new values
  128.     wcls.lpfnWndProc = CParsedEditExported::WndProcHook;
  129.     wcls.hInstance = AfxGetInstanceHandle();
  130.     wcls.lpszClassName = szClass;
  131.     return (RegisterClass(&wcls) != 0);
  132. }
  133.  
  134. /////////////////////////////////////////////////////////////////////////////
  135.