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.

136 lines
4.2 KiB

  1. #ifndef _TREEVIEWWINDOW
  2. #define _TREEVIEWWINDOW
  3. #include "stdafx.h"
  4. #include "CWindow.h"
  5. extern WNDPROC gTreeViewWndSysWndProc;
  6. class CTreeViewWnd {
  7. private:
  8. public:
  9. HWND m_hWnd;
  10. //
  11. // Revisit this in the future!, static variable here, would be better than
  12. // using a global, to store the OldWindowProc value.
  13. //
  14. // static WNDPROC OldWindowProc;
  15. CTreeViewWnd( HWND hWnd )
  16. : m_hWnd(hWnd)
  17. {
  18. }
  19. ~CTreeViewWnd(void)
  20. {
  21. }
  22. static BOOL RegisterClass( HINSTANCE hInstance, LPCTSTR pszClassName)
  23. {
  24. WNDCLASSEX wcex;
  25. ZeroMemory(&wcex,sizeof(wcex));
  26. wcex.cbSize = sizeof(wcex);
  27. if (!GetClassInfoEx( hInstance, pszClassName, &wcex )) {
  28. ZeroMemory(&wcex,sizeof(wcex));
  29. wcex.cbSize = sizeof(wcex);
  30. wcex.style = 0;
  31. wcex.lpfnWndProc = TreeViewWndProc;
  32. wcex.cbClsExtra = 0;
  33. wcex.cbWndExtra = 0;
  34. wcex.hInstance = hInstance;
  35. wcex.hIcon = 0;
  36. wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
  37. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  38. wcex.lpszMenuName = NULL;
  39. wcex.lpszClassName = pszClassName;
  40. wcex.hIconSm = 0;
  41. if (!::RegisterClassEx(&wcex)) {
  42. return FALSE;
  43. }
  44. return TRUE;
  45. }
  46. return TRUE;
  47. }
  48. static HWND Create( LPCTSTR lpWindowName,
  49. LPCTSTR lpWindowClassName,
  50. DWORD dwStyle,
  51. DWORD dwExStyle,
  52. int x,
  53. int y,
  54. int nWidth,
  55. int nHeight,
  56. HWND hWndParent,
  57. HMENU hMenu,
  58. HINSTANCE hInstance)
  59. {
  60. //
  61. // register the window class
  62. //
  63. if (RegisterClass( hInstance, lpWindowClassName)) {
  64. HWND hWnd = CreateWindowEx(dwExStyle,
  65. lpWindowClassName,
  66. lpWindowName,
  67. dwStyle,
  68. x,
  69. y,
  70. nWidth,
  71. nHeight,
  72. hWndParent,
  73. hMenu,
  74. hInstance,
  75. NULL );
  76. SetWindowLongPtr(hWnd,GWLP_USERDATA,NULL);
  77. gTreeViewWndSysWndProc = (WNDPROC)SetWindowLongPtr(hWnd,
  78. GWLP_WNDPROC,
  79. (LONG)(LONG_PTR)TreeViewWndProc);
  80. return hWnd;
  81. } else {
  82. Trace(TEXT("RegisterClass failed, GetLastError() reported %d"),GetLastError());
  83. return NULL;
  84. }
  85. }
  86. //
  87. // Public members
  88. //
  89. VOID SetWindowHandle(HWND hWnd);
  90. HTREEITEM InsertItem (LPTVINSERTSTRUCT lpInsertStruct );
  91. HIMAGELIST SetImageList(HIMAGELIST hImageList, INT iImage);
  92. //
  93. // windows message handlers
  94. //
  95. LRESULT OnPaint ( WPARAM wParam, LPARAM lParam );
  96. LRESULT OnDestroy ( WPARAM wParam, LPARAM lParam );
  97. LRESULT OnCreate ( WPARAM wParam, LPARAM lParam );
  98. LPARAM OnSize ( WPARAM wParam, LPARAM lParam );
  99. LRESULT OnSizing ( WPARAM wParam, LPARAM lParam );
  100. LPARAM OnSetFocus( WPARAM wParam, LPARAM lParam );
  101. LRESULT OnCommand ( WPARAM wParam, LPARAM lParam );
  102. LRESULT OnRButtonDown(WPARAM wParam, LPARAM lParam);
  103. LRESULT OnParentResize(WPARAM wParam, LPARAM lParam);
  104. static LRESULT CALLBACK TreeViewWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  105. {
  106. //Trace(TEXT("Messages to TreeViewWnd\nhWnd = %p, uMsg = %d, wParam = %x, lParam = %x"), hWnd, uMsg, wParam, lParam);
  107. SC_BEGIN_MESSAGE_HANDLERS(CTreeViewWnd)
  108. {
  109. SC_HANDLE_MESSAGE( WM_RBUTTONDOWN, OnRButtonDown);
  110. SC_HANDLE_MESSAGE(WM_PARENT_WM_SIZE, OnParentResize);
  111. SC_HANDLE_MESSAGE_DEFAULT_TREEVIEW();
  112. }
  113. SC_END_MESSAGE_HANDLERS();
  114. }
  115. };
  116. #endif