Mandatory VSCROLL on listview..

Just starting out? Need help? Post your questions and find answers here.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Mandatory VSCROLL on listview..

Post by NoahPhense »

How do I make a mandatory VSCROLL bar on a LISTVIEW when there
aren't enough items to make it popup?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

msdn Platform SDK wrote:To create a list box by using the CreateWindow or CreateWindowEx function, use the LISTBOX class, appropriate window style constants, and the following style constants to define the list box. After the control has been created, these styles cannot be modified, except as noted.

LBS_DISABLENOSCROLL
Shows a disabled vertical scroll bar for the list box when the box does not contain enough items to scroll. If you do not specify this style, the scroll bar is hidden when the list box does not contain enough items.
The code below isn't pretty but it works here on WinXPhome with PB 3.91. The only drawback is it also adds a HSCROLL bar as well. You can remove the HSCROLL bar by uncommenting 3 lines in the code. This does not free up the HSCROLL rect, so you are left with a little dead area. Good place for a button or some maybe some text ;)

Code: Select all

If OpenWindow(0, 0, 0, 250, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListView Forced VScroll")
  CreateGadgetList(WindowID(0)) 
  ListViewGadget(0, 10, 10, 230, 130, #LBS_DISABLENOSCROLL)
  ; uncomment the next 3 lines remove the HSCROLL
  ;style = GetWindowLong_(GadgetID(0), #GWL_STYLE)
  ;newstyle = style &(~#WS_HSCROLL)
  ;SetWindowLong_(GadgetID(0), #GWL_STYLE, newstyle)
  For i=1 To 5 
    AddGadgetItem (0, -1, "Item number " + Str(i)) 
  Next 
  SetGadgetState(0, 3)
EndIf

Repeat
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow 
End
** EDIT ** NoahPhense reported a problem when he ran the code. I was not able to duplicate it as the code runs fine here. I'll leave the code here but be aware of possible problems as described below.
Last edited by Sparkie on Tue Aug 10, 2004 2:42 am, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Thanks Sparkie.. I think I'm just going to let it be.. I ran that code a few
times from inside the IDE... 2 minutes later.. 100%cpu, and couldnt do
anything.. system was dogged... windows 2k pro ..

it worked.. but I'm not sure what else happened.. ;)

Anyhow, thanks for your assisstance..

- np
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

That's odd. I've run the code over a dozen times on WinXPhome and my cpu hasn't suffered from any side effects at all. :?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Sparkie wrote:That's odd. I've run the code over a dozen times on WinXPhome and my cpu hasn't suffered from any side effects at all. :?
I uncommented the section you mentioned.. maybe its in that.. I would
attempt to reproduce it for you.. but not at the chance my blue friend
would come around.. ;)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I just ran the code with the 3 lines uncommented and still no problems here. I even ran 5 instances at once and left them running for a few minutes. No cpu usage during runtime and no crash.

Don't know what to say other than I'm sorry for sending the blues you way. :cry:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Oh no.. you didnt do anything.. I never got a blue screen.. I just don't
_want_ to.. ;)

its ok though.. I'm just going to leave it with no scroll bar anyways.. my
motives were petty. It was just for visual reasons..
deadmoap
User
User
Posts: 79
Joined: Sun Feb 22, 2004 11:45 pm
Location: Riverdale, Utah
Contact:

Post by deadmoap »

Apparently, resizing the gadget gets rid of the "dead" spot at the bottom where the HSCROLL was.

Code: Select all

If OpenWindow(0, 0, 0, 250, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListView Forced VScroll") 
  CreateGadgetList(WindowID(0)) 
  ListViewGadget(0, 10, 10, 230, 130, #LBS_DISABLENOSCROLL) 
  ; uncomment the next 3 lines remove the HSCROLL 
  style = GetWindowLong_(GadgetID(0), #GWL_STYLE) 
  newstyle = style &(~#WS_HSCROLL) 
  SetWindowLong_(GadgetID(0), #GWL_STYLE, newstyle) 
  ResizeGadget(0,10,10,230,129)    ; Resize to get rid of "dead spot"
  For i=1 To 5 
    AddGadgetItem (0, -1, "Item number " + Str(i)) 
  Next 
  SetGadgetState(0, 3) 
EndIf 

Repeat 
  Event = WaitWindowEvent() 
Until Event = #PB_Event_CloseWindow 
End
Although it may seem more logical to resize it to 230,130 (original size), but the Win32 API doesn't really resize it unless you made a change to its proportions.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Ok Sparkie and deadmoap, I've decided to use this method. Thanks for
the help, this is good work.

@deadmoap

Code: Select all

ResizeGadget(0,10,10,230,129)    ; Resize to get rid of "dead spot"
ResizeGadget(0,10,10,230,130)
I just do another resize to go back to normal.. ;)

- np
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Code: Select all

; English Forum: http://jconserv.net/purebasic/viewtopic.php?t=12053
; Authors: Sparkie, deadmoap
; Date: August 10, 2004
;
; This is an example of how to use a VSCROLL in a listview when you
; don't have enough items to make it show up.
;
; Also, very important, because of forcing the VSCROLL, the HSCROLL
; shows up, just resize the listview and the HSCROLL will go away.

If OpenWindow(0, 0, 0, 250, 170, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"ListView Forced VScroll") 
  CreateGadgetList(WindowID(0)) 
  ListViewGadget(0, 10, 10, 230, 130, #LBS_DISABLENOSCROLL) 
  ; uncomment the next 3 lines remove the HSCROLL 
  style = GetWindowLong_(GadgetID(0), #GWL_STYLE) 
  newstyle = style &(~#WS_HSCROLL) 
  SetWindowLong_(GadgetID(0), #GWL_STYLE, newstyle) 
  ResizeGadget(0,10,10,230,129)    ; Resize to get rid of "dead spot" 
  ResizeGadget(0,10,10,230,130)
  For i=1 To 5
    AddGadgetItem (0, -1, "Item number " + Str(i)) 
  Next 
  SetGadgetState(0, 3) 
EndIf 

Repeat 
  Event = WaitWindowEvent() 
Until Event = #PB_Event_CloseWindow 
End
Let's see if Andre wants to add this to the CodeArchiv..
Post Reply