Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[function] Attach 1.1


  • Please log in to reply
62 replies to this topic
HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
For AutoHotkeyv2:
Attach(hCtrl:="", aDef:="") {

   Attach_(hCtrl, aDef, "", "")

}



Attach_(hCtrl, aDef, Msg, hParent){

  static

  local s1,s2, enable, reset, oldCritical



  if (aDef = "") {							;Reset if integer, Handler if string

    if IsFunc(hCtrl)

      return Handler := hCtrl

  

    If adrWindowInfo=""

      return			;Resetting prior to adding any control just returns.

    hParent := hCtrl != "" ? hCtrl+0 : hGui

    loopparse,% _%hParent%a, %A_Space%

    {

      hCtrl := A_LoopField, SubStr(_%hCtrl%,1,1), aDef := SubStr(_%hCtrl%,1,1)="-" ? SubStr(_%hCtrl%,2) : _%hCtrl%,  _%hCtrl% := ""

      gosub Attach_GetPos

      loopparse, %aDef%, %A_Space%

      {

        StrSplit, z, %A_LoopField%, :

        z1:=z.1

        _%hCtrl% .= A_LoopField="r" ? "r " : (z.1 ":" z.2 ":" c%z1% " ")

      }

      _%hCtrl% := SubStr(_%hCtrl%, 1, -1)				

    }

    reset := 1,  _%hParent%_s := _%hParent%_pw " " _%hParent%_ph

  }



  if (hParent = "")  {						;Initialize controls 

    if !adrSetWindowPos

      adrSetWindowPos		:= DllCall("GetProcAddress", "uint", DllCall("GetModuleHandle", "str", "user32"), A_IsUnicode ? "astr" : "str", "SetWindowPos")

      ,adrWindowInfo		:= DllCall("GetProcAddress", "uint", DllCall("GetModuleHandle", "str", "user32"), A_IsUnicode ? "astr" : "str", "GetWindowInfo")

      ,OnMessage(5, A_ThisFunc),	VarSetCapacity(B, 60), NumPut(60, B), adrB := &B

      ,hGui := DllCall("GetParent", "uint", hCtrl, "Uint") 



    hParent := DllCall("GetParent", "uint", hCtrl, "Uint") 

    

    if !_%hParent%_s

      DllCall(adrWindowInfo, "uint", hParent, "uint", adrB), _%hParent%_pw := NumGet(B, 28) - NumGet(B, 20), _%hParent%_ph := NumGet(B, 32) - NumGet(B, 24), _%hParent%_s := !_%hParent%_pw || !_%hParent%_ph ? "" : _%hParent%_pw " " _%hParent%_ph

    

    if InStr(" " aDef " ", "p")

      StrReplace, aDef, %aDef%, p, xp yp wp hp,,1

    if aDef="-"

      return SubStr(_%hCtrl%,1,1) != "-" ? _%hCtrl% := "-" _%hCtrl% : ""

    else if (aDef = "+")

      if SubStr(_%hCtrl%,1,1) != "-" 

         return

      else _%hCtrl% := SubStr(_%hCtrl%, 2), enable := 1 

    else {

      gosub Attach_GetPos

      _%hCtrl% := ""

      loopparse, %aDef%, %A_Space%

      {			

        if (l := A_LoopField) = "-"	{

          _%hCtrl% := "-" _%hCtrl%

          continue

        }

        f := SubStr(l,1,1), k := StrLen(l)=1 ? 1 : SubStr(l,2)

        if (j := InStr(l, "/"))

          k := SubStr(l, 2, j-2) / SubStr(l, j+1)

        _%hCtrl% .= f ":" k ":" c%f% " "

      }

      return _%hCtrl% := SubStr(_%hCtrl%, 1, -1), _%hParent%a .= InStr(_%hParent%, hCtrl) ? "" : (_%hParent%a = "" ? "" : " ")  hCtrl 

    }

  }

  if _%hParent%a=""

    return				;return if nothing to anchor.



  if !reset && !enable {					

    _%hParent%_pw := aDef & 0xFFFF, _%hParent%_ph := aDef >> 16

    if _%hParent%_ph=0

      return		;when u create gui without any control, it will send message with height=0 and scramble the controls ....

  } 



  if !_%hParent%_s

    _%hParent%_s := _%hParent%_pw " " _%hParent%_ph



  oldCritical := A_IsCritical

  critical, 5000



  StrSplit, s,% _%hParent%_s, %A_Space%

  loopparse,% _%hParent%a, %A_Space%

  {

    hCtrl := A_LoopField, aDef := _%hCtrl%, 	uw := uh := ux := uy := r := 0, hCtrl1 := SubStr(_%hCtrl%,1,1)

    if (hCtrl1 = "-")

      if reset=""

        continue

      else aDef := SubStr(aDef, 2)	

    

    gosub Attach_GetPos

    loopparse, %aDef%, %A_Space%

    {

      StrSplit, z,%A_LoopField%, :		; opt:coef:initial

      If z.1="r"

        r := z.2

      z1:=z.1

      if z.2="p"

         c%z1% := z.3 * (z.1="x" || z.1="w" ?  _%hParent%_pw/s.1 : _%hParent%_ph/s.2), u%z1% := true

      else c%z1% := z.3 + z.2*(z.1="x" || z.1="w" ?  _%hParent%_pw-s.1 : _%hParent%_ph-s.2), 	u%z1% := true

    }

    flag := 4 | (r=1 ? 0x100 : 0) | (uw OR uh ? 0 : 1) | (ux OR uy ? 0 : 2)			; nozorder=4 nocopybits=0x100 SWP_NOSIZE=1 SWP_NOMOVE=2

    ;m(hParent, _%hParent%a, hCtrl, _%hCtrl%)

    DllCall(adrSetWindowPos, "uint", hCtrl, "uint", 0, "uint", cx, "uint", cy, "uint", cw, "uint", ch, "uint", flag)

    r+0=2 ? Attach_redrawDelayed(hCtrl) : ""

  }

  critical %oldCritical%

  return Handler != "" ? %Handler%(hParent) : ""



 Attach_GetPos:									;hParent & hCtrl must be set up at this point

    DllCall(adrWindowInfo, "uint", hParent, "uint", adrB), 	lx := NumGet(B, 20), ly := NumGet(B, 24), DllCall(adrWindowInfo, "uint", hCtrl, "uint", adrB)

    ,cx :=NumGet(B, 4),	cy := NumGet(B, 8), cw := NumGet(B, 12)-cx, ch := NumGet(B, 16)-cy, cx-=lx, cy-=ly

 return

}



Attach_redrawDelayed(hCtrl){

  static s

  s .= !InStr(s, hCtrl) ? hCtrl " " : ""

  SetTimer, %A_ThisFunc%, -100

  return

 Attach_redrawDelayed:

  loopparse, %s%, %A_Space%

    WinSet, Redraw, , ahk_id %A_LoopField%

  s := ""

 return

}



Verdlin
  • Members
  • 256 posts
  • Last active: Apr 29 2016 06:46 PM
  • Joined: 21 Dec 2012

Tested first with AHK_H 64w on W7 64bit, then on W8 64-bit system. This works great with W7, but it is broken in W8. I suspect one of the DllCalls. Any thoughts?


Scripts are written and tested using AHK_H 64w (unless otherwise specified).

CFlyout. EasyIni. Dynamic Label Execution (No Reload). Word Lookup.


evilc
  • Members
  • 340 posts
  • Last active: Oct 27 2015 11:07 PM
  • Joined: 17 Nov 2005

Great lib, but I am slightly concerned that the hosting on Google Code is gonna die.

 

Do you have plans to port to GitHub or something?

 

Also, a slight issue. If you attach a Text GuiControl with the Center option set, when the GuiControl gets wider, the text does not remain centered.

Any ideas on what causes this?