Jump to content

Recommended Posts

I'm trying to put together a gui to be able to drag an item from one listview into another. I've found some very nice examples on the forum. However, I'm having a bit of an issue. When I drag an item from either of the listview controls to the other, artifacts appear from the child gui that appears when dragging. The funny thing is that the artifacts only appear when dragging upward! There's got to be something I'm missing here.

I've been looking at the code from both of these links to try to figure something out.

For the example of what I'm talking about, the code from JonnyThunder from the top link with the fancy drag gui from ReFran in the bottom link is below. They did some really great work and my combining the code is just lacking something that I can't figure out. I've attached a pic of what I'm witnessing.

How can I eliminate these artifacts? Here's the code that I'm working with:

; Includes first! Must must must!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
; Switch on the 'onEvent' notifications
Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 2)
; Generate the GUI! Ahoy there.
Global $gw = 16
Global $gh = 16
Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc
Global $MainForm, $list_source, $list_target, $drag_gui
$MainForm = GUICreate(" TEST! ", 517, 178)
; Source list box
$list_source = GUICtrlCreateListView("Title|Details", 13, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
; Target list box
$list_target = GUICtrlCreateListView("Title|Details", 261, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
; Populate box with some test stuff
For $x = 1 To 6
GUICtrlCreateListViewItem( _makeJunkName() & "|" & _makeJunkName(), $list_source)
Next
GUISetState(@SW_SHOW, $MainForm)
; Handle GUI events
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_dragHandler")
GUISetOnEvent($GUI_EVENT_CLOSE, "_formEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_formEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "_formEvents")
$position = WinGetPos($MainForm)
$client = WinGetClientSize($MainForm)
$light_border = ($position[2] - $client[0]) / 2
$thick_border = $position[3] - $client[1] - $light_border
$x_coord = $position[0] + $light_border
$y_coord = $position[1] + $thick_border
$drag_gui = GUICreate("Drag", $gw, $gh, $x_coord, $y_coord, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $MainForm)
$cursor_icon = GUICtrlCreateIcon("Shell32.dll", -147, 0, 0, 16, 16)
GUISetState(@SW_SHOW, $drag_gui)
setTrans()
GUISetState(@SW_HIDE, $drag_gui)
; Main program loop
While 1
; Don't really do much in here at all...
Sleep(10)
WEnd
; Create a junk name for testing
Func _makeJunkName()
Local $labelout = ''
For $i = 1 To 10
  $labelout &= Chr(Random(65, 90, 1))
Next
Return $labelout
EndFunc   ;==>_makeJunkName
; Function to handle drag and drop
Func _dragHandler()
; Define some stuff
Local $source, $desc
Local $cinfo = GUIGetCursorInfo(WinGetHandle($MainForm))
Local $direction = 0
; Check we are dragging from one or the other boxes
If $cinfo[4] = $list_source Or $cinfo[4] = $list_target Then
  ; Are we moving from source to destination
  If $cinfo[4] = $list_source Then
   $direction = 1
  EndIf
  ; Or are we moving from destination to source
  If $cinfo[4] = $list_target Then
   $direction = 2
  EndIf
  ; Doublecheck we're pressing mouse button
  If _IsPressed(1) Then
   If $direction = 1 Then
    $selecteditems = _GUICtrlListView_GetSelectedCount($list_source)
    $idx = _GUICtrlListView_GetSelectedIndices($list_source, False)
    $item_txt = _GUICtrlListView_GetItemText($list_source, Int($idx))
   Else
    $selecteditems = _GUICtrlListView_GetSelectedCount($list_target)
    $idx = _GUICtrlListView_GetSelectedIndices($list_target, False)
    $item_txt = _GUICtrlListView_GetItemText($list_target, Int($idx))
   EndIf
   ; Check we actually have selected an item
   If $selecteditems >= 1 Then
    ; Wait for keypress!
    _WinAPI_ShowCursor(False)
    GUISetState(@SW_SHOW, $drag_gui)
    While _IsPressed(1)
     chase($item_txt)
    WEnd
    GUISetState(@SW_HIDE, $drag_gui)
    _WinAPI_ShowCursor(True)
    ToolTip("")
    ; Get new position
    Local $newcinfo = GUIGetCursorInfo(WinGetHandle($MainForm))
    ; If we were moving from source to destination and we ARE in the destination box
    If $direction = 1 And $newcinfo[4] = $list_target Then
     ConsoleWrite("Moved " & $selecteditems & " items from source to destination" & @CRLF)
     _GUICtrlListView_CopyItems(GUICtrlGetHandle($list_source), $list_target, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $direction = 2 And $newcinfo[4] = $list_source Then
     ConsoleWrite("Moved " & $selecteditems & " items from destination to source" & @CRLF)
     _GUICtrlListView_CopyItems(GUICtrlGetHandle($list_target), $list_source, 1)
    EndIf
   EndIf
  EndIf
EndIf
EndFunc   ;==>_dragHandler
; Function to handle other form events
Func _formEvents()
Select
  Case @GUI_CtrlId = $GUI_EVENT_CLOSE
   Exit
EndSelect
EndFunc   ;==>_formEvents
Func chase($moving_txt)
$mp = MouseGetPos()
WinMove($drag_gui, "", $mp[0] + 1, $mp[1] + 0)
ToolTip($moving_txt, $mp[0] + 18, $mp[1])
EndFunc   ;==>chase
Func setTrans()
$aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)
$rct = DllStructCreate("int;int;int;inr", $aM_Mask[0])
$TestCol = PixelGetColor(0, 0)
$Startx = -1
$Starty = -1
$Endx = 0
$Endy = 0
For $i = 0 To $gw
  For $j = 0 To $gh
   If PixelGetColor($i, $j) = $TestCol And $j < $gh Then
    If $Startx = -1 Then
     $Startx = $i
     $Starty = $j
     $Endx = $i
     $Endy = $j
    Else
     $Endx = $i
     $Endy = $j
    EndIf
   Else
    If $Startx <> -1 Then addRegion()
    $Startx = -1
    $Starty = -1
   EndIf
  Next
Next
DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $drag_gui, "long", $aM_Mask[0], "int", 1)
EndFunc   ;==>setTrans
Func addRegion()
$aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $Startx, "long", $Starty, "long", $Endx + 1, "long", $Endy + 1)
$nc += 1
DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc   ;==>addRegion

Artifacts.bmp

Link to post
Share on other sites

If this helps, the culprit line is the WinMove line in your chase function. Comment it out, and all is well. I'll keep looking into it and see if I can track down why...

Just as a friendly suggestion, I'm having trouble reading your code. Line breaks and tabbing help ;)

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

Just as a friendly suggestion, I'm having trouble reading your code. Line breaks and tabbing help :)

Sorry about that! I'm very diligent in tabbing my code in SciTE, but for some reason, when I paste it into the forum, it loses all the tabs. Thanks for the suggestion! I'll try that out ;)

