📄 listctrlhiddensb.cpp
字号:
// ListCtrlHiddenSB.cpp : implementation file
//
#include "stdafx.h"
#include "CListCtrlExample.h"
#include "ListCtrlHiddenSB.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListCtrlHiddenSB
CListCtrlHiddenSB::CListCtrlHiddenSB()
{
NCOverride=FALSE; //False as default...
Who=SB_BOTH; //Default remove both...
}
CListCtrlHiddenSB::~CListCtrlHiddenSB()
{
}
BEGIN_MESSAGE_MAP(CListCtrlHiddenSB, CListCtrl)
//{{AFX_MSG_MAP(CListCtrlHiddenSB)
ON_WM_NCCALCSIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListCtrlHiddenSB message handlers
//****************************************************************************************
void CListCtrlHiddenSB::HideScrollBars(int Type, int Which)
{
if(Type==LCSB_CLIENTDATA) //This is the clientrect function
{
RECT ierect;
int cxvs, cyvs;
GetClientRect(&ierect); //Get client width and height
cxvs = GetSystemMetrics (SM_CXVSCROLL); //Get the system metrics - VERT
cyvs = GetSystemMetrics (SM_CYVSCROLL); //Get the system metrics - HORZ
if(Which==SB_HORZ) cxvs=0; //Set VERT to zero when choosen HORZ
if(Which==SB_VERT) cyvs=0; //Set HORZ to zero when choosen VERT
//Here we set the position of the window to the clientrect + the size of the scrollbars
SetWindowPos(NULL, ierect.left, ierect.top, ierect.right+cxvs, ierect.bottom+cyvs, SWP_NOMOVE | SWP_NOZORDER);
//Her we modify the rect so the right part is subbed from the rect.
if(Which==SB_BOTH||Which==SB_HORZ) ierect.bottom -= ierect.top;
if(Which==SB_BOTH||Which==SB_VERT) ierect.right -= ierect.left;
//Just to be safe that the left/top corner is 0...
ierect.top = 0;
ierect.left = 0;
HRGN iehrgn = NULL; //This range is created base on which scrollbar that is going to be removed!
//The -2 is probably a border of some kind that we also need to remove. I could not find any good
//metrics that gave me an 2 as an answer. So insted we makes it static with -2.
if(Which==SB_BOTH) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right-2, ierect.bottom-2);
if(Which==SB_HORZ) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right, ierect.bottom-2);
if(Which==SB_VERT) iehrgn=CreateRectRgn (ierect.left, ierect.top, ierect.right-2, ierect.bottom);
//After the range has been made we add it...
SetWindowRgn (iehrgn, TRUE);
//Reset of NCOverride
NCOverride=FALSE;
}
if(Type==LCSB_NCOVERRIDE) //This is the NcCalcSize override
{
NCOverride=TRUE; //Set to true, so we run the code on each OnNcCalcSize.
Who=Which; //Selects which scrollbars to get hidden.
}
}
//****************************************************************************************
void CListCtrlHiddenSB::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
// TODO: Add your message handler code here and/or call default
if(NCOverride==TRUE) //If the NCOverride is true we remove each time the CListCtrl calc its rect.
{
if(Who==SB_HORZ) ModifyStyle(WS_HSCROLL ,0,0); //Just by modifing the style we remove the scrollbar
if(Who==SB_VERT) ModifyStyle(WS_VSCROLL,0,0);
if(Who==SB_BOTH) ModifyStyle(WS_HSCROLL | WS_VSCROLL,0,0);
}
CListCtrl::OnNcCalcSize(bCalcValidRects, lpncsp);
}
//****************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -