Post by hd0202 » 26 Nov 2014, 16:34
Thank you for this wunderful class (and for the wunderful SciTE4AutoHotkey, too) !!!
In order to learn about OOP with AutoHotkey and to get some experience I have converted the second (full) example of the TreeView section in the help and made some additions (folders and icons in the listview and doubleclick for treeview, listview and statusbar) and will share it here with this community:
Spoiler
#include <CCtrlLabel>
#include <CCtrlListView>
#include <CCtrlTreeView>
#include <CCtrlStatusBar>
#include <CPropImpl>
#include <CImageList>
AFC_Entrypoint(MyWin)
class MyWin extends CWindow
{
__New()
{
Random, ov, 1, 10000
base.__New("#" ov " - File Manager with AFC")
il := new CImageList(this, 5)
loop, 5
IL.AddImage("shell32.dll", A_Index)
this.TreeViewWidth := 280
tv := new CCtrlTreeView(this, "r20 w" this.TreeViewWidth)
tv.BindImageList(il)
tv.OnDoubleClick := this.tvDoubleClick
tv.OnSelect := this.tvSelect
tv.root := "D:\ahk_source" ; %A_StartMenuCommon%
tv.root := A_StartMenuCommon
this.tv := tv
this.ListViewWidth := A_ScreenWidth - this.TreeViewWidth - 30
lv := new CCtrlListView(this, "Name|Size|Modified", "x+10 r20 grid w" this.ListViewWidth)
lv.BindImageList(il)
lv.OnDoubleClick := this.lvDoubleClick
this.lv := lv
lv.AddRow(["Hello", "world!"])
this.Col2Width := 70
LV.ModifyCol(1, "N" this.ListViewWidth - this.Col2Width - 30)
LV.ModifyCol(2, "integer N" this.Col2Width)
tv.lv := lv
SplashTextOn, 200, 25, TreeView and StatusBar Example, Loading the tree...
this.AddSubFoldersToTree(tv.root, tv)
SplashTextOff
sb := new CCtrlStatusBar(this)
sb.OnClick := this.sbClick
SB.SetPartWidths(300, 85)
sb.SetPartText("Ready.!`tfoo.")
sb.SetPartText("Ready.", 2)
tv.sb := sb
this.setoptions("+resize")
this.onsize := this.guisize
this.onmaximize := this.guisize
this.Show()
AFC_AtExit(this.ExitRoutine1)
}
AddSubFoldersToTree(Ordner, tv, node := "")
{
Loop %Ordner%\*.*, 2 ; Retrieve all of Folder's sub-folders.
this.AddSubFoldersToTree(A_LoopFileFullPath, tv.Addnode(A_LoopFileName, "Icon4"))
}
lvDoubleClick(lv, row)
{
this.OwnDialogs()
MsgBox % lv.Item[row, 1] ", " lv.Item[row, 2]
lv.InsertRow(row+1, lv.RowData[row])
lv.AutoSizeCol()
}
tvDoubleClick(tv, node)
{
this.OwnDialogs()
t := "Children of " node.Text ":`n`n"
for i,child in node
t .= "[" i "]: " child.Text "`n"
MsgBox % t
}
sbClick(sb)
{
this.OwnDialogs()
MsgBox, Hey, you clicked me!
sb.SetPartText("You have already clicked me")
}
ExitRoutine1()
{
this.whatever := "Yeah, it worked."
MsgBox % this.whatever
}
tvselect(tv, node)
{
selecteditemtext := node.text
Loop
{
if !isobject(node.parent)
break
node := node.parent
parenttext := node.text
selecteditemtext = %parenttext%\%selecteditemtext%
}
SelectedFullPath := tv.root "\" selecteditemtext
tv.lv.clear()
tv.lv.setoptions("-Redraw")
SplashTextOn, 200, 25, TreeView and StatusBar Example, Folder is loading...
FolderCount = 0
Loop %SelectedFullPath%\*.*, 2
{
tv.LV.Addrow([A_LoopFileName, "", A_LoopFileTimeModified], "icon4")
FolderCount++
}
FileCount = 0
TotalSize = 0
Loop %SelectedFullPath%\*.*
{
tv.LV.Addrow([A_LoopFileName, A_LoopFileSize, A_LoopFileTimeModified], "icon1")
FileCount += 1
TotalSize += A_LoopFileSize
}
tv.lv.setoptions("+Redraw")
tv.lv.AutoSizeCol()
SplashTextOff
total := Round(TotalSize / 1024)
tv.SB.SetPartText(FileCount . (filecount = 1 ? " File" : " Files") . " / "
. FolderCount . (foldercount = 1 ? " Folder" : " Folders"))
tv.SB.SetPartText(Total . " KB", 2)
tv.SB.SetPartText(SelectedFullPath, 3)
}
guisize(w, h)
{
this.tv.move("H" . (h - 30))
this.lv.move("H" . (h - 30) . " W" . (w - this.tv.position.w - 30)) ; TreeViewWidth - 30))
}
}
During this development I got the following error message:
Spoiler
Error in #include file "D:\ahk_source\forum\AFC2\Lib\CWindow.ahk":
Parameter #2 invalid.
Line#
061: pCtrl := &oCtrl, ctrlName := oCtrl.__CtrlName, glabelAttr := "g__CWindowGlabel"
064: if ctrlName in Progress,GroupBox
065: glabelAttr := ""
066: if !ctrlname
067: ctrlName := hud_ctrlname
068: if !ctrlname
069: ctrlName := octrl.special
---> 071: Gui,%h%:Add,%ctrlName%,hwndctrlHwnd %glabelAttr% v#%pCtrl% %options%,value
072: #%pCtrl% := ""
073: this.__Controls[ctrlHwnd] := oCtrl
074: Return,ctrlHwnd
075: }
078: {
079: h := this.__Handle
080: GuiControl,%h%:%cmd%,%ctrlID%,value
The current thread will exit.
Debugging with SciTE4AutoHotkey showed that the field in the "tv" object contained "TreeView", but the field "ctrlName" is
empty.
This also occurred with the listview and can also be produced with the AFC "Example-Many-Controls.ahk". Additional the event handlers like OnDoubleClick and OnSelect also do not work though the labels are contained in the objects. I think it is them same cause: when the handler is called the label field is empty. On the other side, Button, Edit, UpDown and Statusbar in the example (and Progress from the other example) work without problems.
In these tests I used
V1.1.16.04 to V1.1.16.06 in the modes A32, U32 and U64 on XP, Win7 and Win8.1.
Then I checked
V1.1.14.03, my previous AHK version, in the same modes on the same systems
and it works, so that I could finish my development.
I think this is a bug in the last versions and I wonder if it should be posted in the appropriate section?For the above noted errors I found a workaround with global variables and a change in CWindow class, but this does not work for event handlers.
Hubert
Thank you for this wunderful class (and for the wunderful SciTE4AutoHotkey, too) !!!
In order to learn about OOP with AutoHotkey and to get some experience I have converted the second (full) example of the TreeView section in the help and made some additions (folders and icons in the listview and doubleclick for treeview, listview and statusbar) and will share it here with this community:
[spoiler]#include <CCtrlLabel>
#include <CCtrlListView>
#include <CCtrlTreeView>
#include <CCtrlStatusBar>
#include <CPropImpl>
#include <CImageList>
AFC_Entrypoint(MyWin)
class MyWin extends CWindow
{
__New()
{
Random, ov, 1, 10000
base.__New("#" ov " - File Manager with AFC")
il := new CImageList(this, 5)
loop, 5
IL.AddImage("shell32.dll", A_Index)
this.TreeViewWidth := 280
tv := new CCtrlTreeView(this, "r20 w" this.TreeViewWidth)
tv.BindImageList(il)
tv.OnDoubleClick := this.tvDoubleClick
tv.OnSelect := this.tvSelect
tv.root := "D:\ahk_source" ; %A_StartMenuCommon%
tv.root := A_StartMenuCommon
this.tv := tv
this.ListViewWidth := A_ScreenWidth - this.TreeViewWidth - 30
lv := new CCtrlListView(this, "Name|Size|Modified", "x+10 r20 grid w" this.ListViewWidth)
lv.BindImageList(il)
lv.OnDoubleClick := this.lvDoubleClick
this.lv := lv
lv.AddRow(["Hello", "world!"])
this.Col2Width := 70
LV.ModifyCol(1, "N" this.ListViewWidth - this.Col2Width - 30)
LV.ModifyCol(2, "integer N" this.Col2Width)
tv.lv := lv
SplashTextOn, 200, 25, TreeView and StatusBar Example, Loading the tree...
this.AddSubFoldersToTree(tv.root, tv)
SplashTextOff
sb := new CCtrlStatusBar(this)
sb.OnClick := this.sbClick
SB.SetPartWidths(300, 85)
sb.SetPartText("Ready.!`tfoo.")
sb.SetPartText("Ready.", 2)
tv.sb := sb
this.setoptions("+resize")
this.onsize := this.guisize
this.onmaximize := this.guisize
this.Show()
AFC_AtExit(this.ExitRoutine1)
}
AddSubFoldersToTree(Ordner, tv, node := "")
{
Loop %Ordner%\*.*, 2 ; Retrieve all of Folder's sub-folders.
this.AddSubFoldersToTree(A_LoopFileFullPath, tv.Addnode(A_LoopFileName, "Icon4"))
}
lvDoubleClick(lv, row)
{
this.OwnDialogs()
MsgBox % lv.Item[row, 1] ", " lv.Item[row, 2]
lv.InsertRow(row+1, lv.RowData[row])
lv.AutoSizeCol()
}
tvDoubleClick(tv, node)
{
this.OwnDialogs()
t := "Children of " node.Text ":`n`n"
for i,child in node
t .= "[" i "]: " child.Text "`n"
MsgBox % t
}
sbClick(sb)
{
this.OwnDialogs()
MsgBox, Hey, you clicked me!
sb.SetPartText("You have already clicked me")
}
ExitRoutine1()
{
this.whatever := "Yeah, it worked."
MsgBox % this.whatever
}
tvselect(tv, node)
{
selecteditemtext := node.text
Loop
{
if !isobject(node.parent)
break
node := node.parent
parenttext := node.text
selecteditemtext = %parenttext%\%selecteditemtext%
}
SelectedFullPath := tv.root "\" selecteditemtext
tv.lv.clear()
tv.lv.setoptions("-Redraw")
SplashTextOn, 200, 25, TreeView and StatusBar Example, Folder is loading...
FolderCount = 0
Loop %SelectedFullPath%\*.*, 2
{
tv.LV.Addrow([A_LoopFileName, "", A_LoopFileTimeModified], "icon4")
FolderCount++
}
FileCount = 0
TotalSize = 0
Loop %SelectedFullPath%\*.*
{
tv.LV.Addrow([A_LoopFileName, A_LoopFileSize, A_LoopFileTimeModified], "icon1")
FileCount += 1
TotalSize += A_LoopFileSize
}
tv.lv.setoptions("+Redraw")
tv.lv.AutoSizeCol()
SplashTextOff
total := Round(TotalSize / 1024)
tv.SB.SetPartText(FileCount . (filecount = 1 ? " File" : " Files") . " / "
. FolderCount . (foldercount = 1 ? " Folder" : " Folders"))
tv.SB.SetPartText(Total . " KB", 2)
tv.SB.SetPartText(SelectedFullPath, 3)
}
guisize(w, h)
{
this.tv.move("H" . (h - 30))
this.lv.move("H" . (h - 30) . " W" . (w - this.tv.position.w - 30)) ; TreeViewWidth - 30))
}
}[/spoiler]
During this development I got the following error message:
[spoiler]Error in #include file "D:\ahk_source\forum\AFC2\Lib\CWindow.ahk":
Parameter #2 invalid.
Line#
061: pCtrl := &oCtrl, ctrlName := oCtrl.__CtrlName, glabelAttr := "g__CWindowGlabel"
064: if ctrlName in Progress,GroupBox
065: glabelAttr := ""
066: if !ctrlname
067: ctrlName := hud_ctrlname
068: if !ctrlname
069: ctrlName := octrl.special
---> 071: Gui,%h%:Add,%ctrlName%,hwndctrlHwnd %glabelAttr% v#%pCtrl% %options%,value
072: #%pCtrl% := ""
073: this.__Controls[ctrlHwnd] := oCtrl
074: Return,ctrlHwnd
075: }
078: {
079: h := this.__Handle
080: GuiControl,%h%:%cmd%,%ctrlID%,value
The current thread will exit.[/spoiler]
Debugging with SciTE4AutoHotkey showed that the field in the "tv" object contained "TreeView", but the field "ctrlName" is [b]empty[/b].
This also occurred with the listview and can also be produced with the AFC "Example-Many-Controls.ahk". Additional the event handlers like OnDoubleClick and OnSelect also do not work though the labels are contained in the objects. I think it is them same cause: when the handler is called the label field is empty. On the other side, Button, Edit, UpDown and Statusbar in the example (and Progress from the other example) work without problems.
In these tests I used [b]V1.1.16.04 to V1.1.16.06[/b] in the modes A32, U32 and U64 on XP, Win7 and Win8.1.
Then I checked [b][color=#FF4000]V1.1.14.03[/color][/b], my previous AHK version, in the same modes on the same systems [b]and it works[/b], so that I could finish my development.
[b]I think this is a bug in the last versions and I wonder if it should be posted in the appropriate section?[/b]
For the above noted errors I found a workaround with global variables and a change in CWindow class, but this does not work for event handlers.
Hubert