|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
Sujet : Couleur de fond d'un contrôle slider [ Divers / General ] (Leo_Robotic_Passion)
Informations & options pour cette discussion
vendredi 16 novembre 2007 à 22:04:39 |
Couleur de fond d'un contrôle slider

Leo_Robotic_Passion
|
Bonjour a tous Quelqu'un peut me dire dans un 1er temps si il y a un inconvénient à utiliser cette méthode pour mettre une couleur de fond sur un contrôle slider ? Et si il est possible de gérer cet événement si le contrôle est placé sur une picturebox ?
dans un module : Option Explicit Public defWindowProc As Long Public hSliderHwnd As Long Private hSliderBGBrush As Long Private Const WM_USER = &H400& Private Const TBM_GETTOOLTIPS = (WM_USER + 30) Private Const TTM_ACTIVATE = (WM_USER + 1) Private Const GWL_WNDPROC As Long = (-4) Private Const WM_GETMINMAXINFO As Long = &H24 Private Const WM_TIMECHANGE = &H1E Private Const WM_DESTROY = &H2 Private Const WM_CTLCOLORSTATIC = &H138 Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Sub CreateSliderBrush(clrref As Long, bReset As Boolean) If (hSliderBGBrush <> 0) Or (bReset = True) Then Call DeleteSliderBrush End If If hSliderBGBrush = 0 Then hSliderBGBrush = CreateSolidBrush(clrref) End If End Sub
Public Sub DeleteSliderBrush() If (hSliderBGBrush <> 0) Then DeleteObject hSliderBGBrush hSliderBGBrush = 0 End If End Sub
Public Function Slider_ActivateToolTips(hwndSlider As Long, bEnabled As Boolean) As Long Dim hToolTips As Long hToolTips = SendMessage(hwndSlider, TBM_GETTOOLTIPS, ByVal 0&, ByVal 0&) If hToolTips <> 0 Then Slider_ActivateToolTips = SendMessage(hToolTips, TTM_ACTIVATE, ByVal Abs(bEnabled), ByVal 0&) End If End Function
Public Sub SubClass(hWnd As Long) On Error Resume Next defWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc) End Sub
Public Sub UnSubClass(hWnd As Long) If defWindowProc Then SetWindowLong hWnd, GWL_WNDPROC, defWindowProc defWindowProc = 0 End If End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Select Case hWnd Case Form1.hWnd Select Case uMsg Case WM_CTLCOLORSTATIC If (lParam = hSliderHwnd) And (hSliderBGBrush <> 0) Then WindowProc = hSliderBGBrush Exit Function Else WindowProc = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam) Exit Function End If Case WM_DESTROY If (hSliderBGBrush <> 0) Then Call DeleteSliderBrush hSliderBGBrush = 0 End If Call UnSubClass(hWnd) Case Else WindowProc = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam) Exit Function End Select Case Else WindowProc = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam) End Select End Function
dans un form : - 1 Slider: Slider1 - 1 checkbox: Check1 Option Explicit Private Sub Form_Load() CreateSliderBrush RGB(255, 255, 255), False hSliderHwnd = Slider1.hWnd Call SubClass(Me.hWnd) Check1.Value = vbChecked End Sub Private Sub Form_Unload(Cancel As Integer) If defWindowProc <> 0 Then Call UnSubClass(Me.hWnd) End If Call DeleteSliderBrush End Sub Private Sub Check1_Click() Slider_ActivateToolTips Slider1.hWnd, (Check1.Value = vbChecked) End Sub
Merci Léo
|
|
|
vendredi 16 novembre 2007 à 22:36:15 |
Re : Couleur de fond d'un contrôle slider

Exploreur
|
Réponse acceptée !
Salut, Ben apparement, la méthode c'est du SubClassing....Puis en ce qui concerne le fonctionnement sile contrôle est placer dans une picturebox, cela doit-être faisable, je pense qu'il y a quelque chose à faire au niveau du hWnd, il faut envoyer le hwnd du conteneur..
A+ Exploreur
Linux a un noyau, Windows un pépin 
|
|
|
vendredi 16 novembre 2007 à 23:56:46 |
Re : Couleur de fond d'un contrôle slider

