AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ahkstructlib - Functions for use with Structures (version 2)
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Wed Aug 10, 2005 11:25 am    Post subject: ahkstructlib - Functions for use with Structures (version 2) Reply with quote

ahkstructlib2

ahkstructlib2 is an Include file that I've been working on to hopefully simplify working with structures in AutoHotkey. If anyone has the time to try it out and provide a bit of feedback I'd appreciate it. I'd be interested in hearing any comments, suggestions, bug reports, questions on usage, etc... Smile

** Updated to version 2.02 ** - June 1, 2008
- Version 2.02 is now available with a few changes added since the beta release.
- Version 1 can be downloaded here in case anyone still needs the first version that was posted.
- The current version (2.02) can be downloaded here or the function(s) can be copied and pasted from the code posted below.

Help (Version 2.01) wrote:


Usage:

To create a structure, first use the StructCreate function. This will create the structure itself and create AutoHotkey variables that can be used to send/retrieve values from the structure. The variables are named by using the name of the structure, then a ? character, then the name of the variable.

For example, if StructCreate was used to create a RECT structure with the variables: Left, Top, Right and Bottom
Code:
StructCreate("RECT", "Int", "Left", "Int", "Top", "Int", "Right", "Int", "Bottom")
;
; or using the alternate syntax (either is valid with version 2.0)
;
StructCreate("RECT", "Left As Int", "Top As Int", "Right As Int", "Bottom As Int")

The resulting variables would then be:
RECT - The RECT structure created
RECT?Left
RECT?Top
RECT?Right
RECT?Bottom


To change the values in the RECT structure, use the Struct@ function. For example, to change the Left value to 100
Code:
Struct@("RECT?Left", "100")

To save making multiple calls if many changes need to be made, change the values of the variables first then use the Struct@ function but specify the name of the structure instead of the variable to change:
Code:
RECT?Left = 100
RECT?Top = 50
RECT?Right = 200
RECT?Bottom = 250
; This will change all values in the structure to the values currently assigned to the variables
Struct@("RECT")

If a structure has been used in DllCall and the contents of the structure has been changed, use the Struct? function to retrieve the new values. Similar to using the Struct@ function, if you specify the name of the structure only then the variables are updated with the new values from the structure or you can specify a specific variable to only overwrite the value of that variable with the value from the structure. For example:
Code:
StructCreate("POINT1", "x as long", "y as long")
DllCall("GetCursorPos", "Str", POINT1)
; get the new values from the structure
Struct?("POINT1")
MsgBox, Mouse X position: %POINT1?x%
MsgBox, Mouse Y position: %POINT1?y%


That's about it Smile . To help in troubleshooting potential problems when working with structures I also put together an optional function called struct_enum. This function retrieves the current names and values of each part of the structure. For example, to view the values from the example above, you could use:
Code:
; Display values in POINT1 structure
MsgBox, % struct_enum("POINT1", "`=")
; Display values in variables for POINT1 structure
MsgBox, % struct_enum("POINT1", "`=", "V")


