Publié : jeu. 12/oct./2006 12:03
cette version sauve en prenant compte de la resolution
c'est tout bete, mais utile, cela permet d'avoir un fichier de reference de la position des icones different si l'on est en 800x600 ou 1024x768
cela permet d'avoir une disposition d'icone personalisé en fonction de la résolution
c'est tout bete, mais utile, cela permet d'avoir un fichier de reference de la position des icones different si l'on est en 800x600 ou 1024x768
cela permet d'avoir une disposition d'icone personalisé en fonction de la résolution

; PureBasic 4.0
; Enregistre et Restaure la position des icônes sur le bureau
Macro Listview_GetItemCount(hwnd)
SendMessage_ (hwnd, #LVM_GETITEMCOUNT , #Null , #Null )
EndMacro
Macro Listview_SetItemPosition(hwnd, item, x, Y)
SendMessage_ (hwnd, #LVM_SETITEMPOSITION , item, ((Y)<<16|(x)))
EndMacro
Macro Listview_GetItemPosition(hwnd, iItem, pPoint)
SendMessage_ (hwnd, #LVM_GETITEMPOSITION , iItem, pPoint)
EndMacro
Declare.l IsWindowsNT()
Declare.l GetDesktopHandle()
Declare.l LoadDesktop(FileName.s)
Declare.l SaveDesktop(FileName.s)
Enumeration
#fenetre
#restore
#sauve
#text
EndEnumeration
OpenWindow ( #fenetre ,10,10,220,90, "pos_icone" , #PB_Window_SystemMenu )
Font1 = LoadFont ( #PB_Any , "Comic Sans MS" , 9, #PB_Font_Bold )
SetWindowColor ( #fenetre , RGB ($70,$89,$F1))
If CreateGadgetList ( WindowID (0))
TextGadget ( #text , 20,5,190, 20, "POS ICONES RECOVERER" , #PB_Text_Center )
SetGadgetFont ( #text , FontID (Font1))
SetGadgetColor ( #text , #PB_Gadget_BackColor , RGB ($70,$89,$F1))
ButtonGadget ( #restore , 10, 30, 200, 20, "Restore la position des icones du bureau" )
ButtonGadget ( #sauve , 10, 60, 200, 20, "Sauve la position des icones du bureau" )
EndIf
Repeat
ExamineDesktops ()
Event= WaitWindowEvent ()
Select Event
Case #PB_Event_Gadget
Select EventGadget ()
Case #restore : Debug "restore"
CallDebugger
nom$= Str ( DesktopWidth (0))+ "x" + Str ( DesktopHeight (0))+ "mon_bureau.ini"
If FileSize (nom$) <>-1
LoadDesktop(nom$)
Else ; le fichier de sauvegarde n'existe pas
nom$= Str ( DesktopWidth (0))+ "x" + Str ( DesktopHeight (0))+ "mon_bureau.ini"
SaveDesktop(nom$) ; alors on le creer !
EndIf
Case #sauve : Debug "sauve"
Resultat= MessageRequester ( "attention" , "vous voulez vraiment sauver la position des icones ?" , #PB_MessageRequester_YesNo )
EndSelect
If Resultat = 6 ; le bouton Oui a été choisi (Resultat = 6)
nom$= Str ( DesktopWidth (0))+ "x" + Str ( DesktopHeight (0))+ "mon_bureau.ini"
SaveDesktop(nom$)
Else ; le bouton Non a été choisi (Resultat = 7)
EndIf
Case #PB_Event_Menu
EndSelect
Until Event = #PB_Event_CloseWindow
Procedure.l IsWindowsNT()
Protected OS.OSVERSIONINFO\dwOSVersionInfoSize = SizeOf (OSVERSIONINFO)
If GetVersionEx_ (OS) And OS\dwPlatformId = 2
ProcedureReturn #True
EndIf
EndProcedure
Procedure.l GetDesktopHandle()
Protected hwnd.l = FindWindow_ ( "Progman" , 0)
hwnd = FindWindowEx_ (hwnd, 0, "SHELLDLL_defVIEW" , 0)
ProcedureReturn FindWindowEx_ (hwnd, 0, "SysListView32" , 0)
EndProcedure
Procedure.l LoadDesktop(FileName.s) ; Restaure la position des icônes du bureau depuis un fichier .INI
Protected hwnd.l, nItem.l, i.l
hwnd = GetDesktopHandle()
If hwnd
If OpenPreferences (FileName)
nItem = Listview_GetItemCount(hwnd)
For i = 0 To nItem - 1
If PreferenceGroup ( "ID." + Str (i))
Listview_SetItemPosition(hwnd, i, ReadPreferenceLong ( "x" , 0), ReadPreferenceLong ( "y" , 0))
EndIf
Next i
ClosePreferences ()
EndIf
EndIf
ProcedureReturn nItem
EndProcedure
Procedure.l SaveDesktop(FileName.s) ; Enregistre la position des icônes du bureau dans un fichier .INI
Protected hwnd.l, pid.l, nItem.l, i.l, hProcess.l, hBuffer.l, written.l, p.POINT
hwnd = GetDesktopHandle()
If hwnd
If IsWindowsNT()
GetWindowThreadProcessId_ (hwnd, @pid)
hProcess = OpenProcess_ ( #PROCESS_VM_OPERATION | #PROCESS_VM_READ , 0, pid)
If hProcess
hBuffer = VirtualAllocEx_ (hProcess, 0, SizeOf (POINT), #MEM_RESERVE | #MEM_COMMIT , #PAGE_READWRITE )
If hBuffer
WriteProcessMemory_ (hProcess, hBuffer, @p, SizeOf (POINT), @written)
If CreatePreferences (FileName)
nItem = Listview_GetItemCount(hwnd)
For i = 0 To nItem - 1
If Listview_GetItemPosition(hwnd, i, hBuffer)
If ReadProcessMemory_ (hProcess, hBuffer, @p, SizeOf (POINT), @written)
PreferenceGroup ( "ID." + Str (i))
WritePreferenceLong ( "x" , p\x)
WritePreferenceLong ( "y" , p\Y)
Debug Str (p\x) + ", " + Str (p\Y)
EndIf
EndIf
Next i
ClosePreferences ()
EndIf
VirtualFreeEx_ (hProcess, hBuffer, SizeOf (POINT), #MEM_RELEASE )
EndIf
CloseHandle_ (hProcess)
EndIf
EndIf
EndIf
ProcedureReturn nItem
EndProcedure
;SaveDesktop("mon_bureau.ini")
;LoadDesktop("mon_bureau.ini")