Leo_Robotic_Passion
|
Merci Exploreur
Autre question : Disons que j'ai un groupe de 10 slider. Je devrais gérer de cette façon : Option Explicit Dim i As Long
Private Sub Form_Load() CreateSliderBrush RGB(255, 255, 255), False For i = 0 To 9 hSliderHwnd = Slider1(i).hWnd Next Call SubClass(Me.hWnd) Check1.Value = vbChecked End Sub Private Sub Form_Unload(Cancel As Integer) If defWindowProc <> 0 Then Call UnSubClass(Me.hWnd) End If Call DeleteSliderBrush End Sub Private Sub Check1_Click() For i = 0 To 9 Slider_ActivateToolTips Slider1(i).hWnd, (Check1.Value = vbChecked) Next End Sub
Quelqu'un sait pourquoi je n'ai qu'un contrôle qui prend la couleur de fond ? Merci Léo
|
|
|
samedi 17 novembre 2007 à 14:09:14 |
Re : Couleur de fond d'un contrôle slider
|
samedi 17 novembre 2007 à 14:24:17 |
Re : Couleur de fond d'un contrôle slider

Exploreur
|
Salut, Il faut surement retouché le code, car je viens de faire l'essai et cela ne fonctionne pas avec une boucle.....Bon je ne saurais quoi te dire, car cela dépasse mes connaissances.... A+ Exploreur
Linux a un noyau, Windows un pépin 
|
|
|
samedi 17 novembre 2007 à 14:25:17 |
Re : Couleur de fond d'un contrôle slider

Exploreur
|
D'ailleurs c'est dans le module qui faut revoir le code.... Bon dev.. A+ Exploreur
Linux a un noyau, Windows un pépin 
|
|
|
samedi 17 novembre 2007 à 14:29:16 |
Re : Couleur de fond d'un contrôle slider

Leo_Robotic_Passion
|
Merci Exploreur Je suis dans le meme cas que toi! Un expert en SubClassing pour un petit coup de main SVP ?  Merci Léo
|
|
|
samedi 17 novembre 2007 à 23:19:21 |
Re : Couleur de fond d'un contrôle slider

PCPT
|
Réponse acceptée !
salut, faut vraiment que tu lises ce que tu copies!!!! dans ta boucle tu stoques la valeur du handle. beh ouai mais en boucle forcément c'est uniquement le dernier donc faut tous les stoquer (tableau) et faire le test dans ta windowproc 'FORM Option Explicit
Dim i As Long
Private Sub Form_Load() CreateSliderBrush RGB(255, 255, 255), False For i = 0 To 9 hSliderHwnd(i) = Slider1(i).hWnd Next Call SubClass(Me.hWnd) Check1.Value = vbChecked End Sub
Private Sub Form_Unload(Cancel As Integer) Call UnSubClass Call DeleteSliderBrush End Sub
Private Sub Check1_Click() For i = 0 To 9 Slider_ActivateToolTips Slider1(i).hWnd, (Check1.Value = vbChecked) Next End Sub
'MODULE Option Explicit
Private Const WM_USER As Long = &H400& Private Const TBM_GETTOOLTIPS As Long = (WM_USER + 30) Private Const TTM_ACTIVATE As Long = (WM_USER + 1) Private Const GWL_WNDPROC As Long = (-4) Private Const WM_GETMINMAXINFO As Long = &H24 Private Const WM_TIMECHANGE As Long = &H1E Private Const WM_DESTROY As Long = &H2 Private Const WM_CTLCOLORSTATIC As Long = &H138
Dim lFrmHwnd As Long Dim defWindowProc As Long Public hSliderHwnd(9) As Long Dim hSliderBGBrush As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Sub CreateSliderBrush(clrref As Long, bReset As Boolean) If (hSliderBGBrush <> 0) Or (bReset = True) Then Call DeleteSliderBrush If hSliderBGBrush = 0 Then hSliderBGBrush = CreateSolidBrush(clrref) End Sub
Public Sub DeleteSliderBrush() If (hSliderBGBrush <> 0) Then DeleteObject hSliderBGBrush hSliderBGBrush = 0 End If End Sub
Public Function Slider_ActivateToolTips(hwndSlider As Long, bEnabled As Boolean) As Long Dim hToolTips As Long hToolTips = SendMessage(hwndSlider, TBM_GETTOOLTIPS, ByVal 0&, ByVal 0&) If hToolTips <> 0 Then Slider_ActivateToolTips = SendMessage(hToolTips, TTM_ACTIVATE, ByVal Abs(bEnabled), ByVal 0&) End If End Function
Public Sub SubClass(hWnd As Long) On Error Resume Next lFrmHwnd = hWnd defWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc) End Sub
Public Sub UnSubClass If defWindowProc > 0 Then SetWindowLong lFrmHwnd, GWL_WNDPROC, defWindowProc defWindowProc = 0 Erase hSliderHwnd End If End Sub
Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If hWnd = lFrmHwnd Then Select Case uMsg Case WM_CTLCOLORSTATIC If (IsOneSlide(lParam)) And (hSliderBGBrush <> 0) Then WindowProc = hSliderBGBrush Else WindowProc = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam) End If Case WM_DESTROY If (hSliderBGBrush <> 0) Then Call DeleteSliderBrush hSliderBGBrush = 0 End If Call UnSubClass(hWnd) Case Else WindowProc = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam) End Select Else WindowProc = CallWindowProc(defWindowProc, hWnd, uMsg, wParam, lParam) End If End Function
Private Function IsOneSlide(lParam As Long) As Boolean IsOneSlide = False Dim i As Integer For i = 0 To 9 If lParam = hSliderHwnd(i) Then IsOneSlide = True: Exit For Next i End Function
pense à valider la réponse ++ Prenez un instant pour répondre à ce sondage svp 
|
|
|
samedi 17 novembre 2007 à 23:21:24 |
Re : Couleur de fond d'un contrôle slider