Changes/additions since version 1:
    - Fixed a bug with the "As" syntax that caused a struct to be created with an incorrect size in some cases (fixed in version 2.02)
    - An optional, alternate syntax is now supported in the StructCreate function ("StructName", "VarName As Type", "VarName As Type", etc...).
    - Added the ability to use Tabs and spaces to align code for readability with the new, optional syntax for StructCreate
    - Only 1 variable is now used as a reference Index to cut down on the number of global variables used
    - Added the ability to use different variable types
    - Added support for a few other names for common variable types: long, dword, word, hwnd, byte
    - Changed function names (hopefully easier to remember)
    - The Struct? function will return a value when a variable name is specified, so that the function can be used in an expression
    - Simplified usage - in general
    - ahkstructlib2 now uses the original ExtractInteger and InsertInteger functions from the AHK help file (renamed in case modified versions of these functions are in use)
    - Removed the struct_enum function from the ahkstructlib2 library and added an updated version in a separate Debug plugin library (of course you can still combine the two into one file if you'd like - copy, paste)
    - many other changes...
Requirements:
- AutoHotkey Version 1.0.44.06 or the latest version of AutoHotkey that is available for download

Suggested filename: ahkstructlib2.ahk
Code:
; *********************************
; AHK Function Library - Structures
; Version 2.02
; - by Corrupt
; - Updated June 1, 2008
; *********************************
;
; *********************************
;  Comments, suggestions, etc... welcome :)
; *********************************
;
; *********************************
; Create a new structure
; *********************************
; Params: "Structure Name", "VarType", "VarName", "Type", "Name", etc...
; - Currently a maximum of 32 variables in a structure is supported
;   (to add support for more, add to the list below)
;
; Optional alternate syntax allowed: "Structure Name", "VarName As Type", "VarName As Type", ...
; - mixing of the 2 different syntax styles in the same call is not currently supported
; *********************************
StructCreate(struct_name ,s_type1, s_var1 ,s_type2="", s_var2="" ,s_type3="", s_var3=""
,s_type4="" , s_var4=""  ,s_type5="" , s_var5=""  ,s_type6="" , s_var6=""  ,s_type7="" , s_var7=""
,s_type8="" , s_var8=""  ,s_type9="" , s_var9=""  ,s_type10="", s_var10="" ,s_type11="", s_var11=""
,s_type12="", s_var12="" ,s_type13="", s_var13="" ,s_type14="", s_var14="" ,s_type15="", s_var15=""
,s_type16="", s_var16="" ,s_type17="", s_var17="" ,s_type18="", s_var18="" ,s_type19="", s_var19=""
,s_type20="", s_var20="" ,s_type21="", s_var21="" ,s_type22="", s_var22="" ,s_type23="", s_var23=""
,s_type24="", s_var24="" ,s_type25="", s_var25="" ,s_type26="", s_var26="" ,s_type27="", s_var27=""
,s_type28="", s_var28="" ,s_type29="", s_var29="" ,s_type30="", s_var30="" ,s_type31="", s_var31=""
,s_type32="", s_var32=""){
  Global
  Local struct_sizeA, struct_sizeB, struct_temp1, struct_temp2, struct_temp3, struct_temp4
  , struct_temp40, struct_temp41, struct_temp42, struct_temp5, struct_temp6, struct_templast
  struct_sizeA = 0
  If (!A_AhkScriptProcessID) {
    Process, Exist
    A_AhkScriptProcessID = %ErrorLevel%i
  }
  struct_temp3 = %struct_name%_%A_AhkScriptProcessID%
  %struct_name%= init
  %struct_name%=
  ; Process elements
  Loop, 32 {
    struct_temp42 := s_type%A_Index%
    struct_temp41 := s_var%A_Index%
    struct_temp5 = 1
    ; check for As syntax
    StringReplace, struct_temp42, struct_temp42, %A_Tab%, %A_Space%, All
    If (InStr(struct_temp42, " as ")) {
      StringReplace, struct_temp42, struct_temp42, %A_Space%As%A_Space%, `,
      struct_temp4 = %struct_temp42%
      StringSplit, struct_temp4, struct_temp4, `,, %A_Space%
      struct_temp4 := s_var%A_Index%
      struct_temp5 = 2
    }
    Loop, %struct_temp5%
    {
      If (A_Index = "2") {
        struct_temp41 = %struct_temp4%
        StringReplace, struct_temp41, struct_temp41, %A_Tab%, %A_Space%, All
        StringReplace, struct_temp41, struct_temp41, %A_Space%As%A_Space%, `,
        struct_temp4 = %struct_temp41%
        StringSplit, struct_temp4, struct_temp4, `,, %A_Space%
      }
      ; Check Type (u - unsigned, p - pointer)
      If (struct_temp42="Int" OR struct_temp42="long")
        struct_temp2 = 4
      Else If (struct_temp42="UInt" OR struct_temp42="dword" OR struct_temp42="hwnd")
        struct_temp2 = 4u
      Else If (struct_temp42="Str")
        struct_temp2 = 4up
      Else If (struct_temp42="Short")
        struct_temp2 = 2
      Else If (struct_temp42="UShort" OR struct_temp42="word")
        struct_temp2 = 2u
      Else If (struct_temp42="UChar" OR struct_temp42="byte")
        struct_temp2 = 1u
      Else If (struct_temp42="Char")
        struct_temp2 = 1
      Else If (struct_temp42="Int64")
        struct_temp2 = 8
      Else If (struct_temp42="UInt64")
        struct_temp2 = 8u
      Else
        struct_temp2 = 4p
      If struct_temp41=
      {
        struct_temp6 = 1
        break
      }
      ; ** Create variables **
      struct_temp1 := "?" . struct_temp41
      If (!InStr(struct_temp2, "p"))
        %struct_name%%struct_temp1% = 0
      Else {
        %struct_name%%struct_temp1%=init
        %struct_name%%struct_temp1%=
      }
      ; ** Create reference **
      %struct_temp3% := %struct_temp3% . struct_temp2 . ":" . struct_temp41 "|"
      struct_sizeA += struct_temp2
    }
    If (struct_temp6)
      break
  }
  VarSetCapacity(%struct_name%, struct_sizeA, 0)
Return, True
}


