#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListView.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <Array.au3>
;
Opt("TrayMenuMode", 1 + 2)
Opt("TrayOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("GUIOnEventMode", 1)
Global $iDebug = False
Global $Begin_Drag = False
Global $hGUI, $hExt_GUI, $nListView1, $nListView2, $hCursor
; настройка меню в трее
$nField_TrayItem = TrayCreateItem("Set")
TrayItemSetOnEvent(-1, "_TrayEvents")
$nExit_TrayItem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_TrayEvents")
_GUICreate_Proc()
If $iDebug Then _Create_ExternalForm_Proc()
While 1
Sleep(100)
WEnd
Func _TrayEvents()
Switch @TRAY_ID
Case $nField_TrayItem
GUISetState(@SW_SHOW, $hGUI)
If $iDebug Then GUISetState(@SW_SHOW, $hExt_GUI)
Case $nExit_TrayItem
Exit
EndSwitch
EndFunc
Func _GUIEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
GUISetState(@SW_HIDE, $hGUI)
If $iDebug Then GUISetState(@SW_HIDE, $hExt_GUI)
EndSwitch
EndFunc
Func _GUICreate_Proc()
$hCursor = _WinAPI_LoadImage(0, @WindowsDir & "\Cursors\3dgarro.cur", $IMAGE_CURSOR, 0, 0, _
BitOR($LR_LOADFROMFILE, $LR_DEFAULTSIZE))
Dim $aFields[2][2]
$aFields[0][0] = "item1"
$aFields[1][0] = "item2"
$aFields[0][1] = "status1"
$aFields[1][1] = "status2"
; Create GUI
$hGUI = GUICreate("Test", 800, 300)
$nListView1 = GUICtrlCreateListView("", 2, 2, 394, 268)
$hListView1 = GUICtrlGetHandle(-1)
_GUICtrlListView_SetUnicodeFormat($hListView1, False)
; Add columns
_GUICtrlListView_AddColumn($hListView1, "Item", 100)
_GUICtrlListView_AddColumn($hListView1, "Status", 100)
_GUICtrlListView_SetItemCount($hListView1, 30)
_GUICtrlListView_AddArray($hListView1, $aFields)
$nListView2 = GUICtrlCreateListView("", 396, 2, 394, 268)
$hListView2 = GUICtrlGetHandle(-1)
_GUICtrlListView_SetUnicodeFormat($hListView2, False)
; Add columns
_GUICtrlListView_AddColumn($hListView2, "Item", 100)
_GUICtrlListView_AddColumn($hListView2, "Status", 100)
_GUICtrlListView_SetItemCount($hListView2, 30)
; _GUICtrlListView_AddArray($hListView2, $aFields)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_LBUTTONUP, "WM_LBUTTONUP")
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIEvents")
EndFunc
Func _Create_ExternalForm_Proc()
$hExt_GUI = GUICreate("External Tets Form", 200, 150, 600)
GUICtrlCreateEdit("", 10, 20, 180, 100)
EndFunc
Func _WinAPI_GetHoveredHandle()
Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
Local $Ret = DllCall("user32.dll", "int", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
Opt("MouseCoordMode", $iOld_Opt_MCM)
Return HWnd($Ret[0])
EndFunc
Func WM_LBUTTONUP($hWndGUI, $MsgID, $wParam, $lParam)
If Not $Begin_Drag Then Return $GUI_RUNDEFMSG
$Begin_Drag = False
Local $iIndex = Number(_GUICtrlListView_GetSelectedIndices($nListView1))
Local $sSelText = _GUICtrlListView_GetItemText($nListView1, $iIndex)
Local $hWnd = _WinAPI_GetHoveredHandle()
Local $hAncestor = _WinAPI_GetAncestor($hWnd, $GA_ROOTOWNER)
If $sSelText <> "" Then ; And $hAncestor <> $hGUI Then
ToolTip("Dropped Dest hWnd: " & $hWnd)
_GUICtrlListView_AddItem($hWnd, $sSelText)
;ControlSetText($hAncestor, "", $hWnd, $sSelText)
EndIf
Return $GUI_RUNDEFMSG
EndFunc
Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
Local $tagNMHDR, $iEvent, $hwndFrom, $iCode, $iItem
$tagNMHDR = DllStructCreate("int;int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code, Item)
If @error Then Return $GUI_RUNDEFMSG
$iCode = DllStructGetData($tagNMHDR, 3)
$iItem = DllStructGetData($tagNMHDR, 4)
Switch $wParam
Case $nListView1
Switch $iCode
Case $LVN_BEGINDRAG
_WinAPI_SetCursor($hCursor)
$Begin_Drag = True
EndSwitch
Case $nListView2
Switch $iCode
Case $LVN_BEGINDRAG
_WinAPI_SetCursor($hCursor)
$Begin_Drag = True
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc