如何调整大小并调整+调整大小?

时间:2015-05-22 14:50:46

标签: autohotkey

在设计某个应用程序时,我需要在一个小的GUI窗口中有两个编辑框,你可以调整大小窗口并只调整第一个编辑框的大小,但是 shift + resize 会调整第二个编辑框的大小。

inline edit boxes

(请忽略我的屏幕截图中的图钉图标;它是由DisplayFusion放置在那里的ontop按钮,并且不会影响此线程)

我的尝试一直在使用anchor.ahkautoxywh.ahk库,它们会自动调整控件的大小。这是我的示例代码以及autoxywh的副本(您应该能够粘贴并运行它)。

使用AutoXYWH.ahk库:

#noenv
#singleinstance force

apptitle := "ShiftResize"
 def_uiw := 212

Gui, +Hwnd%apptitle% +resize
Gui, +minsize%def_UIw%
gui, margin, 4
Gui, Add, Edit, vEdit1 HwndhEdit1 w100,
Gui, Add, Edit, vEdit2 HwndhEdit2 w100 x+4,
Gui, Show
return

GuiSize:
    If !pre_GuiWidth
        pre_GuiWidth := A_GuiWidth

    guicontrolget, edit1, pos
    guicontrolget, edit2, pos

    if(getkeystate("shift","P")){
        If (edit2w < 100) && (A_GuiWidth-pre_GuiWidth < 0)
            Return
        If (lastResize != "Edit2")
            lastResize := "Edit2", autoxywh("update_ctrl_info")
        autoxywh("w", hEdit2)
    }else{
        If (edit1w < 100)  && (A_GuiWidth-pre_GuiWidth < 0)
            Return
        If (lastResize != "Edit1")
            lastResize := "Edit1", autoxywh("update_ctrl_info")
        autoxywh("x", hEdit2)
        autoxywh("w", hEdit1)
    }

    pre_GuiWidth := A_GuiWidth
return

GuiClose:
ExitApp

; =============================================================================
; Function: AutoXYWH
;   Move and resize control automatically when GUI resizes.
; Parameters:
;   DimSize - Can be one or more of x/y/w/h  optional followed by a fraction
;             add a '*' to DimSize to 'MoveDraw' the controls rather then just 'Move', this is recommended for Groupboxes
;   cList   - variadic list of ControlIDs
;             ControlID can be a control HWND, associated variable name, ClassNN or displayed text.
;             The later (displayed text) is possible but not recommend since not very reliable 
; Examples:
;   AutoXYWH("xy", "Btn1", "Btn2")
;   AutoXYWH("w0.5 h 0.75", hEdit, "displayed text", "vLabel", "Button1")
;   AutoXYWH("*w0.5 h 0.75", hGroupbox1, "GrbChoices")
; =============================================================================
;   Here is how GuiSize works with AutoXYWH (mod by toralf):
;http://ahkscript.org/boards/viewtopic.php?f=5&t=7696&p=45882#p45786
;The first time Gui, Show executing, the GuiSize lable will be called. At that time then, AutoXYWH stores the initial x/y/w/h of Controls and GuiWidth/GuiHeight.
;Initial_GuiWidth := A_GuiWidth
;Initial_GuiHeight := A_GuiHeight

;GuiControlGet, Initial_Control, Pos, %ControlID%
;; Initial_ControlX
;; Initial_ControlY
;; Initial_ControlW
;; Initial_ControlH

;After that, when user resizing the Gui window, GuiSize lable will be called, AutoXYWH then calculates the changes of Gui Width and Height.
;Diff_GuiWidth := A_GuiWidth - Initial_GuiWidth
;Diff_GuiHeight := A_GuiHeight - Initial_GuiHeight

;Then, the new values:
;New_ControlW := Diff_GuiWidth + Initial_ControlW
;New_ControlX := Diff_GuiWidth + Initial_ControlX