; *********************************
; Retrieve a value from the structure
; *********************************
; Params: struct_name or struct?varname
; - specifying struct_name will retrieve/update values for all variables in the structure
; - specifying struct?varname will retrieve/update only the variable specified   
; *********************************
struct?(s_query)
{
  Global
  Local struct_sizeA, struct_sizeB, struct_temp1, struct_temp2, struct_temp3, struct_temp4, struct_temp5,

struct_temp6
  , struct_temp0, struct_temp00, struct_temp01, struct_temp02
  StringSplit, struct_temp, s_query, ?
  struct_temp3 = %struct_temp1%_%A_AhkScriptProcessID%
  If (!%struct_temp3%) {
    VarSetCapacity(%struct_temp3%, 0)
    ErrorLevel = Invalid_Struct
    Return
  }
  struct_sizeA = 0
  Loop, Parse, %struct_temp3%, |
  {
    StringSplit, struct_temp0, A_LoopField, :
    If struct_temp00 = 0
      break
    struct_sizeA += struct_temp01
    struct_temp4 := !InStr(struct_temp01, "u")
    struct_sizeB = %struct_temp01%
    EnvAdd, struct_temp01, 0
    If (struct_temp02 = struct_temp2 OR struct_temp2 = "") {
      struct_temp5 := ExtractIntegerSL(%struct_temp1%, (struct_sizeA - struct_temp01), !InStr(struct_temp01, "u"),

struct_temp01)
      If (InStr(struct_sizeB, "p"))
        DllCall("lstrcpyA", "Str", %struct_temp1%?%struct_temp02%, "UInt", struct_temp5)
      Else
        %struct_temp1%?%struct_temp02% = %struct_temp5%
      If (struct_temp02 = struct_temp2)
        Return, %struct_temp1%?%struct_temp02%
    }
  }
  Return
}

; *********************************
; Send a value to the structure
; *********************************
; Params: struct_name or struct?varname
; - specifying struct_name will send/update values from all variables in the structure
; - specifying struct?varname will send/update only the variable specified   
; *********************************

struct@(s_modify, s_value="")
{
  Global
  Local struct_sizeA, struct_sizeB, struct_temp1, struct_temp2, struct_temp3, struct_temp4, struct_temp0
  StringSplit, struct_temp, s_modify, ?
  struct_temp3 = %struct_temp1%_%A_AhkScriptProcessID%
  If (!%struct_temp3%) {
    VarSetCapacity(%struct_temp3%, 0)
    ErrorLevel = Invalid_Struct
    Return
  }
  struct_sizeA = 0
  Loop, Parse, %struct_temp3%, |
  {
    Loop, Parse, A_LoopField, :
    {
      If (A_Index = "1") {
        struct_sizeA += A_LoopField
        struct_sizeB = %A_LoopField%
        struct_temp4 = %A_LoopField%
        EnvAdd, struct_sizeB, 0
      }
      Else {
        If (A_LoopField = struct_temp2 OR struct_temp2="") {
          If struct_temp2<>
            %struct_temp1%?%A_LoopField% = %s_value%
          If (InStr(struct_temp4, "p"))
            InsertIntegerSL(&%struct_temp1%?%A_LoopField%, %struct_temp1%, (struct_sizeA - struct_sizeB),

struct_sizeB)
          Else
            InsertIntegerSL(%struct_temp1%?%A_LoopField%, %struct_temp1%, (struct_sizeA - struct_sizeB),

struct_sizeB)
        }
      }
    }
  }
Return
}

; ********************************* 
; Required functions - ExtractInteger, InsertInteger
; - original versions from Version 1.0.44.06 of the AutoHotkey help file
; by Chris Mallett
; // Renamed in case someone is using a modified version of these functions
; // somewhere else in their code
; *********************************
ExtractIntegerSL(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; pSource is a string (buffer) whose memory area contains a raw/binary integer at pOffset.
; The caller should pass true for pSigned to interpret the result as signed vs. unsigned.
; pSize is the size of PSource's integer in bytes (e.g. 4 bytes for a DWORD or Int).
; pSource must be ByRef to avoid corruption during the formal-to-actual copying process
; (since pSource might contain valid data beyond its first binary zero).
{
   Loop %pSize%  ; Build the integer by adding up its bytes.
      result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
   if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
      return result  ; Signed vs. unsigned doesn't matter in these cases.
   ; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
   return -(0xFFFFFFFF - result + 1)
}
; *********************************
InsertIntegerSL(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
; only pSize number of bytes starting at pOffset are altered in it.
{
   Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
      DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1)

& 0xFF)
}
; *********************************



