Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.2 KiB

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