;New_ControlH := Diff_GuiHeight + Initial_ControlH
;New_ControlY := Diff_GuiHeight + Initial_ControlY
; -----------------------------------------------------------------------------
; Release date: 2015-5-17
; Author      : tmplinshi (mod by toralf)
; requires AHK version : 1.1.13.01+
; =============================================================================
AutoXYWH(DimSize, cList*){       ; http://ahkscript.org/boards/viewtopic.php?t=1079
  static cInfo := {}

  If (DimSize = "update_ctrl_info") {
    For ctrlid, obj in cInfo
    {
        GuiControlGet, i, Pos, %ctrlid%
        cInfo[ctrlid].x := ix
        cInfo[ctrlid].y := iy
        cInfo[ctrlid].w := iw
        cInfo[ctrlid].h := ih
    }
    Return
  }

  For i, ctrl in cList {
    ctrlid := A_Gui ":" ctrl
    If ( cInfo[ctrlid].x = "" ){
        GuiControlGet, i, %A_Gui%:Pos, %ctrl%
        GuiControlGet, Hwnd, %A_Gui%:Hwnd, %ctrl%
        MMD := InStr(DimSize, "*") ? "MoveDraw" : "Move"
        fx := fy := fw := fh := 0
        For i, dim in (a := StrSplit(RegExReplace(DimSize, "i)[^xywh]")))
            If !RegExMatch(DimSize, "i)" dim "\s*\K[\d.-]+", f%dim%)
              f%dim% := 1
        cInfo[ctrlid] := { x:ix, fx:fx, y:iy, fy:fy, w:iw, fw:fw, h:ih, fh:fh, gw:A_GuiWidth, gh:A_GuiHeight, a:a , m:MMD}
    }Else If ( cInfo[ctrlid].a.1) {
        dgx := dgw := A_GuiWidth  - cInfo[ctrlid].gw  , dgy := dgh := A_GuiHeight - cInfo[ctrlid].gh
        For i, dim in cInfo[ctrlid]["a"]
            Options .= dim (dg%dim% * cInfo[ctrlid]["f" dim] + cInfo[ctrlid][dim]) A_Space
        GuiControl, % A_Gui ":" cInfo[ctrlid].m , % ctrl, % Options
} } }

Maestrith提出了这个选择:

#SingleInstance,Force
SetBatchLines,-1
Gui,+minsize230 +Resize +hwndmain
Gui,Add,Edit,w100 hwndedit1
Gui,Add,Edit,x+10 w100
ControlGetPos,x,y,w,h,,ahk_id%edit1%
SysGet,Border,32
SysGet,Caption,4
OnMessage(0xA1,"sizemove")
Gui,Show
return
GuiSize:
if(Resize="Left"&&offsetx&&A_GuiWidth-offsetx<=100){
    Gui,+minsize%A_GuiWidth%
}
if(Resize="Left"&&offsetx&&A_GuiWidth-offsetx>=100){
    GuiControl,1:Move,Edit2,% "x" A_GuiWidth-offsetx
    GuiControl,1:move,Edit1,% "w" A_GuiWidth+offsetw
}
if(Resize="right"&&offsetx&&A_GuiWidth+woffset>=100){
    GuiControl,1:move,Edit2,% "w" A_GuiWidth+woffset
}
if(Resize="right"&&offsetx&&A_GuiWidth+woffset<=100)
    Gui,+MinSize%A_GuiWidth%
return
GuiClose:
GuiEscape:
ExitApp
return
sizemove(){
    global
    resize:=GetKeyState("Shift","P")?"Right":"Left"
    ControlGetPos,x,y,w,h,Edit2,ahk_id%main%
    ControlGetPos,xx,yy,ww,hh,Edit1,ahk_id%main%
    VarSetCapacity(rect,16)
    DllCall("GetClientRect",UPtr,main,UPtr,&rect),width:=NumGet(rect,8),height:=NumGet(rect,12)
    offsetx:=width-x+border
    offsetw:=ww-width
    woffset:=w-width
}

这些解决方案都不能完美运行。如果您使用窗口和大小进行游戏并调整大小,使用 resize shift + resize 进行缩小和增长,这些框将会失控。例如,尝试调整大小以增长edit1,然后 shift + resize edit2增长到一个很好的长度,然后 shift +调整大小以缩小edit2。你得到这个,edit2在边缘处运行,或者edit1离开边缘的第二个图像edit2甚至不可见:

edit2 off the edge both boxes out of whack

完美地工作:

  • 每个编辑框都需要最小尺寸100px,并且不应缩小到该尺寸以下。
  • 两个编辑框应保持可见 - 换句话说,缩小GUI不应该使其中一个框不可见。
  • resize 只应调整edit1
  • 的大小
  • shift + resize 应该只调整edit2

现在,我意识到我可以叠加编辑框而忘记它,但这不是我想要做的。 stacked edit boxes

现在,I have a thread on ahkscript.org,但进展非常缓慢,所以我希望能在这里引起更多关注,并希望找到一个有效的解决方案。

1 个答案:

答案 0 :(得分:1)

Just Me on the Autohotkey forum solved this perfectly

public class DontQuoteMeOnIt {
    private static final String SPECIALS_NO_DOT = "()<>,;:\\\"[] \t";

    public static void main(String[] args) throws Exception {
        String s = "MA NA US error@hub.wmmercer.com";
        s = MimeUtility.quote(s, SPECIALS_NO_DOT);
        System.out.println(InternetAddress.parse(s, true)[0]);
    }
}
相关问题