SkinWin.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /************************************************************************
  2. * 程序名: 精仿QQ主界面
  3. * 制作人: 李克平, 2011年04月11日
  4. * 版本号: 1.0
  5. ************************************************************************/
  6. #include "stdafx.h"
  7. #include "SkinWin.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CSkinWin::CSkinWin()
  17. {
  18. }
  19. CSkinWin::~CSkinWin()
  20. {
  21. }
  22. BOOL CSkinWin::InstallSkin(CWnd *wnd)
  23. {
  24. if ( !wnd ) return FALSE;
  25. HookWindow( (HWND)NULL);
  26. int r = HookWindow( wnd );
  27. DWORD style = GetWindowLong( m_hWnd, GWL_STYLE );
  28. style &= ~(WS_MINIMIZEBOX);
  29. style &= ~WS_MAXIMIZEBOX;
  30. style &= ~WS_SYSMENU;
  31. SetWindowLong( m_hWnd, GWL_STYLE, style );
  32. return r;
  33. }
  34. LRESULT CSkinWin::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
  35. {
  36. if ( !IsWindow(m_hWnd) )
  37. return 0;
  38. switch ( msg )
  39. {
  40. case WM_NCHITTEST:
  41. {
  42. Default();
  43. return OnNcHitTest(CPoint(LOWORD(lp), HIWORD(lp)));
  44. }
  45. default:
  46. return Default();
  47. }
  48. }
  49. UINT CSkinWin::OnNcHitTest(CPoint point)
  50. {
  51. static int m_TitleHeight = 5;
  52. static int m_BorderLeftWidth = 5;
  53. static int m_BorderRightWidth=5;
  54. static int m_BorderBottomHeight = 5;
  55. CWnd *pWnd = CWnd::FromHandle(m_hWnd);
  56. CRect wr;
  57. pWnd->GetWindowRect(wr);
  58. point.x -= wr.left;
  59. point.y -= wr.top;
  60. CRect rc;
  61. int cx = GetSystemMetrics(SM_CXSMICON);
  62. int cy = GetSystemMetrics(SM_CYSMICON);
  63. rc = CRect( 0, 0, m_BorderLeftWidth, m_TitleHeight );
  64. if ( PtInRect( rc, point )) //!IsZoomed(m_hWnd) )
  65. return HTTOPLEFT;
  66. rc = CRect( wr.Width() - m_BorderLeftWidth, 0, wr.Width(), m_TitleHeight );
  67. if ( PtInRect( rc, point ) ) //!IsZoomed(m_hWnd) )
  68. return HTTOPRIGHT;
  69. rc = CRect( 0, wr.Height() - m_BorderBottomHeight, m_BorderLeftWidth, wr.Height() );
  70. if ( PtInRect( rc, point ) ) //!IsZoomed(m_hWnd) )
  71. return HTBOTTOMLEFT;
  72. rc = CRect( wr.Width()-m_BorderRightWidth, wr.Height() - m_BorderBottomHeight, wr.Width(), wr.Height() );
  73. if ( PtInRect( rc, point )) //!IsZoomed(m_hWnd) )
  74. return HTBOTTOMRIGHT;
  75. rc = CRect( 0, m_TitleHeight, m_BorderLeftWidth, wr.Height() - m_BorderBottomHeight );
  76. if ( PtInRect( rc, point )) //!IsZoomed(m_hWnd) )
  77. return HTLEFT;
  78. rc = CRect( wr.Width()-m_BorderRightWidth, m_TitleHeight, wr.Width(), wr.Height() - m_BorderBottomHeight );
  79. if ( PtInRect( rc, point ) ) //!IsZoomed(m_hWnd) )
  80. return HTRIGHT;
  81. rc = CRect( m_BorderLeftWidth, wr.Height() - m_BorderBottomHeight, wr.Width()-m_BorderRightWidth, wr.Height() );
  82. if ( PtInRect( rc, point ) ) //!IsZoomed(m_hWnd) )
  83. return HTBOTTOM;
  84. rc = CRect( m_BorderLeftWidth, 0, wr.Width()-m_BorderRightWidth, m_BorderBottomHeight );
  85. if ( PtInRect( rc, point )) //!IsZoomed(m_hWnd) )
  86. return HTTOP;
  87. return HTCLIENT;
  88. }