frk25
Messages postés13Date d'inscriptionsamedi 24 mai 2003StatutMembreDernière intervention31 mai 2005
-
29 juin 2004 à 14:46
ShareVB
Messages postés2676Date d'inscriptionvendredi 28 juin 2002StatutMembreDernière intervention13 janvier 2016
-
29 juin 2004 à 21:37
Bonjour à tous,
J'aimerais savoir si c'est possible de mettre un image aligner à gauche ou à droite d'un boutton de commande. Et si oui comment faire?
ShareVB
Messages postés2676Date d'inscriptionvendredi 28 juin 2002StatutMembreDernière intervention13 janvier 201626 29 juin 2004 à 19:30
salut
pour cela il faut utiliser les apis :
getwindowlong pour obtenir le style actuel
setwindowlong pour ajout un autre style
invalidaterect pour mettre à jour le style
Private Const BS_BOTTOM As Long = &H800&
Private Const BS_LEFT As Long = &H100&
Private Const BS_RIGHT As Long = &H200&
Private Const BS_TOP As Long = &H400&
Private Const BS_CENTER As Long = &H300&
Private Const BS_VCENTER As Long = &HC00&
Private Const BS_LEFTTEXT As Long = &H20&
Private Const BS_RIGHTBUTTON As Long = BS_LEFTTEXT
'ajout perso
Private Const BS_NOALIGN As Long = Not (BS_BOTTOM + BS_CENTER + BS_LEFT + BS_LEFTTEXT + BS_RIGHT + BS_RIGHTBUTTON + BS_TOP + BS_VCENTER)
Private Const GWL_STYLE As Long = -16
Private Const GWL_EXSTYLE As Long = -20
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
Private Sub Command1_Click()
Dim ret As Long
ret = GetWindowLong(Command1.hwnd, GWL_STYLE)
ret = SetWindowLong(Command1.hwnd, GWL_STYLE, (ret And BS_NOALIGN) Or BS_TOP Or BS_RIGHT)
InvalidateRect Command1.hwnd, 0&, 0&
End Sub
frk25
Messages postés13Date d'inscriptionsamedi 24 mai 2003StatutMembreDernière intervention31 mai 2005 29 juin 2004 à 20:10
Salut
J'avais trouver c'est commandes, mais il reste un petit problème, parce que la commande peut ajuster le style seulement pour le texte du boutton. Si l'on change la propriété Style du boutton pour le mettre à « Graphical» et qu'on ajoute une image, les fonctions API ne fonctionne plus, le texte ainsi que l'image reste toujours au même endroit.
ShareVB
Messages postés2676Date d'inscriptionvendredi 28 juin 2002StatutMembreDernière intervention13 janvier 201626 29 juin 2004 à 21:37
salut
en essayant ca :
Private Const IMAGE_BITMAP As Long = 0
Private Const BM_SETIMAGE As Long = &HF7
Private Const BS_BITMAP As Long = &H80
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Command1_Click()
Dim ret As Long
ret = GetWindowLong(Command1.hwnd, GWL_STYLE)
ret = SetWindowLong(Command1.hwnd, GWL_STYLE, (ret And BS_NOALIGN) Or BS_TOP Or BS_RIGHT Or BS_BITMAP)
on s'apercois que soit on a du texte soit on a une image (au quel cas on peut définir l'alignement)
ou alors on met le style BS_OWNERDRAW et la c VB qui fait le dessin texte et image mais pas choix de l'alignement...