Laddy Posted November 17, 2010 Share Posted November 17, 2010 (edited) Hello, sorry for my english i speak a little bit. I want to disable right click outside listview, outside of the selected row, but it does not work Why? I can not find my mistake Can you help me please ? Thank a lot Laddy expandcollapse popup#include <GUIConstantsEx.au3> ; pour la gui #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <StructureConstants.au3> Opt("GUIDataSeparatorChar",@LF) $Gui = GUICreate(" Un clic", 700, 360) ;h360 w326 $BouttonLister = GUICtrlCreateButton("Lister", 6, 145, 100, 25) $ListePoint = GUICtrlCreateList("", 6, 190, 660, 160) ;310 GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $RPList ; On définie une variable vide Func WMIDateStringToDate($dtmInstallDate) Return (StringMid($dtmInstallDate, 5, 2) & "/" & _ StringMid($dtmInstallDate, 7, 2) & "/" & StringLeft($dtmInstallDate, 4) _ & " " & StringMid ($dtmInstallDate, 9, 2) & ":" & _ StringMid($dtmInstallDate, 11, 2) & ":" & StringMid($dtmInstallDate, _ 13, 2)) EndFunc Do GUISetState() $Msg = GUIGetMsg() Switch $Msg Case $BouttonLister GUICtrlSetData($ListePoint, "Wait, please...") $i = 0 $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") $objWMI = ObjGet("winmgmts:\\localhost\root\default") $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") If $colItems.Count = 0 Then MsgBox(0, "No Point", "No restore point in system.") Else $i = $colItems.Count ;For Each $objItem In $colItems If IsObj($colItems) Then For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate ;$RPList &= "[" & WMIDateStringToDate($objItem.CreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @CRLF $RPList &= "[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF EndIf $i = $i - 1 Next EndIf EndIf GUICtrlSetData($ListePoint, "") GUICtrlSetData($ListePoint, $RPList) $List1context = GUICtrlCreateContextMenu($ListePoint) $MenuItem1 = GUICtrlCreateMenuItem("Action", $List1context) $RPLIST = "" ; vide la variable EndSwitch Until $Msg = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWnd_ListView, $tNMHDR, $hWndFrom, $iCode $hWnd_ListView = $ListePoint If Not IsHWnd($hWnd_ListView) Then $hWnd_ListView = GUICtrlGetHandle($ListePoint) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWnd_ListView Switch $iCode Case $NM_RCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iItem = DllStructGetData($tInfo, $RPList) If $iItem = -1 Then GUICtrlSetState($MenuItem1, $GUI_DISABLE) Else GUICtrlSetState($MenuItem1, $GUI_ENABLE) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Edited November 20, 2010 by Laddy Link to comment Share on other sites More sharing options...
Laddy Posted November 18, 2010 Author Share Posted November 18, 2010 (edited) Hi Nobody would have an idea of my problem? Thx Laddy Edited November 18, 2010 by Laddy Link to comment Share on other sites More sharing options...
Tvern Posted November 18, 2010 Share Posted November 18, 2010 Your example is using a GuictrlCreateList, not GuiCtrlCreateListView. Because you set all the rows of data in the list control at once you don't have individual controlID's for the items, so you can't to my knowledge specify seperate GUICtrlCreateContextMenu's for them. You may need to use GuiCtrlCreateListView, or _GUICtrlListBox_Create to get individual context menu's per item. Link to comment Share on other sites More sharing options...
Laddy Posted November 18, 2010 Author Share Posted November 18, 2010 Oh my god I struggled to my code, change will be difficult I hope to get there Thank you for your answer Link to comment Share on other sites More sharing options...
Laddy Posted November 20, 2010 Author Share Posted November 20, 2010 I used GUICtrlCreateListView but it still does not work why? where is my mistake? expandcollapse popup#include <GUIConstantsEx.au3> ; pour la gui #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #Include <GuiListView.au3> #include <StructureConstants.au3> Opt("GUIDataSeparatorChar",@LF) $Gui = GUICreate(" Un clic", 700, 360) ;h360 w326 $BouttonLister = GUICtrlCreateButton("Lister", 6, 145, 100, 25) $ListePoint = GUICtrlCreateListView("", 6, 190, 660, 160) ;310 _GUICtrlListView_AddColumn($ListePoint, "Restore Point",700) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $RPList ; On définie une variable vide Func WMIDateStringToDate($dtmInstallDate) Return (StringMid($dtmInstallDate, 5, 2) & "/" & _ StringMid($dtmInstallDate, 7, 2) & "/" & StringLeft($dtmInstallDate, 4) _ & " " & StringMid ($dtmInstallDate, 9, 2) & ":" & _ StringMid($dtmInstallDate, 11, 2) & ":" & StringMid($dtmInstallDate, _ 13, 2)) EndFunc Do GUISetState() $Msg = GUIGetMsg() Switch $Msg Case $BouttonLister Lister() ;$RPLIST = "" ; vide la variable EndSwitch Until $Msg = $GUI_EVENT_CLOSE Func Lister() ;GUICtrlSetData($ListePoint, "Wait, please...") $i = 0 $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") $objWMI = ObjGet("winmgmts:\\localhost\root\default") $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") If $colItems.Count = 0 Then MsgBox(0, "No Point", "No restore point in system.") Else $i = $colItems.Count If IsObj($colItems) Then For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate ;$RPList &= "[" & WMIDateStringToDate($objItem.CreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @CRLF ;$RPList &= "[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF GUICtrlCreateListViewItem("[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF, $ListePoint) EndIf $i = $i - 1 Next EndIf EndIf GUICtrlSetData($ListePoint, "") GUICtrlSetData($ListePoint, $RPList) $List1context = GUICtrlCreateContextMenu($ListePoint) $MenuItem1 = GUICtrlCreateMenuItem("Action", $List1context) EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $hWnd_ListView, $tNMHDR, $hWndFrom, $iCode $hWnd_ListView = $ListePoint If Not IsHWnd($hWnd_ListView) Then $hWnd_ListView = GUICtrlGetHandle($ListePoint) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWnd_ListView Switch $iCode Case $NM_RCLICK Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iItem = DllStructGetData($tInfo, "Restore Point") If $iItem = -1 Then GUICtrlSetState($MenuItem1, $GUI_DISABLE) Else GUICtrlSetState($MenuItem1, $GUI_ENABLE) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Can you help me ? Link to comment Share on other sites More sharing options...
Tvern Posted November 20, 2010 Share Posted November 20, 2010 Hmm I was expecting two things to be different: 1. I hoped it would be possible to make a Context menu for each item in the listview. Instead it seems to be created for the Listview itsself. 2. I thought capturing the right click would avoid the selection changing. Instead it seems to change before the right click is handled. I've made something that should come close to what you want to do, but I'm really not very proud of it. Hopefully someone will come in with a better idea. I did make a few extra suggested changes to the script that you can consider. expandcollapse popup#include <GUIConstantsEx.au3> ; pour la gui #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <GuiListView.au3> #include <StructureConstants.au3> Opt("GUIDataSeparatorChar", @LF) Global $Ctrl_LV_Selected Global $Gui = GUICreate(" Un clic", 700, 360) ;h360 w326 Global $BouttonLister = GUICtrlCreateButton("Lister", 6, 145, 100, 25) Global $ListePoint = GUICtrlCreateListView("", 6, 190, 660, 160) ;310 Global $List1context = GUICtrlCreateContextMenu($ListePoint) Global $MenuItem1 = GUICtrlCreateMenuItem("Action", $List1context) Global $hWnd_ListView = GUICtrlGetHandle($ListePoint) ;It's usually a bad idea to mix internal Autoit controls with UDF functions, but I don't seean easy workaround atm. _GUICtrlListView_AddColumn($hWnd_ListView, "Restore Point", 700) GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $RPList ; On définie une variable vide Func WMIDateStringToDate($dtmInstallDate) Return StringRegExpReplace($dtmInstallDate,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})","$2/$3/$1 $4:$5:$6") ;should be a bit faster and cleaner EndFunc Do GUISetState() $Msg = GUIGetMsg() Switch $Msg Case $BouttonLister Lister() EndSwitch Until $Msg = $GUI_EVENT_CLOSE Func Lister() Local $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") Local $objWMI = ObjGet("winmgmts:\\localhost\root\default") Local $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") If Not IsObj($colItems) Or $colItems.Count = 0 Then ;You had IsObj, after $colItems.Count, making it useless (the script would have crashed before it got to IsObj) MsgBox(0, "No Point", "No restore point in system.") Return SetError(1,0,0) EndIf Local $i = $colItems.Count For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate GUICtrlCreateListViewItem("[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF, $ListePoint) EndIf $i = $i - 1 Next EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWnd_ListView Switch $iCode Case $LVN_FIRST ;this seems to be fired consistently before an item change, so it seems usefull to update the selected item when it fires. $Ctrl_LV_Selected = _GUICtrlListView_GetSelectedIndices($hWnd_ListView) Case $NM_RCLICK $aHit = _GUICtrlListView_HitTest($hWnd_ListView) If $Ctrl_LV_Selected == "" Or $Ctrl_LV_Selected <> $aHit[0] Then ;You could set the selection back to the original item at this point, but preventing it from being selected would be much nicer. (Not sure how to do that) ;_GUICtrlListView_ClickItem($hWnd_ListView,$Ctrl_LV_Selected) ;return the selection to the originally selected item. Return 1 ;prevents the right click from being processed further EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 20, 2010 Moderators Share Posted November 20, 2010 Laddy, My take on the problem (and I did not look at Tvern's solution until afterwards ). The checkbox lets you adjust the behaviour of the ListView on a right click on a non-selected item. - If the box is checked: the selection moves and you need a second right click to show the context menu. - If the box is not checked: the selection to the previously selected row In both cases, right clicking on the selected item brings up the context menu. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiListView.au3> Global $iLeftSelected $hGUI = GUICreate("Test", 300, 400) ; Create ListView $hListView = GUICtrlCreateListView("Col 1|Col 2|Col 3|Col 4", 10, 10, 280, 350, BitOR($LVS_REPORT, $LVS_SINGLESEL, $WS_BORDER), $LVS_EX_FULLROWSELECT) $hListView_Handle = GUICtrlGetHandle(-1) _GUICtrlListView_SetColumnWidth($hListView, 0, 60) _GUICtrlListView_SetColumnWidth($hListView, 1, 60) _GUICtrlListView_SetColumnWidth($hListView, 2, 110) _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER ) For $k = 1 To 4 GUICtrlCreateListViewItem( "Item" & $k & "|Sub " & Chr(64 + $k) & "|Sub " & Chr(77 + $k), $hListView) Next $hCheck = GUICtrlCreateCheckbox(" Allow selection on Right click", 10, 370, 280, 20) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") Global $mContext = GUICtrlCreateContextMenu($hListView) Global $mContextItem = GUICtrlCreateMenuItem("Action", $mContext) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") ; Check if a ListView has sent the message If $hListView_Handle = $hWndFrom Then Switch $iCode Case $NM_CLICK ; Save left clicked item $iLeftSelected = GUICtrlRead($hListView) Case $NM_RCLICK ; Get clicked item info $iRightSelected = GUICtrlRead($hListView) ; Is it the selected item? If $iRightSelected <> $iLeftSelected Then Switch GUICtrlRead($hCheck) Case 1 ; Set item as selected $iLeftSelected = GUICtrlRead($hListView) Case Else ; Reset previous selection GUICtrlSetState($iLeftSelected, $GUI_FOCUS) EndSwitch ; No further action on right click Return 1 EndIf EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc Like Tvern I am surprised we cannot prevent the selection switch when right clicking. No doubt there is a way, but it is not immediately obvious. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tvern Posted November 20, 2010 Share Posted November 20, 2010 (edited) Strange isn't it? I thought of another way to do it that seems to do what to OP wants, but still uses methods I wish I could avoid. Basically I use _IsPressed to avoid any message from being handled untill the right mouse button is released, at which point $NM_RCLCICK is handled. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <GuiListView.au3> #include <StructureConstants.au3> #include <Misc.au3> Opt("GUIDataSeparatorChar", @LF) Global $User32Dll = DllOpen("user32.dll") Global $Gui = GUICreate(" Un clic", 700, 360) Global $BouttonLister = GUICtrlCreateButton("Lister", 6, 145, 100, 25) Global $ListePoint = GUICtrlCreateListView("", 6, 190, 660, 160) Global $List1context = GUICtrlCreateContextMenu($ListePoint) Global $MenuItem1 = GUICtrlCreateMenuItem("Action", $List1context) Global $hWnd_ListView = GUICtrlGetHandle($ListePoint) _GUICtrlListView_AddColumn($hWnd_ListView, "Restore Point", 700) GUICtrlSetLimit(-1, 200) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case 0 ContinueLoop Case $GUI_EVENT_CLOSE Exit Case $BouttonLister Lister() EndSwitch WEnd Func Lister() Local $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") Local $objWMI = ObjGet("winmgmts:\\localhost\root\default") Local $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") If Not IsObj($colItems) Or $colItems.Count = 0 Then MsgBox(0, "No Point", "No restore point in system.") Return SetError(1,0,0) EndIf Local $i = $colItems.Count For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate GUICtrlCreateListViewItem("[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF, $ListePoint) EndIf $i = $i - 1 Next EndFunc Func WMIDateStringToDate($dtmInstallDate) Return StringRegExpReplace($dtmInstallDate,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})","$2/$3/$1 $4:$5:$6") EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHEADER, $hWndFrom, $iCode $tNMHEADER = DllStructCreate($tagNMHEADER , $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHEADER, "hWndFrom")) $iCode = DllStructGetData($tNMHEADER, "Code") Switch $hWndFrom Case $hWnd_ListView If _IsPressed("02", $User32Dll) Then Return 1 Switch $iCode Case $NM_RCLICK Local $iItem = DllStructGetData($tNMHEADER, "Item") Local $Ctrl_LV_Selected = _GUICtrlListView_GetSelectedIndices($hWnd_ListView) If $Ctrl_LV_Selected == "" Or $Ctrl_LV_Selected <> $iItem Then Return 1 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Edit: Hmm using $tagNMHEADER you should be able to get the Item and Button triggering the event, so _IsPressed and _GUICtrlListView_HitTest can be removed. Getting the item is working as expected, but the button is returning seemingly nonsense values. (Updated the example to use $tagNMHEADER to get the Item, but it still relies on _IsPressed) Edited November 20, 2010 by Tvern Link to comment Share on other sites More sharing options...
Laddy Posted November 22, 2010 Author Share Posted November 22, 2010 Woua is impressive. Thank you for your help. I learned a lot from your examples.I have a new problemI will wish to retrieve my line number of the selected sequence and apply my restore function : Restore()via the right click [Action]?$Sequence = $objItem.SequenceNumber$RPList = GUICtrlCreateListViewItem("[" & $dateWMI & "] " & "RP" & $Sequence & " - " & $Description & " " & @LF, $ListePoint)Extract $Sequence What Should I use ?expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <GuiListView.au3> #include <StructureConstants.au3> #include <Misc.au3> Opt("GUIDataSeparatorChar", @LF) Global $RPList Global $objItem Global $User32Dll = DllOpen("user32.dll") Global $Gui = GUICreate(" Un clic", 700, 360) Global $BouttonLister = GUICtrlCreateButton("Lister", 6, 145, 100, 25) Global $ListePoint = GUICtrlCreateListView("", 6, 190, 660, 160) Global $List1context = GUICtrlCreateContextMenu($ListePoint) Global $MenuItem1 = GUICtrlCreateMenuItem("Action", $List1context) Global $hWnd_ListView = GUICtrlGetHandle($ListePoint) _GUICtrlListView_AddColumn($hWnd_ListView, "Restore Point", 700) GUICtrlSetLimit(-1, 200) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case 0 ContinueLoop Case $GUI_EVENT_CLOSE Exit Case $BouttonLister Lister() Case $MenuItem1 MsgBox(0,"test",$Sequence) EndSwitch WEnd Func Lister() Local $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") Local $objWMI = ObjGet("winmgmts:\\localhost\root\default") Local $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") If Not IsObj($colItems) Or $colItems.Count = 0 Then MsgBox(0, "No Point", "No restore point in system.") Return SetError(1,0,0) EndIf Local $i = $colItems.Count For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate $Sequence = $objItem.SequenceNumber $dateWMI = WMIDateStringToDate($dtmCreationTime) $Description = $objItem.Description ;$RPList = GUICtrlCreateListViewItem("[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF, $ListePoint) $RPList = GUICtrlCreateListViewItem("[" & $dateWMI & "] " & "RP" & $Sequence & " - " & $Description & " " & @LF, $ListePoint) EndIf $i = $i - 1 Next EndFunc Func Restore() Local $SRP = ObjGet("winmgmts:\\.\root\Default:SystemRestore") Local $eSRP = $SRP.Restore($objItem.SequenceNumber) ;le paramètre passé est le numéro de séquence du point de restauration qu'on souhaite reprendre. Shutdown(2) ; reboot PC EndFunc Func WMIDateStringToDate($dtmInstallDate) Return StringRegExpReplace($dtmInstallDate,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})","$2/$3/$1 $4:$5:$6") EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHEADER, $hWndFrom, $iCode $tNMHEADER = DllStructCreate($tagNMHEADER , $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHEADER, "hWndFrom")) $iCode = DllStructGetData($tNMHEADER, "Code") Switch $hWndFrom Case $hWnd_ListView If _IsPressed("02", $User32Dll) Then Return 1 Switch $iCode Case $NM_RCLICK Local $iItem = DllStructGetData($tNMHEADER, "Item") Local $Ctrl_LV_Selected = _GUICtrlListView_GetSelectedIndices($hWnd_ListView) If $Ctrl_LV_Selected == "" Or $Ctrl_LV_Selected <> $iItem Then Return 1 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
Tvern Posted November 22, 2010 Share Posted November 22, 2010 I'm not familliar with he object you use, so I'm not sure how to apply this, but I think you'll be able to make this work: Clicking Action will run the restore function, which retrieves the index of the selected item. There should be a way to refer to a restore point with that. (I've also disabled the context menu for the ListView Header) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <GuiListView.au3> #include <StructureConstants.au3> #include <Misc.au3> Opt("GUIDataSeparatorChar", @LF) Global $RPList Global $objItem Global $User32Dll = DllOpen("user32.dll") Global $Gui = GUICreate(" Un clic", 700, 360) Global $BouttonLister = GUICtrlCreateButton("Lister", 6, 145, 100, 25) Global $ListePoint = GUICtrlCreateListView("", 6, 190, 660, 160) Global $List1context = GUICtrlCreateContextMenu($ListePoint) Global $MenuItem1 = GUICtrlCreateMenuItem("Action", $List1context) Global $hWnd_ListView = GUICtrlGetHandle($ListePoint) _GUICtrlListView_AddColumn($hWnd_ListView, "Restore Point", 700) GUICtrlSetLimit(-1, 200) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Switch GUIGetMsg() Case 0 ContinueLoop Case $GUI_EVENT_CLOSE Exit Case $BouttonLister Lister() Case $MenuItem1 Restore() EndSwitch WEnd Func Lister() Local $dtmConvertedDate = ObjCreate("WbemScripting.SWbemDateTime") Local $objWMI = ObjGet("winmgmts:\\localhost\root\default") Local $colItems = $objWMI.ExecQuery("SELECT * FROM SystemRestore") If Not IsObj($colItems) Or $colItems.Count = 0 Then MsgBox(0, "No Point", "No restore point in system.") Return SetError(1,0,0) EndIf Local $i = $colItems.Count For $objItem In $colItems If $i < 6 Then $dtmConvertedDate.Value = $objItem.CreationTime $dtmCreationTime = $dtmConvertedDate.GetVarDate $Sequence = $objItem.SequenceNumber $dateWMI = WMIDateStringToDate($dtmCreationTime) $Description = $objItem.Description ;$RPList = GUICtrlCreateListViewItem("[" & WMIDateStringToDate($dtmCreationTime) & "] " & "RP" & $objItem.SequenceNumber & " - " & $objItem.Description & " " & @LF, $ListePoint) $RPList = GUICtrlCreateListViewItem("[" & $dateWMI & "] " & "RP" & $Sequence & " - " & $Description & " " & @LF, $ListePoint) EndIf $i = $i - 1 Next EndFunc Func Restore() Local $Ctrl_LV_Selected = _GUICtrlListView_GetSelectedIndices($hWnd_ListView) If MsgBox(52,"Restore restorepoint " & $Ctrl_LV_Selected,"Warning!" & @CRLF & "Clicking yes will reboot your PC." & @CRLF & "(And possibly restore some restore point)" & @CRLF & "Are you sure you want to continue?") <> 6 Then Return ;I imagine you should be able to use the value of $Ctrl_LV_Selected to refer to the object you want to restore. Local $SRP = ObjGet("winmgmts:\\.\root\Default:SystemRestore") Local $eSRP = $SRP.Restore($objItem.SequenceNumber) ;le paramètre passé est le numéro de séquence du point de restauration qu'on souhaite reprendre. Shutdown(2) ; reboot PC EndFunc Func WMIDateStringToDate($dtmInstallDate) Return StringRegExpReplace($dtmInstallDate,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})","$2/$3/$1 $4:$5:$6") EndFunc Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHEADER, $hWndFrom, $iCode $tNMHEADER = DllStructCreate($tagNMHEADER , $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHEADER, "hWndFrom")) $iCode = DllStructGetData($tNMHEADER, "Code") If _WinAPI_GetClassName($hWndFrom) = "SysHeader32" And $iCode = $NM_RCLICK Then Return 1 Switch $hWndFrom Case $hWnd_ListView If _IsPressed("02", $User32Dll) Then Return 1 Switch $iCode Case $NM_RCLICK Local $iItem = DllStructGetData($tNMHEADER, "Item") Local $Ctrl_LV_Selected = _GUICtrlListView_GetSelectedIndices($hWnd_ListView) If $Ctrl_LV_Selected == "" Or $Ctrl_LV_Selected <> $iItem Then Return 1 EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
Laddy Posted November 23, 2010 Author Share Posted November 23, 2010 (edited) It's work fine I just changed information since apparently it crashes but the system restore point has been launched and restoreFunc Restore() Local $Ctrl_LV_Selected = _GUICtrlListView_GetSelectedIndices($hWnd_ListView) If MsgBox(52,"Restore restorepoint " & $Ctrl_LV_Selected ,"Warning!" & @CRLF & "Clicking yes will reboot your PC." & @CRLF & "(And possibly restore some restore point)" & @CRLF & "Are you sure you want to continue?") <> 6 Then Return ;I imagine you should be able to use the value of $Ctrl_LV_Selected to refer to the object you want to restore. Local $SRP = ObjGet("winmgmts:\\.\root\Default:SystemRestore") Local $eSRP = $SRP.Restore($Sequence) ;le paramètre passé est le numéro de séquence du point de restauration qu'on souhaite reprendre. Shutdown(2) ; reboot PC EndFuncMy next step is to delete a specific restore point: Dhttp://msdn.microsoft.com/en-us/library/aa378934%28v=VS.85%29.aspxI think I Use : DllOpenDllStructSetDataThanks a lot for you help.Your comments to me are a great help for a beginner like me in this programming language.Laddy Edited November 23, 2010 by Laddy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now