OVH Cloud OVH Cloud

background slider !

4 réponses
Avatar
Titeuf
bonjour,
à première vue il n'est pas possible de changer le background du controle
slider
quelqu'un saurait-il si oui il y a un moyen de le changer ?
ou existe-il d'autres controles slider gratuit qui son un peu plus
personnalisables ?

merci

4 réponses

Avatar
François Picalausa
Hello,

le contrôle trackbar (slider) peut utiliser le customdraw pour les versions
suivantes de windows:
Windows 2000, Windows NT 4.0 with Internet Explorer 3.0, Windows 98, Windows
95 with Internet Explorer 3.0

Il te faudra commencer par sous classer le parent de ton contrôle (la form,
probablement) et ensuite capter les WM_NOTIFY.
Une fois ceux ci récupérés et leur information copiée (CopyMemory Alias
"RtlMoveMemory"), tu pourra tester si le message s'adresse bien au slider.
Si c'est le cas tu pourra copier les informations du WM_NOTIFY dans un
structure NMCUSTOMDRAW.
En testant le dwItemSpec de cette structure contre la valeur TBCD_CHANNEL,
en retournant CDRF_SKIPDEFAULT lorsque le dwStage est CDDS_ITEMPREPAINT et
en utilisant les API GDI, il serait possible de tracer un fond.

Je vais tenter de faire un petit exemple utilisant cette technique et aussi
voir s'il n'y a pas de méthode moins "lourde".

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net

"Titeuf" a écrit dans le message de
news:
à première vue il n'est pas possible de changer le background du
controle slider
quelqu'un saurait-il si oui il y a un moyen de le changer ?
ou existe-il d'autres controles slider gratuit qui son un peu plus
personnalisables ?


Avatar
Titeuf
je comprends bien ta méthode mais il y a certains points ou je ne sais pas
comment faire pour le code
merci
Avatar
François Picalausa
Hello,

Pour t'aider sur ces points que tu nes sais pas comment implémenter, et en
attendant que j'ai réussi à faire un exemple pour le slider, un exemple qui
dessine des progressbar sur une listview est disponible ici:
http://apisvb.europe.webmatrixhosting.net/progressbar.zip (7Ko)

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net

"Titeuf" a écrit dans le message de
news:%
je comprends bien ta méthode mais il y a certains points ou je ne
sais pas comment faire pour le code
merci


Avatar
François Picalausa
Hello,

Voici un bout de code fonctionne (j'utilise un contrôle de sous classement
mais le module disponible avec l'autre exemple sur mon site peut aussi être
utilisé):
Option Explicit

Private Const NM_FIRST = &H0& '(0U- 0U)
Private Const NM_CUSTOMDRAW = (NM_FIRST - 12)
Private Const WM_NOTIFY = &H4E

Private Const CDDS_PREPAINT = &H1
Private Const CDDS_POSTPAINT = &H2
Private Const CDDS_PREERASE = &H3
Private Const CDDS_POSTERASE = &H4

Private Const CDDS_ITEM = &H10000
Private Const CDDS_ITEMPREPAINT = (CDDS_ITEM Or CDDS_PREPAINT)
Private Const CDDS_ITEMPOSTPAINT = (CDDS_ITEM Or CDDS_POSTPAINT)
Private Const CDDS_ITEMPREERASE = (CDDS_ITEM Or CDDS_PREERASE)
Private Const CDDS_ITEMPOSTERASE = (CDDS_ITEM Or CDDS_POSTERASE)
Private Const CDDS_SUBITEM = &H20000

Private Const CDRF_DODEFAULT = &H0
Private Const CDRF_NEWFONT = &H2
Private Const CDRF_SKIPDEFAULT = &H4
Private Const CDRF_NOTIFYPOSTPAINT = &H10
Private Const CDRF_NOTIFYITEMDRAW = &H20
Private Const CDRF_NOTIFYSUBITEMDRAW = &H20
Private Const CDRF_NOTIFYPOSTERASE = &H40

Private Enum BDR
BDR_RAISEDOUTER = &H1
BDR_SUNKENOUTER = &H2
BDR_RAISEDINNER = &H4
BDR_SUNKENINNER = &H8
BDR_OUTER = (BDR_RAISEDOUTER Or BDR_SUNKENOUTER)
BDR_INNER = (BDR_RAISEDINNER Or BDR_SUNKENINNER)
BDR_RAISED = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
BDR_SUNKEN = (BDR_SUNKENOUTER Or BDR_SUNKENINNER)
End Enum

Private Enum EDGE
EDGE_RAISED = (BDR_RAISEDOUTER Or BDR_RAISEDINNER)
EDGE_SUNKEN = (BDR_SUNKENOUTER Or BDR_SUNKENINNER)
EDGE_ETCHED = (BDR_SUNKENOUTER Or BDR_RAISEDINNER)
EDGE_BUMP = (BDR_RAISEDOUTER Or BDR_SUNKENINNER)
End Enum

