Ci-joint un code propre et fonctionnel jusqu'au moment ou je trouve un conflit GUIRegisterMsg $WM_DROPFILES et $WM_NOTIFY
Je souhaite caresser l'espoir d'une ame charitable afin de m'aider à comprendre comment résoudre ce soucis.
J'ai déjà éssayé pas mal de choses mais je bloque toujours sur les GUIRegisterMsg.
Le but est de pouvoir organiser l'ordre de plusieurs fichiers GCODE afin de les combiner dans un GCODE unique très simplement.
Merci d'avance.
EDIT: Résolu voir viewtopic.php?f=3&t=16040&p=108501#p108501
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstants.au3>
#include <FontConstants.au3>
#include <GUIListView.au3>
#include "GUIListViewEx.au3"
Global $gaDropFiles[1]
;GUICreate('', 320, 220, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUICreate("CNC fusion (de fichiers GCode)", 520, 420, -1, -1, $WS_OVERLAPPEDWINDOW, $WS_EX_ACCEPTFILES)
Global $BtnName1 = "Glissez-Déposez vos fichiers dans la fenêtre", $BtnName2 = "Fusionner",$OutFile, $OutName = "Prg_Uni", $OutExt
Global $idBtnFusion = GUICtrlCreateButton( $BtnName1, 10, 380, 500, 30)
GUICtrlSetResizing( -1, BitOr( $GUI_DOCKBOTTOM, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
GUICtrlSetFont( -1, 10, $FW_NORMAL, $GUI_FONTUNDER, "Comic Sans Ms")
;GUICtrlSetState( -1,$GUI_DISABLE)
$cList = GUICtrlCreateListView('Nom du fichier|Dossier', 10, 10, 500, 360)
GUICtrlSendMsg( $cList, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, -1)
_GUICtrlListView_SetColumnWidth( $cList, 0, $LVSCW_AUTOSIZE_USEHEADER)
GUICtrlSetState( $cList, $GUI_DROPACCEPTED)
GUICtrlSetResizing(-1, BitOr( $GUI_DOCKTOP, $GUI_DOCKBOTTOM, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKSIZE))
_Context_Menu()
_Init_GUIListViewEx_Init()
_Count_Items()
GUIRegisterMsg($WM_DROPFILES, '_WM_DROPFILES_FUNC')
GUISetState()
_GUIListViewEx_MsgRegister()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_Quit()
Case $GUI_EVENT_DROPPED
_Event_Dropped()
Case $idBtnFusion
_Fusion()
Case $mContextMenu1
_Remove()
Case $mContextMenu2
_Remove_All()
EndSwitch
WEnd
Func _Context_Menu()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Context_Menu()" & @CRLF)
Global $mContextMenu, $mContextMenu1, $mContextMenu2
; Create context menu for native ListView
$mContextMenu = GUICtrlCreateContextMenu( $cList)
$mContextMenu1 = GUICtrlCreateMenuItem("Retirer de la liste", $mContextmenu)
GUICtrlCreateMenuItem("", $mContextmenu)
$mContextMenu2 = GUICtrlCreateMenuItem("Retirer tout", $mContextmenu)
EndFunc
Func _Init_GUIListViewEx_Init()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Init_GUIListViewEx_Init()" & @CRLF)
Global $iList = _GUIListViewEx_Init( $cList, "", 0, 0, True, 1) ; External drag & drop - items deleted on drag
EndFunc
Func _Remove()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Remove()" & @CRLF)
_GUIListViewEx_SetActive( $iList)
_GUIListViewEx_Delete()
_Count_Items()
EndFunc
Func _Remove_All()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Remove_All()" & @CRLF)
_GUIListViewEx_Close( $iList) ; Should be the index returned from _GUIListViewEx_Init
_GUICtrlListView_DeleteAllItems( $cList) ; Should be the handle/ControlID returned by GUICtrlCreateListView/_GUICrtlListView_Create
_Init_GUIListViewEx_Init() ; Here you need to store the new index retuned by the function...
_GUIListViewEx_SetActive( $iList) ; ...which you then use here
_Count_Items()
;$aRet = _GUIListViewEx_ReadToArray( $cList, 0)
;_ArrayDisplay( $aRet)
;ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "_GUICtrlListView_GetItemCount( $cList) " & _GUICtrlListView_GetItemCount( $cList) & @CRLF)
EndFunc
Func _Fusion()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Fusion()" & @CRLF)
Local $aRet = '', $aRetOld = '', $AddFiles = ''
$aRet = _GUIListViewEx_ReadToArray( $cList, 0)
;$CNT = _GUICtrlListView_GetItemCount( $cList)-1
;_ArrayDisplay( $aRet)
For $i = 0 To _GUICtrlListView_GetItemCount( $cList)-1
$RetPath = $aRet[$i][1]
$RetFile = $aRet[$i][0]
;ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & $i & @TAB & "$RetPath = " & $RetPath & @CRLF)
If Not $aRetOld Then $aRetOld = $RetPath
;ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & $i & @TAB & "$aRetOld = " & $aRetOld & @CRLF)
If $aRetOld = $RetPath Then
If $i = _GUICtrlListView_GetItemCount( $cList)-1 Then
$AddFiles &= '"' & $RetPath & $RetFile & '"'
Else
$AddFiles &= '"' & $RetPath & $RetFile & '"+'
EndIf
Else
;ConsoleWrite( $RetPath & @CRLF)
EndIf
Next
;ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "$AddFiles = " & $AddFiles & @CRLF)
If $AddFiles Then
RunWait(@ComSpec & ' /c ' & 'Copy /b ' & $AddFiles & ' "' & $OutFile & '"', "", @SW_SHOW)
Else
EndIf
EndFunc
Func _Event_Dropped()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Event_Dropped()" & @CRLF)
For $i = 0 To UBound( $gaDropFiles) - 1
$RetPath = StringRegExpReplace( $gaDropFiles[$i], "(^.*\\)(.*)", "\1")
$RetFile = StringRegExpReplace( $gaDropFiles[$i], "^.*\\", "")
GUICtrlCreateListViewItem( $RetFile & '|' & $RetPath, $cList)
_GUIListViewEx_Insert( $RetFile & '|' & $RetPath)
Next
For $i = 0 To _GUICtrlListView_GetColumnCount( $cList)-1
_GUICtrlListView_SetColumnWidth( $cList, $i, $LVSCW_AUTOSIZE_USEHEADER)
Next
_Count_Items()
EndFunc
Func _Count_Items()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Count_Items()" & @CRLF)
If _GUICtrlListView_GetItemCount( $cList) < '2' Then
GUICtrlSetState( $idBtnFusion, $GUI_DISABLE)
GUICtrlSetData( $idBtnFusion, $BtnName1)
Else
If Not $OutExt Then
GUICtrlSetState( $idBtnFusion, $GUI_DISABLE)
Else
GUICtrlSetState( $idBtnFusion, $GUI_ENABLE)
EndIf
GUICtrlSetData( $idBtnFusion, "Cliquez sur un fichier pour choisir son extension")
EndIf
If _GUICtrlListView_GetItemCount( $cList) < '1' Then
GUICtrlSetState( $mContextMenu1, $GUI_DISABLE)
GUICtrlSetState( $mContextMenu2, $GUI_DISABLE)
Else
GUICtrlSetState( $mContextMenu1, $GUI_ENABLE)
GUICtrlSetState( $mContextMenu2, $GUI_ENABLE)
EndIf
;ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "_GUICtrlListView_GetItemCount( $cList) = " & _GUICtrlListView_GetItemCount( $cList) & @CRLF)
EndFunc
Func _WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)" & @CRLF)
Local $nSize, $pFileName, $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
For $i = 0 To $nAmt[0] - 1
$nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
$nSize = $nSize[0] + 1
$pFileName = DllStructCreate("char[" & $nSize & "]")
DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
ReDim $gaDropFiles[$i + 1]
$gaDropFiles[$i] = DllStructGetData($pFileName, 1)
$pFileName = 0
Next
EndFunc
Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$event = DllStructGetData($tNMHDR, 'Code')
If $wParam = $cList And $event = $NM_CLICK Then
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
$index = DllStructGetData($tInfo, "Index")
$SubItem = DllStructGetData($tInfo, "SubItem")
$OutPath = StringRegExpReplace( _GUICtrlListView_GetItemText( $cList, $index, 1), "(^.*\\)(.*)", "\1")
$OutExt = StringRegExpReplace( _GUICtrlListView_GetItemText( $cList, $index, 0), "^.*\.", ".$1")
$OutFile = $OutName & $OutExt
If Not $OutExt Or _GUICtrlListView_GetItemCount( $cList) < '2' Then
GUICtrlSetState( $idBtnFusion, $GUI_DISABLE)
GUICtrlSetData( $idBtnFusion, "Pas de fichier selctionné, minimum 2 fichiers pour fusionner")
Else
GUICtrlSetState( $idBtnFusion, $GUI_ENABLE)
GUICtrlSetData( $idBtnFusion, $BtnName2 & " (" & $OutFile & ")")
EndIf
;ConsoleWrite(">>>>>>>>>>> " & _GUICtrlListView_GetItemText( $cList, $index, 0) & @CRLF)
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY
Func _Quit()
ConsoleWrite("Line=" & @ScriptLineNumber & @TAB & "Func _Quit()" & @CRLF)
_GUIListViewEx_Close( $iList)
Exit
EndFunc