Edit: Ok, now I'm looking for a different method to moving the hidden GUI around since just the tooltip is displayed.

Edited by buymeapc
Link to post
Share on other sites

No worries, hope I didn't come off as a pain. When you figure it out, definitely post back the solution. I'll let you know if I get anywhere.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

Not at all! It actually bothers me when the tabs don't come out properly, so I certainly know where you're coming from. I'm still trying on my end. I'll definitely post here if I figure something out.

The weird thing is that the treeview example link that I posted (the second link from the first post) displays no artifacts when dragging and I just can't figure out why mine does. Is it that it's a treeview and not a listview?

I appreciate the help, by the way!

Link to post
Share on other sites

Well only to complicate matters further, I setup Autoit at home to try something out, and running on Win 7 64 bit with both the newest production and beta, I do not get the artifacting problem at all!

The other weird tihng I get is the 'drag' arrow appears at the top of the GUI window for about 5 seconds before dissapearing on its own.

I'll have to go back to my work machines and see if I can isolate anything...maybe my home machine is a one-off.

post-17201-0-60362800-1337991902_thumb.j

EDIT: Tested this out on my Win 7 32 work machine... and no artifacting, but same problem as described above with the drag GUI appearing. Seems this is exploiting something in Win XP.

From here, what I'm doing and my suggestion is to strip out everything possible to make the smallest reproducer possible, and switch to only _guictrllistview and not the internal GuiCtrlCreateListView.

Hopefully we can narrow down what is to blame.

Edited by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

Well I'm going to have to leave this for the weekend, but I have made some progress.

The *fix* would seem to be a combination of converting everything to _guictrllistview (and in turn changing the register messages) and putting in _WinAPI_UpdateWindow in the chase function.

I tried putting just the _WinAPI_UpdateWindow in your original code and it does nothing. Also, to reiterate I do NOT get this problem with Win 7, 32 or 64, only in XP. The good news is I don't see any negative from using the code that works in XP on Win 7.

The code posted is not in a fully working state. There are a couple bugs, most notably the icon does not appear, and the text of what you are moving doesn't appear. I changed the tooltip to a splashtext, which fixed the flickering, but for some reason the text isn't populating into the window. I'm probably overlooking something stupid. I'm sure I've introduced another bug or two into the mix.

Working.au3

Hopefully fixing those bugs are easy, please post back if you are able to. It will be a good couple days before I'm able to check in probably.

Also, I'm by no means a great coder, but as a piece of advise every single time I've started something with the internal GUICtrlCreateListView functions I've come to wish I just bit the bullet and used the _guictrllistview functions. The internal funcs make a lot of it easier, but I always get tripped up in something I just can't do. Its hard to go backwards and redo a script but it isn't that much of a pain to start out that way.

Just my 2 cents.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

It works fine on Win7, huh? Interesting. I do agree with you that the fix may lie in the usage of _GUICtrlListView functions as opposed to GUICtrlCreateListView, though.

I've been fiddling with your sample from the above post. I'm not entirely too sure if the splash window can move and display text at the same time. Every example that I see shows that function as a static window. I noticed a couple of bugs that you mentioned. One being that if you drag/drop an item onto the same listview it came from, it'll drop the item to the opposite listview. Fixed that.

So, Here's a slightly modified version of the code you posted and it does not create the trail marks, which is great! However, I could not seem to get the splashtext to display the text no matter what I tried. Also, the weirdest thing is I commented out the following line on line 56:

GUISetState(@SW_HIDE, $drag_gui)

If you drag an item slowly, you'll see the icon disappear little by little. It's the weirdest thing! If you uncomment this line, however, the icon won't show at all.

Check it out ;)

; Includes first! Must must must!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <SendMessage.au3>
; Switch on the 'onEvent' notifications
Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 2)
; Generate the GUI! Ahoy there.
Global $gw = 16
Global $gh = 16
Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc
Global $MainForm, $list_source, $list_target, $drag_gui, $hSplash
$MainForm = GUICreate(" TEST! ", 517, 178)
; Source list box
$list_source = _GUICtrlListView_Create($MainForm, "Title|Details", 13, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
_GUICtrlListView_SetExtendedListViewStyle($list_source, $LVS_EX_FULLROWSELECT)
; Target list box
$list_target = _GUICtrlListView_Create($MainForm, "Title|Details", 261, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
_GUICtrlListView_SetExtendedListViewStyle($list_target, $LVS_EX_FULLROWSELECT)
; Populate box with some test stuff
For $i = 0 To 4
   $item = _GUICtrlListView_AddItem($list_source, _makeJunkName())
   _GUICtrlListView_AddSubItem($list_source, $item, _makeJunkName(), 1)
Next
GUISetState(@SW_SHOW, $MainForm)
; Handle GUI events
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetOnEvent($GUI_EVENT_CLOSE, "_formEvents")
;~ $drag_gui = GUICreate("Drag", $gw, $gh, 0, 0, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $MainForm)
;~ $cursor_icon = GUICtrlCreateIcon("Shell32.dll", -147, 0, 0, 16, 16)
;~ GUISetState(@SW_HIDE, $drag_gui)
$position = WinGetPos($MainForm)
$client = WinGetClientSize($MainForm)
$light_border = ($position[2] - $client[0]) / 2
$thick_border = $position[3] - $client[1] - $light_border
$x_coord = $position[0] + $light_border
$y_coord = $position[1] + $thick_border
$drag_gui = GUICreate("Drag", $gw, $gh, $x_coord, $y_coord, BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $MainForm)
$cursor_icon = GUICtrlCreateIcon("Shell32.dll", -147, 0, 0, 16, 16)
GUISetState(@SW_SHOW, $drag_gui)
setTrans()
;GUISetState(@SW_HIDE, $drag_gui);<<<<<<< Try enabling and disabling this! See the fun happen
; Main program loop
While 1
   ; Don't really do much in here at all...
   Sleep(10)
WEnd
; Function to handle other form events
Func chase()
   $mp = MouseGetPos()
  _WinAPI_UpdateWindow($MainForm)
  WinMove($drag_gui, "", $mp[0] + 1, $mp[1] + 0)
  ;ToolTip($moving_txt, $mp[0] + 18, $mp[1])
  WinMove($hSplash, "", $mp[0] + 18, $mp[1])
EndFunc   ;==>chase
Func _formEvents()
   Exit
EndFunc   ;==>_formEvents
; Create a junk name for testing
Func _makeJunkName()
  Local $labelout = ''
  For $i = 1 To 10
    $labelout &= Chr(Random(65, 90, 1))
  Next
  Return $labelout
EndFunc   ;==>_makeJunkName
Func setTrans()
  $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)
  $rct = DllStructCreate("int;int;int;inr", $aM_Mask[0])
  $TestCol = PixelGetColor(0, 0)
  $Startx = -1
  $Starty = -1
  $Endx = 0
  $Endy = 0
  For $i = 0 To $gw
    For $j = 0 To $gh
     If PixelGetColor($i, $j) = $TestCol And $j < $gh Then
      If $Startx = -1 Then
       $Startx = $i
       $Starty = $j
       $Endx = $i
       $Endy = $j
      Else
       $Endx = $i
       $Endy = $j
      EndIf
     Else
      If $Startx <> -1 Then addRegion()
      $Startx = -1
      $Starty = -1
     EndIf
    Next
  Next
  DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $drag_gui, "long", $aM_Mask[0], "int", 1)
