AutoHotkey Community

It is currently May 26th, 2012, 11:55 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: September 30th, 2009, 9:42 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
attempt to wrap gui controls in object
Requires options.ahkl
Requires gui.ahkl

version .1a
minimal testing done
lots of code cleanup to do
:D

Test Script:
Code:
Type := "Edit"
Gui1 := Gui()
o := Control(Gui1,Type)
o.v := "MyEdit1"
o.g := "MyEdit1Label"
o.w := 300
o.h := 100
o.Text := "Some Text"
;o.AltSubmit := "True"
;o.Create()
Gui1.Show()
Return
Esc::ExitApp

MyEdit1Label:
MsgBox % MyEdit1



Code:
; control.ahkl
; requires AutoHotkey_L
; by ahklerner
;version .1 alpha
; This object  handles a gui's controls
; intended use is by gui object... but can be modified to suit other purposes
;
Control_GetVal(obj, name){
if name = hWnd
   {
   text := obj[name]
   ;MsgBox % text
   VarSetCapacity(text, -1)
   return text ? text : " "
   }
   if name = HasBeenCreated
      return obj.HasBeenCreated
   
;MsgBox % "GetVal: " . name
return obj.Options[name]
}

Control_SetVal(obj, name, val){
   if name = hWnd
      obj.hWnd := val
   else if name = HasBeenCreated
      obj.HasBeenCreated := val
   else if name = Text
      obj.Text := val
   else
      obj.Options[name]:= val
   if name = v
      obj.Parent[val] := obj
}

Control_Delete(obj){
MsgBox "Delete"
}

Control_GetClassNN(hWndWindow,hWndControl){
   DetectHiddenWindows, On
   WinGet, ClassNNList, ControlList, ahk_id %hWndWindow%
   Loop, PARSE, ClassNNList, `n
   {
      ControlGet, hwnd, hwnd,,%A_LoopField%,ahk_id %hWndWindow%
      if (hWnd = hWndControl)
         return A_LoopField
   }
}

Control_SetText(obj,NewText){
   if (obj.HasBeenCreated = True) {
      hWnd := obj.hWnd
      GuiNum := obj.Parent.GuiNum
      controlvarname := obj.v
      controlvarname = %controlvarname%
      if controlvarname
         GuiControl, %GuiNum%:, %controlvarname%, %NewText%
      else
         ControlSetText,, %NewText%,ahk_id %hWnd%
   }
   obj.Text := NewText
}

Control_GetText(obj,NewText){
   if (obj.HasBeenCreated = True) {
      hWnd := obj.hWnd
      ControlGetText, out,,ahk_id %hWnd%
      obj.Text := out
   }
   return obj.Text
}


Control_Call(obj, func, prm0="¬",prm1="",prm2="",prm3="",prm4="",prm5=""){
   loop 6
      num := A_Index - 1, VarSetCapacity(prm%num%, -1)
   if (func = "Create"){
      ;MsgBox % obj.Text
      Control_Create(obj,obj.Type,obj.Options.ToParam(),obj.Text)
      obj.HasBeenCreated := True
   }else if (func = "Text"){
      prm0 = %prm0%
      ;GuiNum := obj.Parent.GuiNum
      if (prm0 != "¬"){
         hWnd := obj.hWnd
         ControlSetText,, %prm0%,ahk_id %hWnd%
         obj.Text := prm0
      }else{
         hWnd := obj.hWnd
         ControlGetText, out,,ahk_id %hWnd%
         obj.Text := out
         return out
      }
   }
}

Control_Create(obj,Type,Opts="",Text=""){
   Global
   Local GuiNum, hWnd
   ;MsgBox Create Called
   Type = %Type%
   Opts = %Opts%
   Text = %Text%
   GuiNum := obj.Parent.GuiNum
   Gui, %GuiNum%:Add, %Type%, %Opts% hWndhWndControl, %Text%
   obj.hWnd := hWndControl
   ;MsgBox % "hWndControl: " . hWndControl
   hWndWindow := obj.Parent.hWnd
   ;MsgBox % "hWndWindow: " . hWndWindow
   ClassNN := Control_GetClassNN(hWndWindow,hWndControl)
   ClassNN = %ClassNN%
;   MsgBox % "New Control ClassNN: " . ClassNN
   obj.Parent[ClassNN] := obj
}
   

Control(Parent,Type){
   static COBase
   ;Local AddCount
   If !COBase
      COBase := Object(      "__Get"       , "Control_GetVal" ; default getter
                     , "__Set"       , "Control_SetVal" ; default setter
                     , "GetText"    , "Control_GetText" ; .GetText()
                     , "SetText"    , "Control_SetText" ; .SetText(NewText)
;                     , "Text"       , "Control_Text" ; .Text([NewText])
;                     , "__Delete"    , "Control_Delete"
                     , "__Call"       , "Control_Call")
   ;MsgBox % "Control():Type " . Type
   
   AddCount := Parent.ControlCount
   VarSetCapacity(AddCount, -1)
   if !AddCount
      AddCount = 0
   AddCount++
   Control := Object("Type", Type, "Parent", parent,"HasBeenCreated", false, "Index", AddCount, "hWnd", " ", "Text", " ", "Options", opt := options(), "base", COBase)
   opt.Parent := Control
   Control.Parent.ControlCount := AddCount
   Control.Parent[AddCount] := Control
   Control.Parent[AddCount] := Control
   return Control
}





_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Last edited by ahklerner on October 1st, 2009, 4:03 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2009, 11:13 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
updated

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2009, 2:09 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Missing Gui() :?:

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2009, 9:10 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
... code updated ...
HotKeyIt wrote:
Missing Gui() :?:

it's in the gui.ahkl thread

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2009, 4:04 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
updated :)
Now Allows Gui.ClassNN.* to be used to select control (after Gui.Show() has been called)

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group