Suggested filename: ahkstructlib2_debug.ahk
Code:
; *********************************
; Debug plugin
; *********************************
; AHK Function Library - Structures
; Version 2.01
; - by Corrupt
; - July 1, 2006
; *********************************

; *********************************
; Retrieve a list of all variable names and values in a structure
; *********************************
; "StructName", "DelimChar", "V"
; - DelimChar may be character(s) to use to separate variable and value
; - The info for each variable is separated by a `n character
; - This function retrieves the values stored in the structure by default.
; "V" can be specified as the 3rd param to retrieve the values from the
; associated variables instead.
; *********************************
struct_enum(s_query, struct_delim2="", struct_local="")
{
  Global
  Local struct_sizeA, struct_sizeB, struct_temp1, struct_temp2, struct_temp3, struct_temp4, struct_temp5, struct_temp6
  , struct_temp0, struct_temp00, struct_temp01, struct_temp02, struct_temp7, struct_temp8
  StringSplit, struct_temp, s_query, ?
  struct_temp3 = %struct_temp1%_%A_AhkScriptProcessID%
  If (!%struct_temp3%) {
    VarSetCapacity(%struct_temp3%, 0)
    ErrorLevel = Invalid_Struct
    Return
  }
  If struct_delim2=
    struct_delim2 = `=
  struct_sizeA = 0
  Loop, Parse, %struct_temp3%, |
  {
    StringSplit, struct_temp0, A_LoopField, :
    If struct_temp00 = 0
      break
    struct_sizeA += struct_temp01
    struct_temp4 := !InStr(struct_temp01, "u")
    struct_sizeB = %struct_temp01%
    EnvAdd, struct_temp01, 0
    If struct_local = V
      struct_temp5 := %struct_temp1%?%struct_temp02%
    Else {
      struct_temp5 := ExtractIntegerSL(%struct_temp1%, (struct_sizeA - struct_temp01), struct_temp4, struct_temp01)
      If (InStr(struct_sizeB, "p"))
      {
        struct_temp7 = %struct_temp5%
        struct_temp8 := DllCall("lstrlen", "UInt", struct_temp7)
        VarSetCapacity(struct_temp5, struct_temp8, 0)
        DllCall("RtlMoveMemory", "Str", struct_temp5, "UInt", struct_temp7, "Int", struct_temp8)
      }
    }
    struct_temp6 = %struct_temp6%`n%struct_temp02%%struct_delim2%%struct_temp5%
  }
  Return, struct_temp6
}
; *********************************


Last edited by corrupt on Sun Jun 01, 2008 5:15 pm; edited 14 times in total
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Thu Aug 11, 2005 12:17 am    Post subject: Reply with quote

ahkstructlib2 Test script - Chalkboard demo (Updated June 17, 2006)

Code:
#Include ahkstructlib2.ahk
; *********************************
; Chalkboard demo
; - hold down mouse1 to draw on the window
; - click mouse3 to clear
; *********************************
Gui, Show, w400 h400, Chalkboard Demo
Gui + LastFound
g1 := WinExist()
StructCreate("Rect", "Int", "Left", "Int", "Top", "Int", "Right", "Int", "Bottom")
CoordMode, Mouse, Relative
OnMessage(0x200, "WM_MOUSEMOVE")
OnMessage(0x204, "WM_RBUTTONDOWN")
HS_DIAGCROSS := 5
Return

WM_RBUTTONDOWN(wParam, lParam)
{
  WinSet, Redraw
}

GuiClose:
ExitApp

WM_MOUSEMOVE(wParam, lParam)
{
  Global
  MouseGetPos, POINTAPI?X, POINTAPI?Y, OutputVarWin
  If (OutputVarWin = g1 AND GetKeyState("LBUTTON", "P"))
  {
    Rect?Left := POINTAPI?X - 5
    Rect?Top := POINTAPI?Y - 30
    Rect?Right := POINTAPI?X + 5
    Rect?Bottom := POINTAPI?Y - 20
    struct@("Rect")
    hDC := DllCall("GetDC", "UInt", g1)
    hBrush := DllCall("CreateHatchBrush", "UInt", HS_DIAGCROSS, "UInt", 0xFF00CC) 
    DllCall("FillRect", "UInt", hDC, "Str", Rect, "UInt", hBrush)
    DllCall("ReleaseDC", "UInt", g1, "UInt", hDC)
    DllCall("DeleteObject", "UInt", hBrush)
  }
  Return
}


Last edited by corrupt on Sun Jun 18, 2006 1:44 am; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Fri Aug 12, 2005 1:15 am    Post subject: Reply with quote

It looks great and makes structure usage much more convenient. This or something like it should probably be distributed in the upcoming standard library.

Thanks for putting it together.
Back to top
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Fri Aug 12, 2005 1:04 pm    Post subject: Reply with quote

Chris wrote:
It looks great and makes structure usage much more convenient. This or something like it should probably be distributed in the upcoming standard library.
Thanks. A standard library sounds great. This or something similar might be a good addition if there is enough interest.

Chris wrote:
Thanks for putting it together.
You're welcome.
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sun Jun 18, 2006 1:46 am    Post subject: Reply with quote

Simple test script for ahkstructlib2:
Code:
#Include, %A_ScriptDir%\ahkstructlib2.ahk
#Include, %A_ScriptDir%\ahkstructlib2_debug.ahk

MsgBox, Create a Rect structure and set the Right and Bottom values...
; Create a Rect structure
structcreate("Rect"
, "Int", "Left"
, "Int", "Top"
, "Int", "Right"
, "Int", "Bottom")
; Set values (Int values not specified are initially set to 0)
struct@("Rect?Right", (A_ScreenWidth//4))
struct@("Rect?Bottom", (A_ScreenHeight//4))
; Display current values of Rect structure
Gosub, DisplayRect
MsgBox, Modify the Left value but don't modify the structure...
Rect?Left := 100
Gosub, DisplayRect
MsgBox, Overwrite the associated variable values with the values in the structure...
struct?("Rect")
Gosub, DisplayRect
MsgBox, Modify the Left and Top values but don't modify the structure...
Rect?Left := 100
Rect?Top := 100
Gosub, DisplayRect
MsgBox, Overwrite the values in the structure with the associated variable values
struct@("Rect")
Gosub, DisplayRect
MsgBox, Draw a red box on the screen using the current Rect values...
hDC := DllCall("GetDC", UInt, 0)  ; Pass zero to get the desktop's device context.
hBrush := DllCall("CreateSolidBrush", UInt, 0x0000FF)  ; Create a red brush (0x0000FF is in BGR format).
DllCall("FillRect", UInt, hDC, Str, Rect, UInt, hBrush)  ; Fill the specified rectangle using the brush above.
DllCall("ReleaseDC", UInt, 0, UInt, hDC)  ; Clean-up.
DllCall("DeleteObject", UInt, hBrush)  ; Clean-up.
Return
DisplayRect:
; Display current values of Rect structure
OutputStruct := struct_enum("Rect", "`=")
OutputVar := struct_enum("Rect", "`=", "V")
MsgBox, Values retrieved from Rect structure:`n`n%OutputStruct%`n`n`nValues of variables:`n`n%OutputVar%
Return
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sun Jun 18, 2006 1:50 am    Post subject: Reply with quote

- Updated to ahkstructlib2, version 2b Beta
- Added 2 new test scripts above
- updated the code in the first post (version 1 still available for download)

If anyone has a chance to check it out, please let me know what you think...
Back to top
View user's profile Send private message Visit poster's website
olfen



Joined: 04 Jun 2005
Posts: 99
Location: Stuttgart, Germany

PostPosted: Sun Jun 18, 2006 12:52 pm    Post subject: Reply with quote

Thanks for sharing it Smile
I think I'll test it using it for this...
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sat Jul 01, 2006 12:25 pm    Post subject: Re: ahkstructlib - Functions for use with Structures (versio Reply with quote

Updated to version 2.0

    - Removed beta status
    - An optional, alternate syntax is now supported in the StructCreate function ("StructName", "VarName As Type", "VarName As Type", etc...).
    - Added support for a few other names for common variable types: long, dword, word, hwnd, byte
    - Added instructions on usage (first post)
Back to top
View user's profile Send private message Visit poster's website
foom



Joined: 19 Apr 2006
Posts: 386

PostPosted: Sat Jul 01, 2006 3:33 pm    Post subject: Reply with quote

Thanks for the instructions on usage. I was unsure what the difference between @ and ? was. Now i know. Thanks for your work.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sat Jul 01, 2006 4:59 pm    Post subject: Reply with quote

foom wrote:
Thanks for the instructions on usage. I was unsure what the difference between @ and ? was. Now i know. Thanks for your work.
Thanks for checking it out Smile . The documentation is probably still a bit weak so if you have any questions or suggestions please let me know.
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sat Jul 01, 2006 5:14 pm    Post subject: Reply with quote

Updated to version 2.01

- Added the ability to use tabs to make code a bit more readable when using the new, optional syntax in StructCreate.

Here's an example:
- Load in your favorite editor with fixed width fonts to see the effect
Code:
#Include, %A_ScriptDir%\ahkstructlib2.ahk

StructCreate("MEMORYSTATUS"
, "dwLength         as long"
, "dwMemoryLoad      as long"
, "dwTotalPhys      as long"
, "dwAvailPhys      as long"
, "dwTotalPageFile   as long"
, "dwAvailPageFile   as long"
, "dwTotalVirtual   as long"
, "dwAvailVirtual   as long")

DllCall("GlobalMemoryStatus", "Str", MEMORYSTATUS)
Struct?("MEMORYSTATUS")

MEMORYSTATUS?dwTotalPhys       :=   Round(MEMORYSTATUS?dwTotalPhys / 1024 / 1024, 2)
MEMORYSTATUS?dwAvailPhys       :=   Round(MEMORYSTATUS?dwAvailPhys / 1024 / 1024, 2)
MEMORYSTATUS?dwTotalPageFile    :=   Round(MEMORYSTATUS?dwTotalPageFile / 1024 / 1024, 2)
MEMORYSTATUS?dwAvailPageFile    :=   Round(MEMORYSTATUS?dwAvailPageFile / 1024 / 1024, 2)
MEMORYSTATUS?dwTotalVirtual    :=   Round(MEMORYSTATUS?dwTotalVirtual / 1024 / 1024, 2)
MEMORYSTATUS?dwAvailVirtual    :=   Round(MEMORYSTATUS?dwAvailVirtual / 1024 / 1024, 2)

MsgBox,
(
System Memory Status:

Memory Load:      %MEMORYSTATUS?dwMemoryLoad%`%
Total Physical:      %MEMORYSTATUS?dwTotalPhys%    MB
Available Physical:      %MEMORYSTATUS?dwAvailPhys%    MB
Total Pagefile:      %MEMORYSTATUS?dwTotalPageFile%    MB
Available Pagefile:      %MEMORYSTATUS?dwAvailPageFile%    MB
Total Virtual:      %MEMORYSTATUS?dwTotalVirtual%    MB
Available Virtual:      %MEMORYSTATUS?dwAvailVirtual%    MB
)
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sun Jul 02, 2006 12:06 am    Post subject: Reply with quote