EndFunc   ;==>setTrans
Func addRegion()
$aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $Startx, "long", $Starty, "long", $Endx + 1, "long", $Endy + 1)
$nc += 1
DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc   ;==>addRegion
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $item_txt
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
$hWndListView = $hWndFrom
If Not IsHWnd($hWndFrom) Then $hWndListView = GUICtrlGetHandle($hWndFrom)
Switch $hWndFrom
  Case $hWndListView
   Switch $iCode
    Case $LVN_BEGINDRAG ; A drag-and-drop operation involving the left mouse button is being initiated
                $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    If $hWndFrom = $list_source Then
     $direction = 1
    ElseIf $hWndFrom = $list_target Then
     ; Or are we moving from destination to source
     $direction = 2
    Else
     MsgBox(0, "", "bad")
    EndIf
    $aidx = _GUICtrlListView_GetSelectedIndices($hWndFrom, True)
    $iselecteditems = $aidx[0]
    ;retrieve all item text, not just first item
    For $i = 1 To $aidx[0]
     $item_txt &= _GUICtrlListView_GetItemText($hWndFrom, $aidx[$i]) & @CRLF
    Next
    _WinAPI_ShowCursor(False)
    GUISetState(@SW_SHOW, $drag_gui)
    ;$atemp = _GUICtrlListBox_GetItemRect($cinfo[4], Int($idx))
    $atemp = _GUICtrlListView_ApproximateViewRect($hWndFrom, $iselecteditems)
    $hSplash = SplashTextOn("title", $item_txt, $atemp[0], $atemp[1] + 20, -1, -1, 1, "", 8)
    ;MsgBox(0, "", $item_txt)
    While _IsPressed(1)
     chase()
    WEnd
    GUISetState(@SW_HIDE, $drag_gui)
    _WinAPI_ShowCursor(True)
    SplashOff()
    ; Get new position
;~  Local $newcinfo = GUIGetCursorInfo(WinGetHandle($MainForm));<--- Had to disable this since we're using handles and not id's anymore
    $flag = False
    If $hWndFrom = $list_source Then
     Local $newcinfo = _GUICtrlListView_HitTest($list_target)
    Else
     Local $newcinfo = _GUICtrlListView_HitTest($list_source)
    EndIf
    For $t = 1 To 5
     If $newcinfo[$t] = True Then
      ConsoleWrite([email="$t&@CRLF"]$t&@CRLF[/email])
      $flag = True
      ExitLoop
     EndIf
    Next
    ; If we were moving from source to destination and we ARE in the destination box
