Author Topic: Hide the Scrollbar in ListView  (Read 1435 times)

0 Members and 1 Guest are viewing this topic.

Offline Stefan Midegaal

  • Newbie
  • *
  • Posts: 26
Hide the Scrollbar in ListView
« on: January 21, 2017, 11:24:07 AM »
hello

How i can hide the Scrollbar from Listview?
i'am use following way.

Code: [Select]
procedure TSkinListView.HideScrollBars(Typ, Which: Integer);
var
  ierect: TRect;
  cxvs, cyvs: Integer;
  iehrgn: HRGN;

begin
  GetClientRect(Handle, ierect);

  cxvs := GetSystemMetrics(SM_CXVSCROLL); //Get the system metrics - VERT
  cyvs := GetSystemMetrics(SM_CYVSCROLL); //Get the system metrics - HORZ

  if (Which = SB_HORZ) then
    cxvs := 0; //Set VERT to zero when choosen HORZ
  if (Which = SB_VERT) then
    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(Handle, 0, ierect.Left, ierect.Top, ierect.Right + cxvs, ierect.bottom + cyvs,
    SWP_NOMOVE or SWP_NOZORDER);

  //Her we modify the rect so the right part is subbed from the rect.
  if (Which = SB_BOTH) and (Which = SB_HORZ) then
    ierect.bottom := ierect.bottom - ierect.Top;
  if (Which = SB_BOTH) and (Which = SB_VERT) then
    ierect.Right := ierect.Right - ierect.Left;

  //Just to be safe that the left/top corner is 0...
  ierect.Top := 0;
  ierect.Left := 0;

  iehrgn := 0;
  //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) then
    iehrgn := CreateRectRgn(ierect.Left, ierect.Top, ierect.Right - 2, ierect.bottom - 2);
  if (Which = SB_HORZ) then
    iehrgn := CreateRectRgn(ierect.Left, ierect.Top, ierect.Right, ierect.bottom - 2);
  if (Which = SB_VERT) then
    iehrgn := CreateRectRgn(ierect.Left, ierect.Top, ierect.Right - 2, ierect.bottom);

  //After the range has been made we add it...
  SetWindowRgn(Handle, iehrgn, True);
end;

That make Trouble if resize the window..

Any other Idea ?

greets

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2003
    • www.zapsolution.com
Re: Hide the Scrollbar in ListView
« Reply #1 on: January 21, 2017, 12:00:26 PM »
Emil,

Consider using a Region, to protect from the OS that automatically redraws all the virtual scrollbars from any window class.

But you must first check if they are visible or not, using something like this.
Code: [Select]
long skCheckScrollBar (IN HWND hWnd) {
//  Check if the control's scrollbars are shown.
//  Returns zero if (none, 1 if vertical, 2 if horizontal and 3 if both.
    RECT rw = {0}, rc = {0};
    long nRet = SCROLLBAR_NONE;
    if (IsWindowVisible(hWnd)) { // 06-25-2015
        GetWindowRect(hWnd, &rw);
        GetClientRect(hWnd, &rc);
        if (rc.right <= rw.right - rw.left - GetSystemMetrics(SM_CXVSCROLL)) { nRet = SCROLLBAR_VERT; }
        if (rc.bottom <= rw.bottom - rw.top - GetSystemMetrics(SM_CXHSCROLL)) { nRet = nRet + SCROLLBAR_HORZ; }
    }
    return nRet;
}
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Stefan Midegaal

  • Newbie
  • *
  • Posts: 26
Re: Hide the Scrollbar in ListView
« Reply #2 on: January 21, 2017, 12:28:39 PM »
Thank you..
I will check this.

the Trouble is that the Window is resize not the entire ListView, the width not Changed
if set the scrollbar on my way. to zero

greets
« Last Edit: January 21, 2017, 12:46:26 PM by Stefan Midegaal »