Jump to content
Sign in to follow this  
buymeapc

ListView Artifacts While Dragging

Recommended Posts

buymeapc

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

Share this post


Link to post
Share on other sites
buymeapc

*shameless bump*

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
buymeapc

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

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
buymeapc

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!

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
buymeapc

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!

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
Belini

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

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
Belini

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

Share this post


Link to post
Share on other sites
someone

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

Share this post


Link to post
Share on other sites
Belini

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

Share this post


Link to post
Share on other sites
buymeapc

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!! ;)

Share this post


Link to post
Share on other sites
someone

@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

Share this post


Link to post
Share on other sites
Belini

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
Sign in to follow this  

  • Similar Content

    • Broihon
      By Broihon
      Hey guys,

      I ran into a problem when I wanted to delete items of a listview using the delete key. My approach is to register my own WndProc for the listview and then filter the $WM_GETDLGCODE msg and then call the original WndProc.
      That works like a charm. The problem is that when the listview gets redrawn it somehow ends up in an infinite loop. The listview is suddenly emtpy and I can't interact with any controls of the GUI at all. Here's the code:
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WinAPI.au3> $h_GUI = GUICreate("Test", 200, 200, 350, 350) $h_LV = GUICtrlCreateListView("Col 1|Col 2|Col 3", 0, 0, 200, 200) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 0) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 1) _GUICtrlListView_AddSubItem($h_LV, 0, "bla0", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 0) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 1) _GUICtrlListView_AddSubItem($h_LV, 1, "bla1", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 0) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 1) _GUICtrlListView_AddSubItem($h_LV, 2, "bla2", 2) _GUICtrlListView_AddItem($h_LV, "") _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 0) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 1) _GUICtrlListView_AddSubItem($h_LV, 3, "bla3", 2) $h_LV_NewWndProc = DllCallbackRegister("WndProc_LV", "int", "hwnd;uint;wparam;lparam") $g_LV_OldWndProc = _WinAPI_SetWindowLong(GUICtrlGetHandle($h_LV), $GWL_WNDPROC, DllCallbackGetPtr($h_LV_NewWndProc)) GUISetState(@SW_SHOW) Func WndProc_LV($hWnd, $uMsg, $wParam, $lParam) Return _WinAPI_CallWindowProc($g_LV_OldWndProc, $hWnd, $uMsg, $wParam, $lParam) EndFunc ;==>WndProc_GUI Do Until GUIGetMsg() = $GUI_EVENT_CLOSE DllCallbackFree($h_LV_NewWndProc) As you can see I'm doing nothing in the WndProc of the listview. I'm simply calling the original WndProc. This still "freezes" when I mess with the width of the columns or in the original project when I add more items that they don't fit in the listview and I have to scroll. If I don't do that it's working fine.
    • c.haslam
      By c.haslam
      I have
      Local $idListview = GUICtrlCreateListView("",8,8,@DesktopWidth/2-16,@DesktopHeight-150,$LVS_SHOWSELALWAYS, _ $LVS_EX_INFOTIP) Local $hListView = GUICtrlGetHandle($idListview) _GUICtrlListView_InsertColumn($hListview, 0, "Filename", 400) _GUICtrlListView_InsertColumn($hListview, 1, "Ext", 50) _GUICtrlListView_InsertColumn($hListview, 2, "Size",70) _GUICtrlListView_InsertColumn($hListview, 3, 'Date time',100) _GUICtrlListView_InsertColumn($hListview, 4, "Path", 385) _GUICtrlListView_InsertColumn($hListview, 5, "sizeInt", 0) _GUICtrlListView_JustifyColumn($hListview, $kSize,1) ; right align then further on
      While True $sFnamExt = FileFindNextFile($iSrch) If @error Then ExitLoop EndIf $sAtts = FileGetAttrib($sPath&'\'&$sFnamExt) If StringInStr($sAtts,'D') Then If $sFnamExt<>'$RECYCLE.BIN' Then $sDirs &= '?'&$sPath&'\'&$sFnamExt EndIf Else $p = StringInStr($sFnamExt,'.',0,-1) ; last If $p=0 Then $sFnam = $sFnamExt $sExt = '' Else $sFnam = StringLeft($sFnamExt,$p-1) $sExt = StringTrimLeft($sFnamExt,$p) EndIf _GUICtrlListView_AddItem($hListview,$sFnam,-1,_GUICtrlListView_GetItemCount($hListview)+1000) _GUICtrlListView_AddSubItem($hListview,$nItem,$sExt,$kExt) $nSize = FileGetSize($sPath&'\'&$sFnamExt) $sSize = AddThousandsSeparator($nsize) _GUICtrlListView_AddSubItem($hListview,$nItem,$sSize,$kSize) _GUICtrlListView_AddSubItem($hListview,$nItem,$nsize,$kSizeInt) $nTotBytes += $nSize $a1 = FileGetTime($sPath&'\'&$sFnamExt,$FT_MODIFIED,$FT_ARRAY) $t = $a1[0]&'-'&$a1[1]&'-'&$a1[2]&' '&$a1[3]&':'&$a1[4] _GUICtrlListView_AddSubItem($hListview,$nItem,$t,$kDateTime) _GUICtrlListView_AddSubItem($hListview,$nItem,$sPath,$kPath) If $gSQL Then $s = "Insert into tbl values ("&_SQLite_Escape($sFnam)&","&_SQLite_Escape($sExt)&",'"& _ $sSize&"','"& _ $t&"',"&_SQLite_Escape($sPath)&","&$nSize&")" _SQLite_Exec(-1,$s) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf EndIf EndIf WEnd FileClose($iSrch) You will see that I heeded the advice in Help > _GUICtrlListView_AddItem: "As AutoIt uses the $iParam parameter to store the controlID of native-created ListView items, this value should be set sufficiently high for UDF-created items to avoid possible conflict with any existing controls - a starting value of 1000 is recommended."
      (It's unfortunate that the Example does not heed this advice. OK, it doesn't need to because there are no other controls, but still --- it would help neophytes if it did. Also to me _GUICtrlListView_AddItem is not native because it is a UDF. Confused?)
      My script then does a sort using SQLite, and updates the ListView:
      Local $hQuery Local $colNames = ['fnam','ext','nsize','dateTime','path','SizeInt'] Local $s = "Select * FROM tbl ORDER BY "&$colNames[$ncol]&';' _SQLite_Query(-1,$s, $hQuery) If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf Local $aRow[$kSizeInt+1] Local $iItem=-1 While _SQLite_FetchData($hQuery, $aRow, False, False) = $SQLITE_OK ; Read Out the next Row If @error Then MsgBox(0,@ScriptLineNumber,_SQLite_ErrMsg()) EndIf $iItem += 1 For $i = $kFnam To $kSizeInt _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default) Next WEnd This works, but I had earlier coded
      _GUICtrlListView_SetItem($hListview,$aRow[$i],$iItem,$i,Default,$iItem+1000) because the same advice is in the Help for this function.
      So my care in specifying $param back-fired! What am I not understanding?
      The only difference in what works is that the $param parameter is defaulted.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I am building a management for the company I work with, and I just imported a real amount of rows ( about 29000 ), in my SQLite DB.
      The thing I am not understanding, is the time that the script takes to build this amount of rows in the ListView.
      I didn't measure it, but I think it took 2 minutes or so to create each ListView item...
      It is normal that it takes so much time?
      What can I do to improve the creation of the items?

      Here's the code I am using to query and to create ListView items...
      ; Articles ListView: Global $lvwArticles = GUICtrlCreateListView("ID|Fornitore|Codice|Descrizione|EU|Prezzo|Sconto Applicato|Note", 14, 87, 1507, 660, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_SORTDESCENDING), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)) ; Query $strQuery = "SELECT * FROM ARTICOLI;" ; Query Execution _SQLite_GetTable2d($objDatabase, $strQuery, $arrResult, $intRows, $intColumns) If @error Then ; Error Handling Else ; Cleaning the ListView _GUICtrlListView_DeleteAllItems($lvwArticles) If @error Then ; Error Handling Else ; No records in the Table If UBound($arrResult) < 2 Then ; Error Handling Else _GUICtrlListView_BeginUpdate($lvwArticles) For $intCounter = 1 To UBound($arrResult) - 1 $strListViewItem = $arrResult[$intCounter][0] & "|" & _ $arrResult[$intCounter][1] & "|" & _ $arrResult[$intCounter][2] & "|" & _ $arrResult[$intCounter][3] & "|" & _ $arrResult[$intCounter][4] & "|" & _ $arrResult[$intCounter][5] & "|" & _ $arrResult[$intCounter][6] & "|" & _ $arrResult[$intCounter][7] $objListViewItem = GUICtrlCreateListViewItem($strListViewItem, $lvwArticles) Next _GUICtrlListView_EndUpdate($lvwArticles) EndIf EndIf EndIf Thanks in advance


      Best Regards.
    • Skysnake
      By Skysnake
      I am tracking this topic by @LarsJ.  It is very advanced and overkill for what I am currently trying to do.
       
      Problem is this.
      Listview contains columns, one of which is right aligned and gets populated by float values, such as 123.99.  Some do not have decimals ie 124.00 and on sort gets truncated to 124.  Its obviously still the same value, but the display has reset.
      ; line below is for list VIEW ;..................................0.........1......2............ $cListView = GUICtrlCreateListView("CUSTOMER|AMOUNT|DESCRIPTION", 8, 152, 764, 279) GUICtrlSetBkColor($cListView, $GUI_BKCOLOR_LV_ALTERNATE) ; alternate between the listview background color and the listview item background color GUICtrlSetBkColor($cListView, $LVStdClr) ; Set the background color for the listview _GUICtrlListView_SetColumnWidth($cListView, 0, 120) ; -- the client name _GUICtrlListView_SetColumnWidth($cListView, 1, 90) ;-- the amount _GUICtrlListView_JustifyColumn($cListView, 1, 1) ; 1 - Text is right aligned _GUICtrlListView_SetColumnWidth($cListView, 2, 200) ; the description What I am looking for is something native and simple like a 
          _GUICtrlListView_SetColumnFormat($cListView, 1, "%.2f") ;  1 - column is stringformatted to "%.2f"
      So that after each sort it will appear as it was in the original rendering.
      Is there something like this? I have not been able to find a simple solution.

      Thanks.
      Skysnake
    • Ambient
      By Ambient
      I have tried several way sto get this to work to no avail. Any help would be appreciated. #include <ListViewConstants.au3> #include <GuiListView.au3> #include "GuiListViewEx.au3" $idItem = GUICtrlCreateListViewItem($r & " | " & $c & $adoRs.Fields("TransactionAmount").value & " | " & $Timestamp & " | " & _StringProper($adoRs.Fields("Tillid").value) & @CRLF & @CRLF & "Card Number : " & $cardnum & " " , $idListView) ConsoleWrite( "IDITEM" & $idItem) If STRINGLEFT($adoRs.Fields("TransactionAmount").value,1)= "-" Then Consolewrite(" String is Negative" & @CRLF) ;Drops in Here as expected ;GUICtrlSetColor(-1, $COLOR_RED) ; Colour line if item is negative this didn' work $TxC= _GUICtrlListView_SetTextColor($hListView, $CLR_RED) ; I also tried $TxC= _GUICtrlListView_SetTextColor(-1, 0xFF0000) CONSOLEWRITE("TEXTCOLOUR RETURNED " & $TxC & @crlf) ; This is returning True ELSE Consolewrite(" String is NOT Negative" & @CRLF) EndIf  
×