Flat Scroll Bar

Ad1
02-11-2002, 12:49 PM
I need a flat scroll bar for my .ocx but I want it to respond to the mouse wheel when it has the focus like a normal scroll bar would

I have 3 ideas on this and help with any or an alternative suggestion would be appreciated (I can't use SetCapture, and would prefer not to hook)

1)make flat scrollbar respond to mouse wheel

2)make the normal scrollbar's backcolor grey to look like a flat scroll bar

3) use a flat scrollbar with a hidden normal scrollbar that has the focus, and which move in unison (problem here is it only works when you can see the normal scrollbar)

Garrett Sever
02-13-2002, 06:28 AM
Whoa. Sorry man... I missed this ? with the stuff I have been doing the last few weeks.

How did you want to handle this particular request? Did you want to try to modify the style of the standard scrollbars that come with VB? This might be possible with GetWindowLong/SetWindowLong/GWL_EXSTYLE, but I haven't tried it.

Your option #1 might involve a little subclassing for the WM_MOUSEWHEEL message. Shouldn't be too hard.

Option #2 should be easy... you could subclass the scrollbar's parent and return a brush handle for WM_CTLCOLORSCROLLBAR. This only works on Windows NT/2000/XP and maybe ME (don't know).

The other option would probably be to add a UserControl that has lots of nasty (fun) API stuff and create the flatscrollbar using the CreateWindow function... again, haven't tried. This is also essentially a bottom-up solution to idea #1.

I wouldn't recommend #3.

Let me know if you need some help on this one. Sounds fun.

Ad1
02-13-2002, 11:21 AM
:D I thought this would be up your street Garret

I am making a custom combobox control so I think I'll probably go for option #2 at the moment (can you put custom controls inside custom controls ???), although I'm interested in them all as I intend to make a custom scrollbar control soon

I'll zip up my project and post it tommorow

cheers ;)

divil
02-14-2002, 06:09 AM
Look on http://www.vbaccelerator.com for code on how to do flat scrollbars.

Ad1
02-18-2002, 12:57 PM
Garrett: sorry about the delay in reply, I've been having trouble with my web connection :mad: , seems alright now though :rolleyes: here's the zip

Divil: thanks for the link I'll take a look

Ad1
02-20-2002, 08:39 AM
I've got a hook working on a scrollbar on a normal form but it won't work on my usercontrol any ideas ?
I've tried passing the gHW param as usercontrol.hwnd/usercontrol.parent.hwnd/vscroll1.hwnd but nothing seems to work (when I did it on the form I used the form's hwnd)
Private Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Const GWL_WNDPROC = -4
Const WM_CTLCOLORSCROLLBAR = 311

Dim lpPrevWndProc As Long

Public Sub Hook(gHW As Long)
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub Unhook(gHW As Long)
Dim temp As Long
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If uMsg <> WM_CTLCOLORSCROLLBAR Then
Debug.Print uMsg, hw
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End If
End Function
any help much appreciated

Ad1
02-22-2002, 12:44 PM
OK problem solved, I ended up having to use a mix of #1 and #3 with subclassing

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum