Leaked source code of windows server 2003
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.

145 lines
3.7 KiB

  1. #ifndef __MOVEWND_H_INCLUDED
  2. #define __MOVEWND_H_INCLUDED
  3. /*******************************************************************************
  4. *
  5. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  6. *
  7. * TITLE: MOVEWND.H
  8. *
  9. * VERSION: 1.0
  10. *
  11. * AUTHOR: ShaunIv
  12. *
  13. * DATE: 7/31/1999
  14. *
  15. * DESCRIPTION: Simplified Wrapper for DeferWindowPos, plus a couple helpers
  16. *
  17. * To use:
  18. *
  19. * CMoveWindow mw;
  20. * mw.MoveWindow( hWnd1, x1, y1, w1, h1, flags1 );
  21. * mw.MoveWindow( hWnd2, x2, y2, w2, h2, flags2 );
  22. * mw.Apply(); // Optional, the destructor will do this if necessary.
  23. *
  24. *******************************************************************************/
  25. #include <windows.h>
  26. class CMoveWindow
  27. {
  28. public:
  29. // Move/Size Flags
  30. enum
  31. {
  32. NO_MOVEX = 0x00000001,
  33. NO_MOVEY = 0x00000002,
  34. NO_MOVE = (NO_MOVEX|NO_MOVEY),
  35. NO_SIZEX = 0x00000004,
  36. NO_SIZEY = 0x00000008,
  37. NO_SIZE = (NO_SIZEX|NO_SIZEY)
  38. };
  39. private:
  40. // Not implemented
  41. CMoveWindow( const CMoveWindow & );
  42. CMoveWindow &operator=( const CMoveWindow & );
  43. private:
  44. HDWP m_hDeferWindowPos;
  45. bool m_bNeedApply;
  46. public:
  47. CMoveWindow( int nNumWindows = 10 )
  48. : m_bNeedApply(false)
  49. {
  50. Initialize(nNumWindows);
  51. }
  52. bool Initialize( int nNumWindows = 10 )
  53. {
  54. m_hDeferWindowPos = BeginDeferWindowPos(nNumWindows);
  55. return(m_hDeferWindowPos != NULL);
  56. }
  57. static bool ScreenToClient( HWND hwnd, RECT &rc )
  58. {
  59. return (MapWindowPoints( NULL, hwnd, reinterpret_cast<POINT*>(&rc), 2 ) != 0);
  60. }
  61. void Move( HWND hWnd, int x, int y, DWORD nFlags = 0 )
  62. {
  63. SizeMove( hWnd, x, y, 0, 0, NO_SIZE|nFlags );
  64. }
  65. void Size( HWND hWnd, int w, int h, DWORD nFlags = 0 )
  66. {
  67. SizeMove( hWnd, 0, 0, w, h, NO_MOVE|nFlags );
  68. }
  69. void SizeMove( HWND hWnd, int x, int y, int w, int h, DWORD nFlags = 0 )
  70. {
  71. m_bNeedApply = true;
  72. RECT rcWndInScreenCoords, rcWndInParentCoords;
  73. GetWindowRect( hWnd, &rcWndInScreenCoords );
  74. rcWndInParentCoords = rcWndInScreenCoords;
  75. HWND hWndParent = GetParent(hWnd);
  76. if (hWndParent)
  77. {
  78. ScreenToClient( hWndParent, rcWndInParentCoords );
  79. }
  80. if (m_hDeferWindowPos)
  81. {
  82. DeferWindowPos( m_hDeferWindowPos, hWnd, NULL,
  83. nFlags&NO_MOVEX ? rcWndInParentCoords.left : x,
  84. nFlags&NO_MOVEY ? rcWndInParentCoords.top : y,
  85. nFlags&NO_SIZEX ? rcWndInParentCoords.right - rcWndInParentCoords.left : w,
  86. nFlags&NO_SIZEY ? rcWndInParentCoords.bottom - rcWndInParentCoords.top : h,
  87. SWP_NOACTIVATE|SWP_NOZORDER
  88. );
  89. }
  90. }
  91. void Hide( HWND hWnd )
  92. {
  93. if (IsWindowVisible(hWnd))
  94. {
  95. ShowWindow( hWnd, SW_HIDE );
  96. }
  97. }
  98. void Show( HWND hWnd )
  99. {
  100. if (!IsWindowVisible(hWnd))
  101. {
  102. ShowWindow( hWnd, SW_SHOW );
  103. }
  104. }
  105. void Enable( HWND hWnd )
  106. {
  107. if (!IsWindowEnabled(hWnd))
  108. {
  109. ShowWindow( hWnd, TRUE );
  110. }
  111. }
  112. void Disable( HWND hWnd )
  113. {
  114. if (IsWindowEnabled(hWnd))
  115. {
  116. ShowWindow( hWnd, FALSE );
  117. }
  118. }
  119. void Apply(void)
  120. {
  121. if (m_bNeedApply && m_hDeferWindowPos)
  122. {
  123. EndDeferWindowPos(m_hDeferWindowPos);
  124. m_hDeferWindowPos = NULL;
  125. }
  126. }
  127. ~CMoveWindow(void)
  128. {
  129. Apply();
  130. }
  131. };
  132. #endif // __MOVEWND_H_INCLUDED