Jump to content


Photo

CStruct Class (struct base class) - AHK_L


  • Please log in to reply
10 replies to this topic

#1 chaidy

chaidy
  • Members
  • 19 posts

Posted 20 March 2012 - 05:46 PM

This is 'CStruct_Base' Class for struct simple to use. this struct class concept from get MFC structure based class.(CRect, CPoint, ...)
- use normal type array and defined CStruct class array
- struct in struct (use defined CStruct class)
- simply check struct data by use TreeView() method
- bitfield var support (ver 5.0)
- string auto encoding with these type (ver 5.2): CHAR,TCHAR,STR,LPSTR,LPTSTR,LPCTSTR,WCHAR,LPWSTR,LPCWSTR

struct class define sample

class CMyStruct extends CStruct_Base ; inherit CStruct_Base
{
  __New()
  {
    this.AddStructVar("a", "int", 10)
    this.AddStructVar("b", "CRect", 2)	    ; use defined CRect class (inherited CStruct_Base)
    this.AddStructVar("c", "char", "bit:3") ; bit field
    this.AddStructVar("d", "char", "bit:6")
    this.AddStructVar("e", "CRect", "union_start") ; union {
    this.AddStructVar("f", "CSize", "union_end")   ; union }
    this.SetStructCapacity() ; allocate struct memory
  }
}

* same this structure *
struct MyStruct
{
  int a[10];
  RECT b[2];
  char c :3;
  char d :6;
  union
  {
    RECT e;
    SIZE f;
  };
};


CStruct.ahk  ,  Test.ahk 
CStruct_Script Make Helper Download(include 'WinDef.txt') : C type MSDN struct convert to CStruct type class.



#2 fragman

fragman
  • Members
  • 1591 posts

Posted 20 March 2012 - 07:56 PM

You can use __set() to instead of AddStructVar() to allow setting the struct members as class properties!

#3 corrupt

corrupt
  • Members
  • 2558 posts

Posted 24 March 2012 - 06:32 PM

Interesting. Thanks :)
In case you find any of the much older code I had posted interesting <!-- m -->http://www.autohotke... ... 8&start=67<!-- m -->

#4 chaidy

chaidy
  • Members
  • 19 posts

Posted 20 April 2012 - 11:54 AM

This utility help for CStruct class script creating from MSDN struct text.
Posted Image

#5 chaidy

chaidy
  • Members
  • 19 posts

Posted 28 April 2012 - 10:25 AM

Posted Image

#6 chaidy

chaidy
  • Members
  • 19 posts

Posted 01 May 2012 - 04:41 AM

It's a simple bitfield, even though that's a pretty weird time format
<!-- m -->http://stackoverflow... ... hex-format<!-- m -->
1111101100100101101001001011100 = 0x7D92D25C
                         011100 - 28 minutes
                    01001       - 09 hours
               11010            - 26 days
           0010                 - month 3 (zero-based, hence 2)
11111011001                     - 2009 yearswould be my guess.

< structure >
struct TimeFormat {
	union {
		UINT data;
		struct TIMEBITS {
			UINT min   :6;
			UINT hour  :5;
			UINT day   :5;
			UINT month :4;
			UINT year  :11;
		} time;
	};
};
convert to CStruct class:
#include CStruct.ahk
#SingleInstance Force
#NoEnv

^\::ExitApp

F12::
	test := new CTimeFormat
	test.data := 0x7D92D25C
	test.TreeView()
	MsgBox % test.time.hour ":" test.time.min
return

;http://stackoverflow.com/questions/719129/datetime-hex-format
class CTimeFormat extends CStruct_Base
{
	__New()
	{
		this.AddStructVar("data", "uint",      "union_start")
		this.AddStructVar("time", "CTimeBits", "union_end")
		this.SetStructCapacity()
	}
}

class CTimeBits extends CStruct_Base
{
	__New()
	{
		this.AddStructVar("min",   "uint", "bit:6")
		this.AddStructVar("hour",  "uint", "bit:5")
		this.AddStructVar("day",   "uint", "bit:5")
		this.AddStructVar("month", "uint", "bit:4")
		this.AddStructVar("year",  "uint", "bit:11")
		this.SetStructCapacity()
	}
	
	__Get(name)
	{
		if name=month
			return base.__Get(name)+1	;zero-based
	}

	__Set(name, value)
	{
		if name=month
			return base.__Set(name, value-1)
	}
}
check treeview:
Posted Image

CTimeFormat class other making sample: class include mode
Posted Image

#7 chaidy

chaidy
  • Members
  • 19 posts

Posted 07 May 2012 - 08:27 AM

http://msdn.microsof...6(v=VS.85).aspx
UINT GetOutlineTextMetrics(
__in HDC hdc,
__in UINT cbData,
__out_opt LPOUTLINETEXTMETRIC lpOTM
);
[attachment=0]<!-- ia0 -->OutlineTextMetric Structure.ahk<!-- ia0 -->[/attachment]
COutlineTextMetric_TreeView.JPG

#8 projecte1

projecte1
  • Members
  • 1 posts

Posted 10 May 2012 - 10:40 PM

OMG!!

Thanks for the input. You have saved me a lot of work.
I'm starting on the forum but I hope soon to help the same.


Thank you very much for the information.

CHEERS!!

#9 Guests

  • Guests

Posted 21 June 2012 - 11:39 AM

Really easy to use,Thanks. :p

#10 maestrith

maestrith
  • Members
  • 406 posts

Posted 09 November 2012 - 05:18 AM

Wow...I wish I would have found this before today. Very nice work!

#11 ruespe

ruespe
  • Members
  • 562 posts

Posted 09 November 2012 - 09:09 AM

And I wish I would understand what you are talking aboutPosted Image