que vous pouvez telecharger ici : www.serveurperso.com/~cederavic/OwnControl.dllHDC GetOwnControlhDC(lparam);
UINT GetOwnControlCtlType(lparam);
UINT GetOwnControlCtlID(lparam);
UINT GetOwnControlitemID(lparam);
UINT GetOwnControlitemAction(lparam);
UINT GetOwnControlitemState(lparam);
HWND GetOwnControlhwndItem(lparam);
RECT GetOwnControlrcItem(lparam);
DWORD GetOwnControlitemData(lparam);
et voilas le code d'example :
Code : Tout sélectionner
Declare wincb(hWnd, uMsg, wParam, lParam)
Global buttonevent : buttonevent = -1; pour savoir si le bouton a ete cliquer
hb = CreateSolidBrush_(RGB(170, 150, 255))
hb2 = CreateSolidBrush_(RGB(200, 180, 255))
fnt = CreateFont_(10, 10, 0, 0, 900, #false, #false, #false, #ANSI_CHARSET, #OUT_DEFAULT_PRECIS, #CLIP_DEFAULT_PRECIS , #DEFAULT_QUALITY , #DEFAULT_PITCH, "Courier")
hwnd = OpenWindow(0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "MFC Custom Control")
SetWindowCallback(@wincb())
CreateGadgetList(hwnd)
ButtonGadget(0, 10, 10, 100, 50, "Button", #BS_OWNERDRAW) ; bs_ownerdraw dit a windows que c'est nous qui dessinon le bouton
OpenLibrary(0, "OwnControl.dll")
Repeat
wevent = WindowEvent()
Select buttonevent
Case #BN_CLICKED ; simple click
Debug "Le bouton à été cliqué"
buttonevent = -1
Default
buttonevent = -1
EndSelect
Until wevent = #WM_Close
Procedure wincb(hWnd, uMsg, wParam, lParam)
Static hb, hb2, fnt
Select uMsg
Case #WM_DRAWITEM
hb = CreateSolidBrush_(RGB(170, 150, 255)) ; creer le brush 1
hb2 = CreateSolidBrush_(RGB(200, 180, 255)) ; creer le brush 2
fnt = CreateFont_(10, 10, 0, 0, 900, #false, #false, #false, #ANSI_CHARSET, #OUT_DEFAULT_PRECIS, #CLIP_DEFAULT_PRECIS , #DEFAULT_QUALITY , #DEFAULT_PITCH, "Courier") ; creer la font
hdc = CallCFunction(0, "GetOwnControlhDC", lParam) ; recupere le dc
rect.RECT : rect\left = 0 : rect\Top = 0 : rect\right = 100 : rect\bottom = 50
stat = CallCFunction(0, "GetOwnControlitemState", lParam) ; recupere l'etat
If stat = 17
SelectObject_(hdc, hb)
SetBkMode_(hdc, #TRANSPARENT)
RoundRect_(hdc, 0, 0, 100, 50, 40, 40)
Else
SelectObject_(hdc, hb2)
SetBkMode_(hdc, #TRANSPARENT)
RoundRect_(hdc, 0, 0, 100, 50, 40, 40)
EndIf
SelectObject_(hdc, fnt)
SetBkMode_(hdc, #TRANSPARENT)
DrawText_(hdc, GetGadgetText(0), Len(GetGadgetText(0)), @rect, #DT_CENTER | #DT_VCENTER)
DeleteObject_(hb)
DeleteObject_(hb2)
DeleteObject_(fnt)
Case #WM_COMMAND
Select wParam
Case #BN_CLICKED ; simple click
buttonevent = #BN_CLICKED
EndSelect
EndSelect
ProcedureReturn DefWindowProc_(hWnd, uMsg, wParam, lParam)
EndProcedure
