Reputation: 155
I have a owner drawn listbox to which I add a lot of items(and this takes time), when the items are being added, the vertical scrollbar keeps on getting smaller, I want to disable the scrollbar when I begin to add and then re enable it ..
I have tried--
LONG old_style=GetWindowLong(hPlayList,GWL_STYLE);
LONG new_style= old_style&~WS_VSCROLL;
SetWindowLong(hPlayList,GWL_STYLE,new_style);
SetWindowPos(hPlayList,HWND_TOP,lstRc.left,lstRc.right,lstRc.right-lstRc.top,lstRc.bottom-lstRc.top,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
UpdateWindow(hPlayList);
and
ShowScrollBar(hPlayList,SB_VERT,FALSE);
But the scrollbar is still shown when I add items, the listbox is created like,
hPlayList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTBOX, NULL,
LBS_OWNERDRAWFIXED |WS_VSCROLL | WS_HSCROLL |WS_CHILD | WS_TABSTOP | WS_VISIBLE|LBS_NOTIFY|LBS_HASSTRINGS,
lbsPos.x, lbsPos.y,350, 400, hWnd, (HMENU) LIST_ID, GetModuleHandle(NULL), NULL);
and I use SendMessage() to add the items.
I had also tried,
ShowWindow(hPlayList,SW_HIDE);
and
SendMessage(hPlayList,WM_SETREDRAW,(WPARAM)FALSE,0);
Upvotes: 4
Views: 861
Reputation: 21242
You can use the WM_SETREDRAW
message with wParam (fRedraw)
set to FALSE
before adding strings. when you are done set it to TRUE
and UpdateWindow
or RedrawWindow
.
This message can be useful if an application must add several items to a list box. The application can call this message with wParam set to FALSE, add the items, and then call the message again with wParam set to TRUE. Finally, the application can call RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN) to cause the list box to be repainted.
Upvotes: 3