;~  If $direction = 1 And $newcinfo[4] = GUICtrlGetHandle($list_target) Then
    If $direction = 1 And $flag Then
     ConsoleWrite("Moved " & $iselecteditems & " items from source to destination" & @CRLF)
     _GUICtrlListView_CopyItems($list_source, $list_target, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $direction = 2 And $flag Then
     ConsoleWrite("Moved " & $iselecteditems & " items from destination to source" & @CRLF)
     _GUICtrlListView_CopyItems($list_target, $list_source, 1)
    EndIf
                 _DebugPrint("$LVN_BEGINDRAG" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                         "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                         "-->Code:" & @TAB & $iCode & @LF & _
                         "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                         "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                         "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                         "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                         "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                         "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                         "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                         "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
      ;_dragHandler($hWndFrom)
                 ; No return value
             Case $LVN_BEGINRDRAG ; A drag-and-drop operation involving the right mouse button is being initiated
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 _DebugPrint("$LVN_BEGINRDRAG" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                         "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                         "-->Code:" & @TAB & $iCode & @LF & _
                         "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                         "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                         "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                         "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                         "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                         "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                         "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                         "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                 ; No return value
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
   "!===========================================================" & @LF & _
   "+======================================================" & @LF & _
   "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
   "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

I really appreciate your help!

Link to post
Share on other sites

Just a quick reply, and I'll take a look at the code when I can, but the splash screen CAN display text like you can...at least I'm fairly sure ;) . If you go back to your original code and supplement in the splashtext it worked, even with multiple list entries being dragged.

I'l take a look at the rest of the code later. I really hope we get this working the way we want...its a cool piece of code.

EDIT: I think I have it... have to piece it back together. Will post tomorrow morning.

Edited by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

As promised...

I had to go back to my 'working.au3' rather then the code you posted, it was just easier for me to read. The attached is my code with the fixes.

FullyWorking.au3

However, if you want to make your code work all you need to do is;

Add _WinAPI_UpdateWindow($drag_gui) to the chase func

Uncomment line 47, the guisetstate line with your comments at the end

Add Sleep(1) directly below the SplashTextOn line

A few explanations...

In the code, you need

GUISetState(@SW_SHOW, $drag_gui)
setTrans()
GUISetState(@SW_HIDE, $drag_gui)

or else setTrans() doesn't work properly. Seems it can't set the transparency with a hidden GUI, so you have to show it, set the trans, and hide again (an educated guess, could be wrong). I don't know enough about the GDI calls to be of help there. Also, setTrans does not work properly on Win 7 (at least with my limited tested).

The updatewindow($drag_gui) line prevents the drag cursor from being eaten. I can remove both the updatewindow lines and it works in Win 7, so I'm not sure if using updatewindow for the main GUI adds the bug of it 'eating' the drag gui, or what.

Now the hard one... the Sleep(1).

I can only make a guess here, that the window just didn't have enough time to create and add the text before entering the While loop. I played around with it and a sleep of 1 seems to work perfectly, but in reality I would up it to 5 or so. I can't imagine something that small being detectable by a user, and since I don't know why a sleep of 1 works, it would probably be a good idea to pad it a little.

Let me know how it works out for you. If you can update the GDI calls for Win 7 I would like to have that, but its not a big deal. Not sure if you are able to test against a Win 7 machine.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

Congratulations for the work, would be even better if you can use the left and right arrows to change the list as well.

Posted Image

Link to post
Share on other sites

That is something I can do... here is what you would have to do, from my code.

Add a button and onevent for the button;

GUICtrlCreateButton("add", 200, 155, 50, 20)
GUICtrlSetOnEvent(-1, "addpressed")

and the function for it is a very simple

Func addpressed()
_GUICtrlListView_CopyItems($list_source, $list_target, 1)
EndFunc

There's multiple ways to do that, and obviously that only moves from left to right, not the reverse, but you get the idea.

EDIT: OOOOH or am I an idiot and you mean the arrow keys, not buttons? Sorry low on caffeine today. But is follows the same principles whether working with a button or hotkey (hint, GUISetAccelerators)

Edited by someone
While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

I still had not looked at your code, I made the change and was as I suggested.

; Includes first! Must must must!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <SendMessage.au3>
; Switch on the 'onEvent' notifications
Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 2)
; Generate the GUI! Ahoy there.
Global $gw = 16
Global $gh = 16
Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc
Global $MainForm, $list_source, $list_target, $drag_gui, $hSplash
$MainForm = GUICreate(" TEST! ", 517, 178)
; Source list box
$list_source = _GUICtrlListView_Create($MainForm, "Title|Details", 13, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
; Target list box
$list_target = _GUICtrlListView_Create($MainForm, "Title|Details", 261, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
; Populate box with some test stuff

$text = GUICtrlCreateLabel("Use the arrows to add or remove items from the list.", 100, 159, 330, 30)
GUICtrlSetBkColor($text, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont($text,11)
HotKeySet("{right}", "add")
HotKeySet("{left}", "remove")
Func add()
_GUICtrlListView_CopyItems ($list_source , $list_target, 1)
EndFunc
Func remove()
_GUICtrlListView_CopyItems ($list_target , $list_source, 1)
EndFunc
For $i = 0 To 4
   $item = _GUICtrlListView_AddItem($list_source, _makeJunkName())
   _GUICtrlListView_AddSubItem($list_source, $item, _makeJunkName(), 1)
Next
; Handle GUI events
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetOnEvent($GUI_EVENT_CLOSE, "_formEvents")
$drag_gui = GUICreate("Drag", $gw, $gh, 300, 300, BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $MainForm)
$cursor_icon = GUICtrlCreateIcon("Shell32.dll", -147, 0, 0, 16, 16)
GUISetState(@SW_SHOW, $drag_gui)
setTrans()
GUISetState(@SW_HIDE, $drag_gui)
GUISetState(@SW_SHOW, $MainForm)
; Main program loop
While 1
Sleep(10)
WEnd
; Function to handle other form events
Func chase()
$mp = MouseGetPos()
_WinAPI_UpdateWindow($MainForm)
_WinAPI_UpdateWindow($drag_gui)
WinMove($drag_gui, "", $mp[0] + 0, $mp[1] + 0)
;ToolTip($moving_txt, $mp[0] + 18, $mp[1])
WinMove($hSplash, "", $mp[0] + 28, $mp[1] + 0)
EndFunc   ;==>chase
Func _formEvents()
   Exit
EndFunc   ;==>_formEvents
Func setTrans()
  $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)
  $rct = DllStructCreate("int;int;int;inr", $aM_Mask[0])
  $TestCol = PixelGetColor(0, 0)
  $Startx = -1
  $Starty = -1
  $Endx = 0
  $Endy = 0
  For $i = 0 To $gw
    For $j = 0 To $gh
     If PixelGetColor($i, $j) = $TestCol And $j < $gh Then
      If $Startx = -1 Then
       $Startx = $i
       $Starty = $j
       $Endx = $i
       $Endy = $j
      Else
       $Endx = $i
       $Endy = $j
      EndIf
     Else
      If $Startx <> -1 Then addRegion()
      $Startx = -1
      $Starty = -1
     EndIf
    Next
  Next
  DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $drag_gui, "long", $aM_Mask[0], "int", 1)
EndFunc   ;==>setTrans
Func addRegion()
$aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $Startx, "long", $Starty, "long", $Endx + 1, "long", $Endy + 1)
$nc += 1
DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc   ;==>addRegion
; Create a junk name for testing
Func _makeJunkName()
Local $labelout = ''
For $i = 1 To 10
  $labelout &= Chr(Random(65, 90, 1))
Next
Return $labelout
EndFunc   ;==>_makeJunkName
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $item_txt
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
$hWndListView = $hWndFrom
If Not IsHWnd($hWndFrom) Then $hWndListView = GUICtrlGetHandle($hWndFrom)
Switch $hWndFrom
  Case $hWndListView
   Switch $iCode
    Case $LVN_BEGINDRAG ; A drag-and-drop operation involving the left mouse button is being initiated
                $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    If $hWndFrom = $list_source Then
     $direction = 1
    ElseIf $hWndFrom = $list_target Then
     ; Or are we moving from destination to source
     $direction = 2
    Else
     MsgBox(0, "", "bad")
    EndIf
    $aidx = _GUICtrlListView_GetSelectedIndices($hWndFrom, True)
    $iselecteditems = $aidx[0]
    ;retrieve all item text, not just first item
    For $i = 1 To $aidx[0]
     $item_txt &= _GUICtrlListView_GetItemText($hWndFrom, $aidx[$i]) & @CRLF
    Next
    $item_txt = StringStripWS($item_txt, 1+2)
    _WinAPI_ShowCursor(False)
    ;$atemp = _GUICtrlListBox_GetItemRect($cinfo[4], Int($idx))
    $atemp = _GUICtrlListView_ApproximateViewRect($hWndFrom, $iselecteditems)
    $hSplash = SplashTextOn("", $item_txt, $atemp[0] - 10, $atemp[1] - 5, -1, -1, 1+32, "", 12)
    Sleep(5)
    ;MsgBox(0, "", $item_txt)
    GUISetState(@SW_SHOW, $drag_gui)
    While _IsPressed(1)
     chase()
    WEnd
    GUISetState(@SW_HIDE, $drag_gui)
    _WinAPI_ShowCursor(True)
    SplashOff()
    ; Get new position
    Local $newcinfo = GUIGetCursorInfo(WinGetHandle($MainForm))
    ; If we were moving from source to destination and we ARE in the destination box
    If $direction = 1 And $newcinfo[4] = GUICtrlGetHandle($list_target) Then
     ConsoleWrite("Moved " & $iselecteditems & " items from source to destination" & @CRLF)
     _GUICtrlListView_CopyItems($list_source, $list_target, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $direction = 2 And $newcinfo[4] = GUICtrlGetHandle($list_source) Then
     ConsoleWrite("Moved " & $iselecteditems & " items from destination to source" & @CRLF)
     _GUICtrlListView_CopyItems($list_target, $list_source, 1)
    EndIf

                 _DebugPrint("$LVN_BEGINDRAG" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                         "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                         "-->Code:" & @TAB & $iCode & @LF & _
                         "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                         "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                         "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                         "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                         "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                         "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                         "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                         "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
      ;_dragHandler($hWndFrom)
                 ; No return value
             Case $LVN_BEGINRDRAG ; A drag-and-drop operation involving the right mouse button is being initiated
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 _DebugPrint("$LVN_BEGINRDRAG" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                         "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                         "-->Code:" & @TAB & $iCode & @LF & _
                         "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                         "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                         "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                         "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                         "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                         "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                         "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                         "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                 ; No return value
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
   "!===========================================================" & @LF & _
   "+======================================================" & @LF & _
   "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
   "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by Belini
Link to post
Share on other sites

Not to nitpick, but I would suggest changing the hotkeyset to GUISetAccelerators. If you highlight an item, go into a completely different window, and hit an arrow, it will still copy the items.

Using hotkeyset will also completely block the use of the arrow keys as normal buttons (this can be coded around, but would still change it to GUISetAccelerators).

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

I have not learned how to use the command GUISetAccelerators

EDITED: I made another way

; Includes first! Must must must!
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Misc.au3>
#include <SendMessage.au3>
; Switch on the 'onEvent' notifications
Opt("GUIOnEventMode", 1)
Opt("PixelCoordMode", 2)
; Generate the GUI! Ahoy there.
Global $gw = 16
Global $gh = 16
Global $Startx, $Starty, $Endx, $Endy, $aM_Mask, $aMask, $nc
Global $MainForm, $list_source, $list_target, $drag_gui, $hSplash
local $arrows = 0, $hDLL = DllOpen("user32.dll")
AdlibRegister("arrows", 5)
$MainForm = GUICreate(" TEST! ", 517, 178)
; Source list box
$list_source = _GUICtrlListView_Create($MainForm, "Title|Details", 13, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
; Target list box
$list_target = _GUICtrlListView_Create($MainForm, "Title|Details", 261, 16, 240, 136, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING))
; Populate box with some test stuff
$text = GUICtrlCreateLabel("Use the arrows to add or remove items from the list.", 100, 159, 330, 30)
GUICtrlSetBkColor($text, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont($text,11)
func arrows()
while 1
If _IsPressed("25", $hDLL) Then $arrows = 1
If _IsPressed("27", $hDLL) Then $arrows = 2
if not _IsPressed("25", $hDLL) and  not _IsPressed("27", $hDLL) then ExitLoop
wend
if $arrows = 1 then _GUICtrlListView_CopyItems ($list_target , $list_source, 1)
if $arrows = 2 then _GUICtrlListView_CopyItems ($list_source , $list_target, 1)
$arrows = 0
EndFunc
For $i = 0 To 4
   $item = _GUICtrlListView_AddItem($list_source, _makeJunkName())
   _GUICtrlListView_AddSubItem($list_source, $item, _makeJunkName(), 1)
Next

; Handle GUI events
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetOnEvent($GUI_EVENT_CLOSE, "_formEvents")
$drag_gui = GUICreate("Drag", $gw, $gh, 300, 300, BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST), $MainForm)
$cursor_icon = GUICtrlCreateIcon("Shell32.dll", -147, 0, 0, 16, 16)
GUISetState(@SW_SHOW, $drag_gui)
setTrans()
GUISetState(@SW_HIDE, $drag_gui)
GUISetState(@SW_SHOW, $MainForm)
; Main program loop
While 1
Sleep(10)
WEnd
; Function to handle other form events
Func chase()
$mp = MouseGetPos()
_WinAPI_UpdateWindow($MainForm)
_WinAPI_UpdateWindow($drag_gui)
WinMove($drag_gui, "", $mp[0] + 0, $mp[1] + 0)
;ToolTip($moving_txt, $mp[0] + 18, $mp[1])
WinMove($hSplash, "", $mp[0] + 28, $mp[1] + 0)
EndFunc   ;==>chase
Func _formEvents()
   Exit
EndFunc   ;==>_formEvents
Func setTrans()
  $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 460, "long", 460)
  $rct = DllStructCreate("int;int;int;inr", $aM_Mask[0])
  $TestCol = PixelGetColor(0, 0)
  $Startx = -1
  $Starty = -1
  $Endx = 0
  $Endy = 0
  For $i = 0 To $gw
    For $j = 0 To $gh
     If PixelGetColor($i, $j) = $TestCol And $j < $gh Then
      If $Startx = -1 Then
       $Startx = $i
       $Starty = $j
       $Endx = $i
       $Endy = $j
      Else
       $Endx = $i
       $Endy = $j
      EndIf
     Else
      If $Startx <> -1 Then addRegion()
      $Startx = -1
      $Starty = -1
     EndIf
    Next
  Next
  DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $drag_gui, "long", $aM_Mask[0], "int", 1)
EndFunc   ;==>setTrans
Func addRegion()
$aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $Startx, "long", $Starty, "long", $Endx + 1, "long", $Endy + 1)
$nc += 1
DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 3)
EndFunc   ;==>addRegion
; Create a junk name for testing
Func _makeJunkName()
Local $labelout = ''
For $i = 1 To 10
  $labelout &= Chr(Random(65, 90, 1))
