Page 1 of 1

AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP GUI)

Posted: 30 Jan 2014, 17:56
by fincs
[Repost]

AFC is a thin object-oriented wrapper around some of AutoHotkey's functionality. It mainly takes care of wrapping long-time present commands and functions that use old and quirky paradigms into a saner and cleaner class-based API.

AFC is designed to be modular, and to be as direct as possible with the original API. This translates to not having otherwise obvious properties that are implemented through flexi-lists. I believe that the performance and code size penalty is not justified.

AFC provides:
  • Structured class-based entry points.
  • GUI API
  • Default base object, which provides OOP syntax sugar for non-object values (such as str.Length)
AFC will provide in the future:
  • Menus
  • Timers
  • Hotkeys and hotstrings (perhaps?)
Download - GitHub - Documentation (Download documentation)

AFC's GUI API gets completely rid of:
  • g-labels and Gui event labels.
  • Associated variable names.
  • Gui names/numbers.
  • Confusing subcommands.
Feel free to comment. Hope you enjoy! :D

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 30 Jan 2014, 23:26
by Guest10
any examples using AFC? :D

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 31 Jan 2014, 05:47
by fincs
The downloadable package contains 4 examples, their source can also be found online at GitHub.

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 31 Jan 2014, 08:32
by Guest10
thanks, looks like AFC-master.zip includes library, documentation and examples all in one package.

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 26 Nov 2014, 16:34
by hd0202
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
During this development I got the following error message:
Spoiler
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

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 08 Dec 2014, 00:39
by hd0202
bump

did anyone of the nearly 150 viewers test my code or fincs' example?

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 09 Dec 2014, 15:31
by T-Rock
First of all thank you for sharing this cool classes.

I can can confirm the error with ListView and the problem with the ListView Events, which do not work.
I am using V1.1.16.05 U32 with Win7.
But I think I made it work with the following changes:
I changed in the file CCtrlListView.ahk the line 16 from
static __CtrlName := "ListView"
to
__CtrlName := "ListView"
This is somehow related to the sub class __Get (line 177). If you comment the sub class, the static works.

To make the events working, I changed in the file CWindow.ahk the line 444 from
oCtrl.OnEvent.(__CWindow_GetGui(), oCtrl, A_GuiEvent, A_EventInfo)
to
oCtrl.OnEvent(__CWindow_GetGui(), oCtrl, A_GuiEvent, A_EventInfo)
by removing the second dot, which with my understanding changes it from a function reference to a method call.
With this change I had to change also the line 480 in the file CCtrlListView.ahk from
OnEvent(oCtrl, guiEvent, eventInfo)
to
OnEvent(oGui, oCtrl, guiEvent, eventInfo)
Because the hidden "this" did not work here.
Therefore I changed also everywhere in this method "this" to "oGui".

This works for me, but maybe somebody can verify what I did (fincs?).
By the way this is a great example, which made me learning a lot about many specials around classes by studying it. ;)

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 09 Dec 2014, 17:09
by fincs
I suspect this to be an AHK bug.

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 09 Dec 2014, 21:26
by Joe Glines
My only complaint is that this wasn't available a few years ago when I was playing with guis. This will definitely make it much quicker to create new scripts and keep them updated. Thanks fincs! :D

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP G

Posted: 12 Dec 2014, 15:50
by hd0202
I have a gui with 10 listviews as tabs like

Code: Select all

	Gui, Add, Tab2,x0 y0 w1200 h300 buttons gtab vTab, 1|2|3|4|5|6|7|8|9|10
	ztab = 1
	loop 10
	{
		Gui,Tab, %ztab%
                ...
		Gui, Add, ListView, x5 y81 w900 h560 Count5000 Report gOpen vzlistview%A_Index% hwndhlistview%a_index% -readonly -lv0x20 altsubmit, File|Modified|Size|Type
                ...
		ztab++
	}
	ztab = 1
	gui, tab
and I use the following subroutine, triggered by a menu, to enable the first field to inline editing:

Code: Select all