PCPT
|
Réponse acceptée !
dans la windowproc (et peut-être ailleurs), remplacer Call UnSubClass(hWnd) par Call UnSubClass
|
|
|
dimanche 18 novembre 2007 à 00:25:35 |
Re : Couleur de fond d'un contrôle slider
|
Cette discussion est classé dans : long, function, hwnd, if, byval
Répondre à ce message
Sujets en rapport avec ce message
quelqun peut maider pour faire marcher ce code [ par wcwmans ]
ccest un code pour empecher que les fenetre contennat dans leur titre le mots sex ne souvre pas. Il est composé d'un timer d'une form et d'un module.m
EnumWindow... [ par Franck67 ]
Bonjour,J'aimerai pouvoir récupérer uniquement le Handle des fenêtres affichées sur le bureau de Windows pour pouvoir faire un traitement dessus !!!J'
Prob dans le listage des fentres actives [ par CCJ ]
Voila le code :Private Declare Function GetWindowTextLength Lib "USER32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As LongPrivate Declare Func
KillApp [ par TS1 ]
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongPrivate Declare Function GetWindowThreadProc
Ma form est elle visible ?? [ par pluplu ]
Bonjour, Voilà j'ai une application MDI et je désire détecter si une form particulière se trouve chargée ou visible et de mannière élégante (j'ai bien
Transparence [ par tbbuim1 ]
Salut à tous, Je souhaite rendre une couleur semi-transparente sur une de mes forms. Ca fait des heures et des heures que je cherche et je n'ai pas tr
transparence d'une fenêtre [ par bultez ]
Bonjour à toutes et à tous, je ne parviens pas à récupérer la transparence de la fenêtre en cours. ( la mettre, ça baigne, la relire non ) j'
Déplacement aléatoire d'une Form dans l'écran [ par gozzer ]
Bonjour,Je ne suis pas du tout aguerri en programmation sous VB mais j'ai déjà réussi à écrire quelques lignes qui me permettent d'afficher une Image
penProcess Lib "kernel32" [ par rzmitri ]
Bonjour,J'utilise ce bout que j'ai trouvé quelque part pour lancer des batch file sur plusieurs ordinateur en même temps:Private Declare Function Wait
GetWindowTextA [ par romainvv ]
Bonjour,Je finalise mon projet et je rencontre une difficulté. Mon application doit etre sensible au fenetre qui ont le focus.J'aimerais donc que le p
Livres en rapport
|
Téléchargements
Logiciels à télécharger sur le même thème :
|