Next
Return $labelout
EndFunc   ;==>_makeJunkName
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $item_txt
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
$hWndListView = $hWndFrom
If Not IsHWnd($hWndFrom) Then $hWndListView = GUICtrlGetHandle($hWndFrom)
Switch $hWndFrom
  Case $hWndListView
   Switch $iCode
    Case $LVN_BEGINDRAG ; A drag-and-drop operation involving the left mouse button is being initiated
                $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
    If $hWndFrom = $list_source Then
     $direction = 1
    ElseIf $hWndFrom = $list_target Then
     ; Or are we moving from destination to source
     $direction = 2
    Else
     MsgBox(0, "", "bad")
    EndIf
    $aidx = _GUICtrlListView_GetSelectedIndices($hWndFrom, True)
    $iselecteditems = $aidx[0]
    ;retrieve all item text, not just first item
    For $i = 1 To $aidx[0]
     $item_txt &= _GUICtrlListView_GetItemText($hWndFrom, $aidx[$i]) & @CRLF
    Next
    $item_txt = StringStripWS($item_txt, 1+2)
    _WinAPI_ShowCursor(False)
    ;$atemp = _GUICtrlListBox_GetItemRect($cinfo[4], Int($idx))
    $atemp = _GUICtrlListView_ApproximateViewRect($hWndFrom, $iselecteditems)
    $hSplash = SplashTextOn("", $item_txt, $atemp[0] - 10, $atemp[1] - 5, -1, -1, 1+32, "", 12)
    Sleep(5)
    ;MsgBox(0, "", $item_txt)
    GUISetState(@SW_SHOW, $drag_gui)
    While _IsPressed(1)
     chase()
    WEnd
    GUISetState(@SW_HIDE, $drag_gui)
    _WinAPI_ShowCursor(True)
    SplashOff()
    ; Get new position
    Local $newcinfo = GUIGetCursorInfo(WinGetHandle($MainForm))
    ; If we were moving from source to destination and we ARE in the destination box
    If $direction = 1 And $newcinfo[4] = GUICtrlGetHandle($list_target) Then
     ConsoleWrite("Moved " & $iselecteditems & " items from source to destination" & @CRLF)
     _GUICtrlListView_CopyItems($list_source, $list_target, 1)
    EndIf
    ; If we are moving from destination to source and we ARE in source box
    If $direction = 2 And $newcinfo[4] = GUICtrlGetHandle($list_source) Then
     ConsoleWrite("Moved " & $iselecteditems & " items from destination to source" & @CRLF)
     _GUICtrlListView_CopyItems($list_target, $list_source, 1)
    EndIf

                 _DebugPrint("$LVN_BEGINDRAG" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                         "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                         "-->Code:" & @TAB & $iCode & @LF & _
                         "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                         "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                         "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                         "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                         "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                         "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                         "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                         "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
      ;_dragHandler($hWndFrom)
                 ; No return value
             Case $LVN_BEGINRDRAG ; A drag-and-drop operation involving the right mouse button is being initiated
                 $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                 _DebugPrint("$LVN_BEGINRDRAG" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                         "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                         "-->Code:" & @TAB & $iCode & @LF & _
                         "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _
                         "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                         "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                         "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                         "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                         "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                         "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                         "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
                 ; No return value
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _DebugPrint($s_text, $line = @ScriptLineNumber)
ConsoleWrite( _
   "!===========================================================" & @LF & _
   "+======================================================" & @LF & _
   "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
   "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by Belini
Link to post
Share on other sites

Fantastic work!! Thanks so much for the help on this! I really like the way this looks and works. I'll be ultimately using this as a file copy utility to drag a file name from one side (folder source) to the other side (folder destination) and this is perfect.

Thanks again for the help!! ;)

Link to post
Share on other sites

@Belini, this is what I mean by GUISetAccelerators...

(put up by GUICreate)

$left = GUICtrlCreateDummy()
GUICtrlSetOnEvent($left, "leftpressed")
$right = GUICtrlCreateDummy()
GUICtrlSetOnEvent($right, "rightpressed")
Dim $aHotkey[2][2] = [["{LEFT}", $left],["{RIGHT}", $right]]
GUISetAccelerators($aHotkey)

Then somewhere put your funcs...

Func leftpressed()
;MsgBox(0, "", "left pressed")
_GUICtrlListView_CopyItems($list_target, $list_source, 1)
EndFunc
Func rightpressed()
;MsgBox(0, "", "right pressed")
_GUICtrlListView_CopyItems($list_source, $list_target, 1)
EndFunc

Much cleaner that way.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd
Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By UEZ
      This project has been discontinued!
       
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from the live web site cannot be downloaded although they are visible!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.6 build 2020-09-23 beta.7z  (1557 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • By Cengokill
      Hi everyone,
      I have created a ListView that is in a tab, and I want to display an image in that tab, with the ListView on top.
      However, the image still appears on top of my ListView.
      If I remove the tabs everything works. 
      I looked at the autoit documentation and the <GuiListView.au3> documentation , I can't figure out how to display a background image, and put on top a ListView, inside a tab. 😥
      Here is the code:
      Opt("GUIOnEventMode", 1) $Form1 = GUICreate($Titre, 700, 627, $Form1Width, $Form1Height); main window $tabulation = GUICtrlCreateTab(148,0,700,580); creating tabs $tab1=GUICtrlCreateTabItem("Tab 1"); first tab GUICtrlSetState(-1, $GUI_SHOW); this tab is selected by default $Pic1 = GUICtrlCreatePic("image.jpg", 0, 30, 700, 627) GUICtrlSetState(-1, $GUI_DISABLE). $idListview = GUICtrlCreateListView("list 1|list 2|list 3", 200, 50, 390, 200) GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Thank you in advance.

    • By DrJohn
      Hello all.  It's me again.
      I've got a ListView with an associated ImageList to display icons.  What I seem to be hung up on is how to keep the ImageList updated to match the ListView as the latter changes.  I thought it was the case that the indices of the items in the ListView and those in the ImageList just needed to match.  So, for example, if I:
      Delete an item from the ListView [_GUICtrlListView_DeleteItem()], and also delete the image at the matching index in the ImageList [_GUIImageList_Remove()]. Then add a new item to the end of the ListView [_GUICtrlListView_AddItem()], and correspondingly add an image at the end of the ImageList [_GUIImageList_AddIcon()] Shouldn't everything stay in sync?
      Here's the code I thought would work:
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <GuiImageList.au3> Test() func Test() $gui = GUICreate("Test", 400, 300) ; Create ListView $lv = _GUICtrlListView_Create($gui, "", 10, 10, 380, 240, $LVS_DEFAULT) _GUICtrlListView_AddColumn($lv, "Col1", 50) _GUICtrlListView_AddColumn($lv, "Col2", 50) for $i = 0 to 2 $s = StringFormat("%d,1", $i+1) _GUICtrlListView_AddItem($lv, $s, $i) $s = StringFormat("%d,2", $i+1) _GUICtrlListView_AddSubItem($lv, $i, $s, 1) next ; Add ImageList $img_list = _GUIImageList_Create(16, 16, 5, 3) for $i = 0 to 2 $ico = StringFormat("%d.ico", $i+1) _GUIImageList_AddIcon($img_list, $ico) next _GUICtrlListView_SetImageList($lv, $img_list, 1) ; $btn = GUICtrlCreateButton("Test", 10, 260, 60, 30) GUISetState(@SW_SHOW) HotKeySet("^q", Quit) ; Loop until the user exits. while True switch GUIGetMsg() case $GUI_EVENT_CLOSE Exit case $btn ; Remove 2nd list item and image _GUICtrlListView_DeleteItem($lv, 1) _GUIImageList_Remove($img_list, 1) ; Add new item to end of ListView $idx = _GUICtrlListView_AddItem($lv, "foo") _GUICtrlListView_AddSubItem($lv, $idx, "bar", 1) ; Add new image to end of ImageList _GUIImageList_AddIcon($img_list, "5.ico") endswitch wend GUIDelete() endfunc func Quit() Exit endfunc What seems to happen is that when the new item is added to the ListView, its icon is 1.ico (the first item in the ImageList), rather than 5.ico (the newly added item that should be at the end of the ImageList).
      Or do I need to re-create the whole ImageList any time the ListView changes?
      A zip file is attached that contains the script and also the .ico files, for easier testing.
      Thanks!
      /John
      test.zip
    • By Dan_555
      Hi.
      I'm using the FreeCommander XE file manager here, and i'v written a script, which will create an empty, new file, after choosing an extension out from the Listbox.
       
      The listview code  is not mine, iv found the scripts somewhere on this forum. I have no credits in it, because it was intended to be only for my personal use.
      But now, i have a lot of free time, so i remembered that i haven't posted anything on this forum, yet, so here is my first script:
      It should be compiled with the Autoit v3.3.14.3 .
      The compiled exe needs a folder passed as a parameter, so that it know where to create the new file.
      A Listbox is opened, with a selection of available extensions.
      After selecting and doubleclicking (or using the ok button), the script creates a filename (if specified in the config file) with increased numbers (up to 9999).
      If the filename exist, the counter is checking the next number, until the maximum is reached.
      This script uses an ini file for configuration, called "NewFile.ini" which should be in the same folder, as the compiled exe.
      NewFile.au3
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <String.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <ScrollBarsConstants.au3> Global $test[0][2], $hFile, $cmd = "", $cmdtmp, $tmptxt, $tmpinidir, $filesetting, $MouseX, $MouseY, $UseMouseX, $UseMouseY, $Edit1 Global $aArray[1] = [] $cmdtmp = StringReplace($cmdlineraw, Chr(34), "") If StringLen($cmdtmp) = 2 Then     If StringRight($cmdtmp, 1) = ":" Then         $cmd = $cmdtmp & "\"     EndIf Else     If StringRight($cmdtmp, 1) <> "\" Or StringRight($cmdtmp, 1) <> "/" Then         $cmd = $cmdtmp & "\"     EndIf EndIf If Not FileExists($cmd) Then                    ;Check if the folder exists, display an error message if not !     DisplayReadMe(1)     Exit EndIf If StringLen(@ScriptDir) > 3 And StringRight(@ScriptDir, 1) <> "\" Then     $tmpinidir = @ScriptDir & "\" Else     $tmpinidir = @ScriptDir EndIf Local Const $sFilePath = $tmpinidir & "NewFile.ini" $filesetting = IniRead($sFilePath, "setting", "filename", "MyNewFile") $filesetting = StringReplace($filesetting, ">", " ") ;msgbox (0,"",$filesetting)  ;Debugging If FileExists($sFilePath) Then     $aArray = IniReadSectionNames($sFilePath) ; Read the INI section names. This will return a 1 dimensional array. EndIf $UseMouseX = IniRead($sFilePath, "setting", "UseMouseX", "1") $UseMouseY = IniRead($sFilePath, "setting", "UseMouseY", "0") ; Check if an error occurred. If Not @error Then     ; Enumerate through the array displaying the section names.     Local $count = 0     If FileExists($sFilePath) Then         For $i = 1 To $aArray[0]             $tmp1 = IniRead($sFilePath, $aArray[$i], "1", "none")             If $tmp1 <> "none" And StringLeft($tmp1, 1) = "." Then            ;Extension need to have a dot, or it will be ignored !                 $tmptxt = $tmptxt & $tmp1 & "|" & $aArray[$i] & @CRLF                 $count = $count + 1                                            ;Count how many extensions are added !             EndIf         Next     EndIf     If $count = 0 Then $tmptxt = ".au3|AutoIt 3" & @CRLF & ".txt|Text File" & @CRLF     ;MsgBox($MB_SYSTEMMODAL,"",$tmptxt)     _ArrayAdd($test, $tmptxt, 0, "|", @CRLF) Else                                                            ;Reading the ini failed, create a default array for the extensions     $tmptxt = ".au3|AutoIt 3" & @CRLF & ".txt|Text" & @CRLF     _ArrayAdd($test, $tmptxt, 0, "|", @CRLF) EndIf ;Local $test[5][2] = [['.au3', 'AutoIt'], ['.ahk', 'Auto Hotkey'], ['.txt', 'text'], ['.sdlbas', 'Sdl Basic'], ['.html', 'Webpage']] If $UseMouseX = 1 Then     $MouseX = MouseGetPos(0) Else     $MouseX = -1 EndIf If $UseMouseY = 1 Then     $MouseY = MouseGetPos(1) Else     $MouseY = -1 EndIf $Form1 = GUICreate("Create New File", 210, 247, $MouseX, $MouseY, $WS_CAPTION, $WS_EX_TOOLWINDOW) $List = GUICtrlCreateListView("", 5, 5, 200, 200) _GUICtrlListView_InsertColumn($List, 0, "Extension", 65) _GUICtrlListView_InsertColumn($List, 1, "Description", 115) _GUICtrlListView_AddArray($List, $test) GUICtrlCreateLabel("Example:" & $filesetting & "0000.ext", 5, 205) $Button1 = GUICtrlCreateButton("Ok", 16, 224, 45, 22) $Button3 = GUICtrlCreateButton("ReadMe", 80, 224, 55, 22) $Button2 = GUICtrlCreateButton("Cancel", 150, 224, 45, 22) $cDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1     $nMsg = GUIGetMsg()     Switch $nMsg         Case $GUI_EVENT_CLOSE, $Button2             Exit         Case $Button3             DisplayReadMe(0)         Case $Button1, $cDummy             Local $tmptxt = StringSplit(_GUICtrlListView_GetItemTextString($List), "|")[1]             If StringLen($tmptxt) > 0 Then                 Local $fnr = 0, $tmpfile = ""                 While $fnr < 10000                     $tmpfile = $cmd & $filesetting & _StringRepeat("0", 4 - StringLen($fnr)) & $fnr & $tmptxt                     ;MsgBox(0,"",$tmpfile) ; for debugging                     If Not (FileExists($tmpfile)) Then                         $hFile = _WinAPI_CreateFile($tmpfile, 0)                         _WinAPI_CloseHandle($hFile)                         Exit                     EndIf                     $fnr = $fnr + 1                 WEnd             EndIf     EndSwitch WEnd ;================================================================================ Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)     Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView     $hWndListView = $List     If Not IsHWnd($List) Then $hWndListView = GUICtrlGetHandle($List)     $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)     $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))     $iCode = DllStructGetData($tNMHDR, "Code")     Switch $hWndFrom         Case $hWndListView             Switch $iCode                 Case $NM_DBLCLK                     ; Fire the dummy if the ListView is double clicked                     GUICtrlSendToDummy($cDummy)             EndSwitch     EndSwitch     Return $GUI_RUNDEFMSG EndFunc   ;==>WM_NOTIFY Func DisplayReadMe($err)     Local $Form1 = GUICreate("Read Me", 550, 400, 10, 10, BitOR($WS_CAPTION, $WS_THICKFRAME ,$WS_MAXIMIZEBOX))     $Edit1 = GUICtrlCreateEdit("", 0, 0, 549, 399)     GUICtrlSetData(-1, "")     GUISetState(@SW_SHOW)     If $err=1 then         local $txttmp01="Error: Path does not exist"         local $txttmp02="Commandline call was: "         AddText ($txttmp01)         Addtext ($txttmp02 & $cmd & @CRLF & @CRLF)     EndIf     AddText("Instructions:" & @CRLF)     AddText("Displays a selection of available extensions and then creates a new file at the Path's location." & @CRLF & @CRLF & "Usage: NewFile Path")     AddText("Example: NewFile c:\myfolder\" & @CRLF)     AddText("Result: A file with a name 'MyFile0000.ext' will be created at the Path's location.")     AddText("If the filename exists, the number counter will increase, until it finds a free number, up to 9999." & @CRLF)     AddText("Uses a configuration file in the .exe folder named NewFile.ini !" & @CRLF)     AddText("Example of a config file:" & @CRLF)     AddText("[setting]" & @CRLF & "filename=MyFile>")     AddText("UseMouseX=0                ;0 or 1 - position the dialog at the mouse x coordinate - usefull for multi monitor settings !")     AddText("UseMouseY=0                ;0 or 1 - Set this and UseMouseX to spawn the dialog at the mouse coordinates !" & @CRLF)     AddText(";Use > in filename as a space char ! (only needed if you want the space char at the beginning or at the end : in between filename and the number)" & @CRLF)     AddText(";Format for this ini file is:" & @CRLF & ";Name              e.g [Auto It]")     AddText(";extension       e.g 1=.au3" & @CRLF & "; p.s. only 1 extension per section ! the number must be 1" & @CRLF)     AddText("[AutoIt3]" & @CRLF & "1=.au3" & @CRLF & @CRLF & "[Text]" & @CRLF & "1=.txt")     _GUICtrlEdit_SetSel($Edit1, 0, 0)     _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET)     If $err=1 Then         _GUICtrlEdit_SetSel($Edit1, 0, StringLen($txttmp01 & $txttmp02 & $cmd)+5)     EndIf     While 1         $nMsg = GUIGetMsg()         Switch $nMsg             Case $GUI_EVENT_CLOSE                 GUIDelete($Form1)                 ExitLoop         EndSwitch     WEnd EndFunc   ;==>DisplayReadMe Func AddText($edittxt)     _GUICtrlEdit_AppendText($Edit1, $edittxt & @CRLF) EndFunc   ;==>AddText  
       NewFile.ini
      [setting] filename=MyNewFile_ UseMouseX=0                ;0 or 1 - position the dialog at the mouse x coordinate - usefull for multi monitor settings ! UseMouseY=0                ;0 or 1 - Set this and UseMouseX to spawn the dialog at the mouse coordinates ! ;Use > in filename as a space char ! (only needed if you want the space char at the beginning or at the end : in between filename and the number) ;Format for this ini file is: ;Name              e.g [Auto It] ;extension       e.g 1=.au3 ; p.s. only 1 extension per section ! the number must be 1 [AutoIt3] 1=.au3 [Auto Hotkey] 1=.ahk [Text] 1=.txt [Sdl Basic] 1=.sdlbas [Webpage] 1=.html [Basic] 1=.bas [Pascal] 1=.pas [Rich Text (RTF)] 1=.rtf [Word Document] 1=.doc [Hex File] 1=.hex
    • By Miliardsto
      I have the following code. You can see there are $color_normal and $color_trans
      In my case normal is too dark . And color trans is to much violet.
      If you run it you will see how its looks. I want gui with listView have the same color like taskbar in windows 10.
      How to achieve that?
       
       
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> HotKeySet("{ESC}", "Terminate") $color_normal = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) $color_trans = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) $trans = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") ConsoleWrite("Transpart = " & $trans & @CRLF) ConsoleWrite("Color normal = " & $color_normal & @CRLF) ConsoleWrite("Color trans = " & $color_trans & @CRLF) ConsoleWrite(_Get_taskbar_color()); It return AARRGGBB $taskbarColor = _Get_taskbar_color() Global $gui = GUICreate("Test", 150, 58,@DesktopWidth-300,@DesktopHeight-58,$WS_POPUP,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) Global $idListview = GUICtrlCreateListView("", 0, 0, 150, 58,BitOR($LBS_NOTIFY,$LBS_SORT), 0) ;_GuiCtrlMakeTrans(-1,100) ; Add column _GUICtrlListView_AddColumn($idListview, "Msgs", 100) GUICtrlSetFont(-1, 7, 400, 0, "Segoe UI") GUICtrlSetColor(-1, 0x470C4F) GUICtrlSetBkColor($idListview, 0x310638) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Terminate() Exit EndFunc Func _Get_taskbar_color() If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "ColorPrevalence") Then If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) Else Return "0xFF" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) EndIf Else If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9000000" Else Return "0xFF000000" EndIf EndIf EndFunc  
×
×
  • Create New...