ListCtrlHiddenSB.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 3k
Category:

Graph program

Development Platform:

Visual C++

  1. // ListCtrlHiddenSB.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "..//MaterialsEditor.h"
  5. #include "ListCtrlHiddenSB.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CListCtrlHiddenSB
  13. CListCtrlHiddenSB::CListCtrlHiddenSB()
  14. {
  15. NCOverride=FALSE; //False as default...
  16. Who=SB_BOTH; //Default remove both...
  17. }
  18. CListCtrlHiddenSB::~CListCtrlHiddenSB()
  19. {
  20. }
  21. BEGIN_MESSAGE_MAP(CListCtrlHiddenSB, CListCtrl)
  22. //{{AFX_MSG_MAP(CListCtrlHiddenSB)
  23. ON_WM_NCCALCSIZE()
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CListCtrlHiddenSB message handlers
  28. //****************************************************************************************
  29. void CListCtrlHiddenSB::HideScrollBars(int Type, int Which)
  30. {
  31. if(Type==LCSB_CLIENTDATA) //This is the clientrect function
  32. {
  33. RECT ierect;
  34. int cxvs, cyvs;
  35. GetClientRect(&ierect); //Get client width and height
  36. cxvs = GetSystemMetrics (SM_CXVSCROLL); //Get the system metrics - VERT
  37. cyvs = GetSystemMetrics (SM_CYVSCROLL); //Get the system metrics - HORZ
  38. if(Which==SB_HORZ) cxvs=0; //Set VERT to zero when choosen HORZ
  39. if(Which==SB_VERT) cyvs=0; //Set HORZ to zero when choosen VERT
  40. //Here we set the position of the window to the clientrect + the size of the scrollbars
  41. SetWindowPos(NULL, ierect.left, ierect.top, ierect.right+cxvs, ierect.bottom+cyvs, SWP_NOMOVE | SWP_NOZORDER);
  42. //Her we modify the rect so the right part is subbed from the rect.
  43. if(Which==SB_BOTH||Which==SB_HORZ) ierect.bottom -= ierect.top;
  44. if(Which==SB_BOTH||Which==SB_VERT) ierect.right -= ierect.left;
  45. //Just to be safe that the left/top corner is 0...
  46. ierect.top = 0;
  47. ierect.left = 0;
  48. HRGN iehrgn = NULL; //This range is created base on which scrollbar that is going to be removed!
  49. //The -2 is probably a border of some kind that we also need to remove. I could not find any good
  50. //metrics that gave me an 2 as an answer. So insted we makes it static with -2.
  51. if(Which==SB_BOTH) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right-2, ierect.bottom-2);
  52. if(Which==SB_HORZ) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right, ierect.bottom-2);
  53. if(Which==SB_VERT) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right-2, ierect.bottom);
  54. //After the range has been made we add it...
  55. SetWindowRgn (iehrgn, TRUE);
  56. //Reset of NCOverride
  57. NCOverride=FALSE;
  58. }
  59. if(Type==LCSB_NCOVERRIDE) //This is the NcCalcSize override
  60. {
  61. NCOverride=TRUE; //Set to true, so we run the code on each OnNcCalcSize.
  62. Who=Which; //Selects which scrollbars to get hidden.
  63. }
  64. }
  65. //****************************************************************************************
  66. void CListCtrlHiddenSB::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
  67. {
  68. // TODO: Add your message handler code here and/or call default
  69. if(NCOverride==TRUE) //If the NCOverride is true we remove each time the CListCtrl calc its rect.
  70. {
  71.   if(Who==SB_HORZ) ModifyStyle(WS_HSCROLL ,0,0); //Just by modifing the style we remove the scrollbar
  72.   if(Who==SB_VERT) ModifyStyle(WS_VSCROLL,0,0);
  73.   if(Who==SB_BOTH) ModifyStyle(WS_HSCROLL | WS_VSCROLL,0,0);
  74. }
  75. CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
  76. }
  77. //****************************************************************************************