tchalf
Messages postés7Date d'inscriptionmardi 21 décembre 2004StatutMembreDernière intervention28 juillet 2014
-
28 juil. 2014 à 14:26
Whismeril
Messages postés18992Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention29 mars 2024
-
28 juil. 2014 à 15:21
Bien le bonjour,
J'ai un problème qui m'insupporte légèrement ! En voici l'origine :
A partir de cette fonction :
Public Sub DrawBTN(ByVal hwnd As Long, ByVal Selected As Boolean) Dim ClientCoord As RECT Dim TextCoord As RECT Dim LB As LOGBRUSH Dim Mytxt As String Dim FondColor As Long Dim TexteColor As Long Dim TexteHeight As Long Dim idxFinal As Long ' Rechercher les critères de la case idxFinal = onCat(hwnd) If idxFinal = Data_Default Then FondColor = IIf(Selected, vbGreen, vbBlack) TexteColor = vbYellow Else FondColor = IIf(Selected, vbBlue, vbWhite) TexteColor = vbRed End If ' Mettre en forme TheDC = GetDC(hwnd) Call GetClientRect(hwnd, ClientCoord) ' Lecture du texte Mytxt = getText(hwnd) ' Lecture de la taille du texte TextCoord = ClientCoord TexteHeight = DrawText(TheDC, Mytxt, Len(Mytxt), TextCoord, DT_CENTER Or DT_CALCRECT Or DT_WORDBREAK) ' Colorier le bouton LB.lbColor = FondColor hBrush = CreateBrushIndirect(LB) Call SetBkColor(TheDC, LB.lbColor) Call FillRect(TheDC, ClientCoord, hBrush) Call DrawEdge(TheDC, ClientCoord, EDGE_RAISED, BF_RECT) Call SetTextColor(TheDC, TexteColor) ' Nouvelle position du texte With ClientCoord .Top = .Bottom / 2 - TextCoord.Bottom / 2 End With ' Redessiner le texte Call DrawText(TheDC, Mytxt, Data_Default, ClientCoord, DT_CENTER Or DT_WORDBREAK)
Call DeleteObject(hBrush) Call RedrawWindow(hwnd, ClientCoord, 0&, RDW_VALIDATE) Call ReleaseDC(hwnd, TheDC) End Sub
Mais j'obtiens seulement en partie ce que je lui demande ! Je précise que je suis en subclassing.
En effet, lors du démarrage (appel WM_PAINT), le bouton créé par API CreateWindowEx n'est coloré que de moitié.
Mais lorsque je clique sur un bouton, donc appel direct (WM_LBUTTONCLK) de cette fonction, la case s'affiche maintenant correctement, comme le montre cette image.
Quelqu'un aurait-il une explication bienveillante à me fournir, avant que je ne perde mes cheveux prématurément ?