Nice example. An easy interface like this could become the de-facto standard -- either by being built into the program or distributed with it as an includable file (aka the "standard library").

Thanks.
Back to top
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sun Jul 02, 2006 3:45 am    Post subject: Reply with quote

Chris wrote:
Nice example. An easy interface like this could become the de-facto standard -- either by being built into the program or distributed with it as an includable file (aka the "standard library").

Thanks.

Thanks Smile . An includable file seems to work well in most cases but would probably have a few advantages if built-in.: dot notation (MEMORYSTATUS.dwLength, RECT.Left, etc...), speed/efficiency (the current speed is not too bad for single calls but isn't that great if multiple calls are needed, easier user interface (changing a variable's value could automatically update the struct value and vice versa), using a ? mark as a separator might conflict with future commands?

Using an includable file does have the advantage of being flexible though and I'm having fun trying different methods of putting it together Smile .
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2436

PostPosted: Sun Mar 04, 2007 12:40 pm    Post subject: Reply with quote

As it's been while since this function has been posted, does anyone have any suggestions for improvements before the next release? Smile
Back to top
View user's profile Send private message Visit poster's website
majkinetor



Joined: 24 May 2006
Posts: 3652
Location: Belgrade

PostPosted: Sun Mar 04, 2007 6:39 pm    Post subject: Reply with quote

Remarkable job. Thank you.
The very same thing I propsed much latter and documented on wiki, but didnt do the define part. I am lucky you did so.

Now, imagine your functions to set and get the struct fields are called automaticaly by AHK upon API function enterence/exit. That would be awesome .... we would get the same structs as in C. What else to want.

I already explaind here how that can be acheived.
_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group