Charger un curseur en data
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
Merci Dri, je vais voir si je vais pouvoir l'adapter à mon programme ...
Au fait, tu préfères Dri ou Dr Dri ?
Au fait, tu préfères Dri ou Dr Dri ?
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
Bon,peux tu regarder ce code et me dire mon erreur, car là, je commence à douter de mes capacités à comprendre !
Merci de me supporter dédé :p
Code : Tout sélectionner
; ToDo
; Nom du projet : MySplitter
; Version : 1.0.0
; Programmé par : Progi1984
; Date : 10/10/2006
; Purebasic : V4
Global MySplitter_ArrowCursorH
Global Splitter_Activate
Global SkinButton.l
Procedure IsMouseOver(hWnd)
Protected re.RECT
Protected pt.POINT
GetWindowRect_ (hWnd, re)
GetCursorPos_ (pt)
ProcedureReturn PtInRect_ (re, pt\x, pt\y)
EndProcedure
Procedure ResizeInterface(Window.l, Splitter.l, Gadget1.l, Gadget2.l)
Protected Delta.l
If WindowMouseX(Window) = -1
; hors de la fenetre
If DesktopMouseX() > WindowX(Window) + WindowWidth(Window)
; à droite de la fenetre
Delta = WindowWidth(Window)
ElseIf DesktopMouseX() < WindowX(Window)
; à gauche de la fenetre
Delta = - GadgetX(Splitter)
EndIf
Else
Delta = WindowMouseX(Window) - GadgetX(Splitter)
EndIf
If GadgetWidth(Gadget1) + Delta < 0
Delta = 0 - GadgetWidth(Gadget1)
EndIf
If GadgetWidth(Gadget2) - Delta < 0
Delta = GadgetWidth(Gadget2)
EndIf
ResizeGadget(Gadget1, #PB_Ignore, #PB_Ignore, GadgetWidth(Gadget1) + Delta, #PB_Ignore)
ResizeGadget(Splitter, GadgetX(Splitter) + Delta, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(Gadget2, GadgetX(Gadget2) + Delta, #PB_Ignore, GadgetWidth(Gadget2) - Delta, #PB_Ignore)
ProcedureReturn
EndProcedure
Procedure ButtonCallBack(WindowID, Message, wParam, lParam)
Protected point.POINT
Protected rect.RECT
GetCursorPos_(@point)
GetWindowRect_(WindowID, @rect)
OriginProc.l= GetProp_(WindowID, "OriginProc")
Select Message
Case #WM_MOUSEMOVE
If IsMouseOver(GadgetID(3))
SetCursor_(MySplitter_ArrowCursorH)
EndIf
If Splitter_Activate = #True
If point\x >= GadgetX(0)+WindowX(0)+GadgetWidth(3); droite
If point\x <= GadgetX(1)+WindowX(0)+GadgetWidth(1); gauche
SetWindowPos_(WindowID(1), 0,point\x-1,rect\top,3,rect\bottom-rect\top, #SWP_NOSIZE|#SWP_NOACTIVATE)
EndIf
EndIf
ProcedureReturn 0
EndIf
Case #WM_LBUTTONDOWN
If IsMouseOver(GadgetID(3))
Splitter_Activate = #True
OpenWindow(1, 0, 0, 0, 0, "SGBis", #PB_Window_BorderLess|#PB_Window_Invisible)
SetWindowLong_(WindowID(1), #GWL_EXSTYLE, GetWindowLong_(WindowID(1), #GWL_EXSTYLE)|#WS_EX_TOOLWINDOW)
hbruh = CreateSolidBrush_(RGB(128,128,128))
SetClassLong_(WindowID(1), #GCL_HBRBACKGROUND, hbruh)
InvalidateRect_(WindowID(1), 0, 1)
SetWindowPos_(WindowID(1), 0, point\x-1, rect\top,3, rect\bottom-rect\top, #SWP_SHOWWINDOW|#SWP_NOACTIVATE)
EndIf
Case #WM_DRAWITEM
*dis.DRAWITEMSTRUCT
*dis = lParam
If *dis\itemState & #ODS_CHECKED
FillRect_(*dis\hdc, *dis\rcItem, SkinButton)
ElseIf *dis\itemState & #ODS_SELECTED
FillRect_(*dis\hdc, *dis\rcItem, SkinButton)
Else
FillRect_(*dis\hdc, *dis\rcItem, SkinButton)
EndIf
Case #WM_LBUTTONUP;514 ; relaché
If Splitter_Activate = #True
Splitter_Activate = #False
ResizeInterface(0, 3, 0, 1)
DestroyWindow_(WindowID(1))
DeleteObject_(hbruh)
SendMessage_(WindowID, #WM_MOUSEMOVE,a,b)
EndIf
EndSelect
ProcedureReturn CallWindowProc_(OriginProc,WindowID,Message,wParam,lParam)
EndProcedure
Procedure MySplitterGadget(Gadget, X, Y, Width, Height)
ButtonGadget(Gadget, X, Y, Width, Height,"");, #BS_OWNERDRAW)
MySplitter_ArrowCursorH = CatchImage(#PB_Any, ?deb)
;MySplitter_ArrowCursorH = LoadCursorFromFile_(@"SPLITH.CUR")
CreateImage(0,Width,Height)
StartDrawing(ImageOutput(0))
Box(0,0,Width ,Height , GetSysColor_(#COLOR_3DSHADOW))
Box(0,0,Width-2,Height-2, GetSysColor_(#COLOR_3DHILIGHT))
Box(2,2,Width-4,Height-4, GetSysColor_(#COLOR_3DFACE))
StopDrawing()
SkinButton = CreatePatternBrush_(ImageID(0))
OriginProc = SetWindowLong_(GadgetID(Gadget), #GWL_WNDPROC, @ButtonCallBack())
SetProp_(GadgetID(Gadget), "OriginProc", OriginProc)
ProcedureReturn
EndProcedure
OpenWindow(0,200,200,240,190,"SplitterGadget Example",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ListViewGadget(0, 005, 005, 110, 180)
ListViewGadget(1, 125, 005, 110, 180)
MySplitterGadget(3, 116, 010, 008, 170)
For k=0 To 10
AddGadgetItem(0, -1, "0 - " + Str(k))
AddGadgetItem(1, -1, "1 - " + Str(k))
Next
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
DataSection
deb:
IncludeBinary "SPLITH.CUR"
fin:
EndDataSection
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
Utilise les ressources : tu créé une ressource curseur que tu nommes par exemple "cur1", et ensuite c'est un jeu d'enfant :
Code : Tout sélectionner
MySplitter_ArrowCursorH = LoadCursor_(GetModuleHandle_(#Null),"cur1")
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
>Erix14 :
Oki, je vais tester ca.
>Dédé :
Mais mercià Dédé de reager.
Oki, je vais tester ca.
>Dédé :
Mais mercià Dédé de reager.
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
@Erix14 : bon, j'ai pas réussi, mais quel est la différence avec un IncludeBinary ?
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
Je l'ai fait en quelques secondes avec le code de ton programme, ton problème vient peut-être du fait que tu n'as pas su déclarer correctement ta ressource curseur. L'API LoadCursor permet de charger un curseur depuis les ressources. Je ne reviendrai pas sur l'utilité d'utiliser les ressources il y a déjà eu un poste là-dessus, c'est la méthode la mieux adapté, tous les programmeurs l'utilisent. De même que personne n'utilise une "Windows" pour afficher le Splitter en mouvement :Dans ton fichier de ressource *.rc tu dois avoir en gros cela :
Avec jaPBe c'est très facile de déclarer une ressource...
Code : Tout sélectionner
Global MySplitter_ArrowCursorH
Global Splitter_Activate
Global SkinButton.l
Global SplitterX = -1
CreateImage(0, 4, 2)
StartDrawing(ImageOutput(0))
For t=0 To 3 Step 2
Plot(t, 0, $FFFFFF)
Plot(t+1, 1, $FFFFFF)
Next
StopDrawing()
SkinButton = CreatePatternBrush_(ImageID(0))
Procedure ResizeInterface(Window.l, Splitter.l, Gadget1.l, Gadget2.l)
Protected Delta.l
If WindowMouseX(Window) = -1
; hors de la fenetre
If DesktopMouseX() > WindowX(Window) + WindowWidth(Window)
; à droite de la fenetre
Delta = WindowWidth(Window)
ElseIf DesktopMouseX() < WindowX(Window)
; à gauche de la fenetre
Delta = - GadgetX(Splitter)
EndIf
Else
Delta = WindowMouseX(Window) - GadgetX(Splitter)
EndIf
If GadgetWidth(Gadget1) + Delta < 0
Delta = 0 - GadgetWidth(Gadget1)
EndIf
If GadgetWidth(Gadget2) - Delta < 0
Delta = GadgetWidth(Gadget2)
EndIf
ResizeGadget(Gadget1, #PB_Ignore, #PB_Ignore, GadgetWidth(Gadget1) + Delta, #PB_Ignore)
ResizeGadget(Splitter, GadgetX(Splitter) + Delta, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(Gadget2, GadgetX(Gadget2) + Delta, #PB_Ignore, GadgetWidth(Gadget2) - Delta, #PB_Ignore)
ProcedureReturn
EndProcedure
Procedure ButtonCallBack(WindowID, message, wParam, lParam)
Protected point.POINT
Protected rect.RECT,rectS.RECT
GetCursorPos_(@point)
GetWindowRect_(WindowID(0), @rect)
GetClientRect_(WindowID, @rectS)
OriginProc.l= GetProp_(WindowID, "OriginProc")
Select message
Case #WM_MOUSEMOVE
SetCursor_(MySplitter_ArrowCursorH)
If Splitter_Activate = #True
If GetCapture_() <> WindowID
SetCapture_(WindowID)
EndIf
If point\x >= GadgetX(0)+WindowX(0)+GadgetWidth(3); droite
If point\x <= GadgetX(1)+WindowX(0)+GadgetWidth(1); gauche
hdc = GetDC_(WindowID(0))
SelectObject_(hdc, SkinButton)
xPos = point\x - rect\left - 4
If xPos < 0
xPos = 0
EndIf
If xPos > rect\right
xPos = rect\right
EndIf
If SplitterX <> xPos
If SplitterX>=0
PatBlt_(hdc, SplitterX, 10, 4, rectS\bottom, #PATINVERT)
EndIf
SplitterX = xPos
PatBlt_(hdc, xPos, 10, 4, rectS\bottom, #PATINVERT)
EndIf
ReleaseDC_(WindowID(0), hdc)
EndIf
EndIf
ProcedureReturn 0
EndIf
Case #WM_LBUTTONDOWN
Splitter_Activate = #True
hdc = GetDC_(WindowID(0))
xPos = point\x - rect\left - 4
SplitterX = xPos
SelectObject_(hdc, SkinButton)
PatBlt_(hdc, SplitterX, 10, 4, rectS\bottom, #PATINVERT)
ReleaseDC_(WindowID(0), hdc)
SetCursor_(MySplitter_ArrowCursorH)
ProcedureReturn
Case #WM_LBUTTONUP;514 ; relaché
If Splitter_Activate = #True
Splitter_Activate = #False
GetWindowRect_(WindowID,@rect.RECT)
hdc = GetDC_(WindowID(0))
SelectObject_(hdc, SkinButton)
PatBlt_(hdc, SplitterX, 10, 4, rectS\bottom, #PATINVERT)
ReleaseDC_(WindowID(0), hdc)
ResizeInterface(0, 3, 0, 1)
ReleaseCapture_()
EndIf
EndSelect
ProcedureReturn CallWindowProc_(OriginProc,WindowID,message,wParam,lParam)
EndProcedure
Procedure MySplitterGadget(Gadget, x, y, Width, Height)
ButtonGadget(Gadget, x, y, Width, Height,"");, #BS_OWNERDRAW)
MySplitter_ArrowCursorH = LoadCursor_(GetModuleHandle_(#Null),"cur1")
;MySplitter_ArrowCursorH = LoadCursorFromFile_("SPLITH.CUR")
OriginProc = SetWindowLong_(GadgetID(Gadget), #GWL_WNDPROC, @ButtonCallBack())
SetProp_(GadgetID(Gadget), "OriginProc", OriginProc)
ProcedureReturn
EndProcedure
OpenWindow(0,200,200,240,190,"SplitterGadget Example",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
ListViewGadget(0, 005, 005, 110, 180)
ListViewGadget(1, 125, 005, 110, 180)
MySplitterGadget(3, 116, 010, 008, 170)
For k=0 To 10
AddGadgetItem(0, -1, "0 - " + Str(k))
AddGadgetItem(1, -1, "1 - " + Str(k))
Next
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
Code : Tout sélectionner
cur1 CURSOR "chemin de ton curseur : SPLITH.CUR"
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
Merci beaucoup Erix de ton travail ( et pas que pour ce code) ca m'aide beaucoup !
Le code fonctionne c'est parfait
Le code fonctionne c'est parfait

Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net
- Progi1984
- Messages : 2659
- Inscription : mar. 14/déc./2004 13:56
- Localisation : France > Rennes
- Contact :
Et que je ne m'en plaignais pas :p
Librairies & Applications : https://www.purebasic.fr/french/viewtop ... f=8&t=6220
Site Web : https://rootslabs.net
Site Web : https://rootslabs.net