Private Enum BF
BF_LEFT = &H1
BF_TOP = &H2
BF_RIGHT = &H4
BF_BOTTOM = &H8
BF_TOPLEFT = (BF_TOP Or BF_LEFT)
BF_TOPRIGHT = (BF_TOP Or BF_RIGHT)
BF_BOTTOMLEFT = (BF_BOTTOM Or BF_LEFT)
BF_BOTTOMRIGHT = (BF_BOTTOM Or BF_RIGHT)
BF_RECT = (BF_LEFT Or BF_TOP Or BF_RIGHT Or BF_BOTTOM)
BF_DIAGONAL = &H10
BF_DIAGONAL_ENDTOPRIGHT = (BF_DIAGONAL Or BF_TOP Or BF_RIGHT)
BF_DIAGONAL_ENDTOPLEFT = (BF_DIAGONAL Or BF_TOP Or BF_LEFT)
BF_DIAGONAL_ENDBOTTOMLEFT = (BF_DIAGONAL Or BF_BOTTOM Or BF_LEFT)
BF_DIAGONAL_ENDBOTTOMRIGHT = (BF_DIAGONAL Or BF_BOTTOM Or BF_RIGHT)
BF_MIDDLE = &H800
BF_SOFT = &H1000
BF_ADJUST = &H2000
BF_FLAT = &H4000
BF_MONO = &H8000
End Enum


Private Enum TBCD
TBCD_TICS = &H1
TBCD_THUMB = &H2
TBCD_CHANNEL = &H3
End Enum

Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type

Private Type NMHDR
hwndFrom As Long
idFrom As Long
code As Long
End Type

Private Type NMCUSTOMDRAW
hdr As NMHDR
dwDrawStage As Long
hdc As Long
rc As RECT
dwItemSpec As Long
uItemState As Long
lItemlParam As Long
End Type

Private Declare Sub CopyMemory _
Lib "kernel32" _
Alias "RtlMoveMemory" _
( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)

Private Declare Function BitBlt _
Lib "gdi32" _
( _
ByVal hdcDest As Long, _
ByVal nXDest As Long, _
ByVal nYDest As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hdcSrc As Long, _
ByVal nXSrc As Long, _
ByVal nYSrc As Long, _
ByVal dwRop As Long _
) _
As Long

Private Declare Function DrawEdge _
Lib "User32" _
( _
ByVal hdc As Long, _
qrc As RECT, _
ByVal EDGE As Long, _
ByVal grfFlags As Long _
) _
As Long

#Const UseSubclassCtl = 1

#If UseSubclassCtl Then
Private WithEvents Subclasser As SubClassing
#End If

Private Sub Form_Load()
Picture1.Move 0, 0, Slider1.Width, Slider1.Height
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.BorderStyle = 0
Picture1.ScaleMode = 3
Slider1.TickStyle = sldBoth

#If UseSubclassCtl Then
Set Subclasser = New SubClassing
#End If
Subclasser.SubClass Me.hWnd
End Sub

Private Sub Form_Unload(Cancel As Integer)
Subclasser.UnSubclassAll
#If UseSubclassCtl Then
Set Subclasser = Nothing
#End If
End Sub

Private Sub Subclasser_Message(ByVal hWnd As Long, ByVal Msg As Long, ByVal
wParam As Long, ByVal lParam As Long, SetNewValue As Boolean, NewValue As
Long)
'On traite en fonction du message reçu
Select Case Msg
'Quand un contrôle notifie son parent
Case WM_NOTIFY
'Ce type de notifications possèdent toutes une structure qu'on
peut tester
Dim Header As NMHDR

'On copie la structur à partir de l'adresse offerte
CopyMemory Header, ByVal lParam, Len(Header)

'On regarde quel contrôle notifie son parent
Select Case Header.hwndFrom
'S'il s'agit de notre listview
Case Slider1.hWnd
'On regarde ce qu'il souhaite nous dire
Select Case Header.code
'Il souhaiterait savoir comment il doit effectuer
son traçage?
Case NM_CUSTOMDRAW
'On copie la structure correspondante
'(avant on avait uniquement copié l'en-tête)
Dim CustDraw As NMCUSTOMDRAW
CopyMemory CustDraw, ByVal lParam, Len(CustDraw)

'On regarde à quel état de traçage il est
(drawstage)
Select Case CustDraw.dwDrawStage
'Avant de peindre
Case CDDS_PREPAINT
'On demande une notification de traçage
'pour chaque item (curseur, coulisse,
traits)


SetNewValue = True
#If UseSubclassCtl Then
NewValue = CDRF_NOTIFYITEMDRAW
#Else
Subclasser_Message = CDRF_NOTIFYITEMDRAW
#End If
'Avant de peindre un item
Case CDDS_ITEMPREPAINT
Select Case CustDraw.dwItemSpec
'Traçage de la barre
Case TBCD_CHANNEL
SetNewValue = True

'Trace l'image
BitBlt CustDraw.hdc, 0, 0,
Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, vbSrcCopy
'Trace la barre
DrawEdge CustDraw.hdc,
CustDraw.rc, EDGE_SUNKEN, BF_RECT
'Connaissant CustDraw.rc, on
pourrait retracer les marques.

#If UseSubclassCtl Then
NewValue = CDRF_SKIPDEFAULT
#Else
Subclasser_Message CDRF_SKIPDEFAULT
#End If

Case Else
SetNewValue = True

#If UseSubclassCtl Then
NewValue = CDRF_DODEFAULT
#Else
Subclasser_Message CDRF_DODEFAULT
#End If
End Select
End Select
End Select
End Select
End Select
End Sub

--
François Picalausa (MVP VB)
http://faq.vb.free.fr --- http://msdn.microsoft.com
http://apisvb.europe.webmatrixhosting.net