Rename:
	Gui,Tab,%zTab%                     
	gui, listview, zlistview%ztab%
	RowNumber := LV_GetNext()     
	lv_modify(rownumber, "Focus")
	LV_GetText(renameoldName,RowNumber)           
	hlistview := hlistview%ztab%
	sendmessage, 0x1017, rownumber - 1, 0, , ahk_id %hlistview%	; lvm_editlabela
return
I am converting this code to AutoHotkey Foundation Classes, and I have problems to get the value for ahk_id in the sendmessage command.

Here is part of my CWindow class

Code: Select all

class MyWin extends CWindow
{
	__New()
	{
		base.__New("title")
		ctrlTab := new CCtrlTab(this, "1|2|3|4|5|6|7|8|9|10", "x0 y0 w600 h300 buttons altsubmit")
		loop, 10
		{
			ctrlTab.BeginDef(a_index)
                        ...
			this.listview["" a_index] := new CCtrlListView(this, "File|Modified|Size|Type|", "x5 y81 w830 h560 Count5000 Report")
                        ...
		}
		ctrlTab.EndDef()
                ...		
		this.Show()
	}
}
Can anyone here please lead me to the right direction? Thank you in advance.

Hubert

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP GUI)

Posted: 12 May 2017, 19:02
by Gilligan3816
I found the following issues while using the CCtrlListView class in the function OnEvent(oCtrl, guiEvent, eventInfo):

Code: Select all

__CCtrlListView_OnEvent_DoubleClick:
__CCtrlListView_OnEvent_R:
return oCtrl.OnDoubleClick.(this, oCtrl, eventInfo, !!InStr(guiEvent, "R"))
Since InStr() is not case-sensitive by default, the last parameter in the return statement needs additional clarity. The idea was that it would search for "RightClick" by finding "R", and perhaps InStr() was case-insensitive at the time the library was written, however it now needs to either add the case-sensitive parameter to InStr() or search for "RightClick" instead of "R" -- possible solutions would be as follows:

Code: Select all

return oCtrl.OnDoubleClick.(this, oCtrl, eventInfo, !!InStr(guiEvent, "R", true))
return oCtrl.OnDoubleClick.(this, oCtrl, eventInfo, !!InStr(guiEvent, "RightClick"))
There are multiple lines in that file where this appears to be the case, including 488 and 501, however considering the number of functions that check GuiEvent in this file and possibly others, it is likely that this needs to be updated throughout the library.

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP GUI)

Posted: 12 May 2017, 19:28
by Gilligan3816
Upon further review, it appears that the syntax I mentioned above is only used in lines 488 and 501 in CCtrlListView.ahk and in line 505 in CCtrlTreeView.ahk. Regardless, I favor the solution where "RightClick" is used.

Re: AFC - AutoHotkey Foundation Classes v0.1 (Includes OOP GUI)

Posted: 02 Sep 2017, 14:25
by jeeswg
I get this error when I try to run Example-ManyControls.ahk:

Code: Select all

Error in #include file "C:\AFC-master\Lib\CWindow.ahk":
     Parameter #2 invalid.
...
--->	065: Gui,%h%:Add,%ctrlName%,hwndctrlHwnd %glabelAttr% v#%pCtrl% %options%,value
The problem is that the variable ctrlName is blank. A workaround (that works with the latest AHK, v1.1.26.01) is to add the following 4 lines:

Code: Select all

;add just below this line: pCtrl := &oCtrl, ctrlName := oCtrl.__CtrlName, glabelAttr := "g__CWindowGlabel"

if (ctrlName = "") && (options = "xs Section")
	ctrlName := "ListView"
else if (ctrlName = "") && (options = "r7")
	ctrlName := "TreeView"
I found that this script did work correctly using v1.1.15.02, but did not work correctly using v1.1.15.03.
See here to download old versions of AutoHotkey:
old versions of AutoHotkey - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=2&t=30206

The changelog says very little for this update:
Changes & New Features
https://autohotkey.com/docs/AHKL_Change ... v1.1.15.03
Fixed meta-functions to exit the thread correctly after using Exit or Throw.

Fixed FileInstall to use A_WorkingDir when Dest is relative in a non-compiled script.
I would be interested to understand why the problem occurs. Thanks for reading.