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 

control.ahkl - a gui control object for AutoHotkey_L - v.1a

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Wed Sep 30, 2009 8:42 am    Post subject: control.ahkl - a gui control object for AutoHotkey_L - v.1a Reply with quote

attempt to wrap gui controls in object
Requires options.ahkl
Requires gui.ahkl

version .1a
minimal testing done
lots of code cleanup to do
Very Happy

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
}





_________________

ʞɔпɟ əɥʇ ʇɐɥʍ


Last edited by ahklerner on Thu Oct 01, 2009 3:03 am; edited 2 times in total
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Wed Sep 30, 2009 10:13 am    Post subject: Reply with quote

updated
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Wed Sep 30, 2009 1:09 pm    Post subject: Reply with quote

Missing Gui() Question
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Wed Sep 30, 2009 8:10 pm    Post subject: Reply with quote

... code updated ...
HotKeyIt wrote:
Missing Gui() Question

it's in the gui.ahkl thread
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
ahklerner



Joined: 26 Jun 2006
Posts: 1381
Location: USA

PostPosted: Thu Oct 01, 2009 3:04 am    Post subject: Reply with quote

updated Smile
Now Allows Gui.ClassNN.* to be used to select control (after Gui.Show() has been called)
_________________

ʞɔпɟ əɥʇ ʇɐɥʍ
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
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