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 

a simple but hard GUI ? for gifted binary minds...
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Tue Jun 03, 2008 10:48 pm    Post subject: Reply with quote

That would be very interesting, please see this code:

Code:


WinW := 478
WinH := 478
WinX := (A_ScreenWidth - WinW) / 2
WinY := (A_ScreenHeight - WinH) / 2
OffsetLeft := 40
OffsetTop := 40
OffsetRight := WinW - OffsetLeft
OffsetBottom := WinH - OffsetTop

Gui, -Border -Caption +ToolWindow
Gui, Color, D3407E
Gui, Show, x%WinX% y%WinY% w%WinW% h%WinH%, A %WinW%x%WinH% GUI
WinGet, ActiveID, ID, A
OnMessage(0x201, "GUI_Expand")


return


GUI_Expand(wParam, lParam)
{
   global
   MouseGetPos, MouseX, MouseY, MouseWin
   If (MouseWin != ActiveID)
      Return
   WinGetPos, WinX, WinY, WinW, WinH, ahk_id %ActiveID%
   OffsetRight := WinW - OffsetLeft
   OffsetBottom := WinH - OffsetTop

   If (MouseX > OffsetRight)
      Loop
      {
         If !GetKeyState("LButton")
            Break
         prevMouseX := MouseX
         MouseGetPos, MouseX
         WinW += MouseX - prevMouseX
         Gui, Show, w%WinW%
      }

   If (MouseX < OffsetLeft)
      Loop
      {
         If !GetKeyState("LButton")
            Break
         prevMouseX := MouseX
         MouseGetPos, MouseX
         WinX += MouseX - prevMouseX
         WinW -= MouseX - prevMouseX
         Gui, Show, x%WinX% w%WinW%
      }

   If (MouseY > OffsetBottom)
      Loop
      {
         If !GetKeyState("LButton")
            Break
         prevMouseY := MouseY
         MouseGetPos,, MouseY
         WinH += MouseY - prevMouseY
         Gui, Show, h%WinH%
      }

   If (MouseY < OffsetTop)
      Loop
      {
         If !GetKeyState("LButton")
            Break
         prevMouseY := MouseY
         MouseGetPos,, MouseY
         WinY += MouseY - prevMouseY
         WinH -= MouseY - prevMouseY
         Gui, Show, y%WinY% h%WinH%
      }
}



For some reason there was major flickering upon rezising the top and left handsizes, and it has been a complete mystery to me why Confused
Back to top
View user's profile Send private message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Tue Jun 03, 2008 10:59 pm    Post subject: Reply with quote

I was running some tests on Vista and XP (which btw this code, yours works just the same Smile... but, I get some weird results if I start this routine:

@#> Clicking bottom, holding mouse, rezise -- works great --- but if I release mouse, and reclick, the GUI contorts and expands in weird porportions, or sometimes fails to grab.... kinda random almost

I think the right side is doing basically the same thing,... but at one point the GUI was almost half the size of my screen! lol Smile

BTW, this is the furthest advanced I've seen this model go, and nobody has gotten it this far, s...so, seems like little issues left
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Wed Jun 04, 2008 9:25 am    Post subject: Reply with quote

Quote:
but if I release mouse, and reclick, the GUI contorts and expands in weird porportions, or sometimes fails to grab
Is this with mine, or the code you posted? I can't duplicate the behavior with either.
_________________
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Wed Jun 04, 2008 2:09 pm    Post subject: Reply with quote

This one has top and left border resize added. Now all four borders work.
Code:
SetBatchLines, -1
SetWinDelay,10

Gui 2: -Border -caption +ToolWindow +LastFound
Gui 2: Color, D3407E
guiID := WinExist()
Gui, 2:Show, w300 h351
WinGetPos,,,winW, winH

changeArrow=0   ;change the cursor to arrows when over the drag area or not
constrainMouse=0   ;constrain the mouse to the border min/max during drag
fudgeFactor = 3   ;makes the border area larger for easier dragging, seems to be needed on the bottom border
GuiMinSize=300x351
GuiMaxSize=425x496

IDC_SIZEWE = 32644
IDC_SIZENS = 32645
SysGet, SM_CXFIXEDFRAME, 7
SysGet, SM_CYFIXEDFRAME, 8
leftBorder := SM_CXFIXEDFRAME + fudgeFactor
topBorder := SM_CYFIXEDFRAME + fudgeFactor
WM_MOUSEMOVE = 0x200
WM_LBUTTONDOWN = 0x201
 
hProp := winH / winW   ;multiply the current width by hProp to get the new height
wProp := winW / winH   ;multiply the current height by wProp to get the new width
WEcursor := DllCall("LoadCursor", "Uint", 0, "Int", IDC_SIZEWE)    ;load west-east cursor
NScursor := DllCall("LoadCursor", "Uint", 0, "Int", IDC_SIZENS)    ;load north-south cursor
StringSplit, guiMin, GuiMinSize, x   ;guiMin1 is width   ;guiMin2 is height
StringSplit, guiMax, GuiMaxSize, x   ;guiMax1 is width   ;guiMax2 is height

OnMessage(WM_MOUSEMOVE, "CheckDrag")
OnMessage(WM_LBUTTONDOWN, "CheckDrag")

Return

;need to make left and top border work.
;for left, have to make x smaller while making w larger.

CheckDrag(wparam, lparam, msg, hwnd)
{
   global
   MouseGetPos, mX, mY
   WinGetPos, oX, oY, oW, oH, ahk_id %guiID%
   rightBorder := oW - SM_CXFIXEDFRAME - fudgeFactor
   bottomBorder := oH - SM_CYFIXEDFRAME - fudgeFactor
   If(mX < leftBorder)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
      }
      direction = W
      SetTimer, sizer, 0
   }
   Else If(mX >= rightBorder)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
      }
      direction = E
      SetTimer, sizer, 0
   }
   Else If(mY < topBorder)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
      }
      direction = N
      SetTimer, sizer, 0
   }
   Else If(mY > bottomBorder)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
      }
      direction = S
      SetTimer, sizer, 0
   }
}

sizer:
   Critical
   If GetKeyState("LButton","P")
   {   CoordMode, MOUSE, SCREEN
      MouseGetPos, moveX, moveY
      If(direction = "W")   ;dragging left border   ******NOW WORKS*****
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
         }
         newW := moveX > oX ? oW - Abs(moveX - oX) : oW + Abs(moveX - oX)
         newW := newW < guiMin1 ? guiMin1 : newW   ;make sure its not smaller than minimum
         newW := newW > guiMax1 ? guiMax1 : newW   ;make sure its not bigger than maximum
         newH := newW * hProp
         newX := (newW=guiMin1) or (newW=guiMax1) ? : moveX   ;only move if not at limits
         newY :=
      }
      Else If(direction = "N")   ;dragging top border   ******NOW WORKS*****
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
         }
         newH := moveY > oY ? oH - Abs(moveY - oY) : oH + Abs(moveY - oY)
         newH := newH < guiMin2 ? guiMin2 : newH   ;make sure its not smaller than minimum
         newH := newH > guiMax2 ? guiMax2 : newH   ;make sure its not bigger than maximum
         newW := newH * wProp
         newX :=
         newY := (newH=guiMin2) or (newH=guiMax2) ? : moveY   ;only move if not at limits
      }
      Else If(direction = "E")   ;dragging right border
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
         }
         newW := moveX - oX
         newW := newW < guiMin1 ? guiMin1 : newW   ;make sure its not smaller than minimum
         newW := newW > guiMax1 ? guiMax1 : newW   ;make sure its not bigger than maximum
         newH := newW * hProp
         newX=
         newY=
         If(constrainMouse)
         {   moveX := moveX > oX + guiMax1 ? oX + guiMax1 : moveX   ;keep mouse within max
            moveX := moveX < oX + guiMin1 ? oX + guiMin1 : moveX   ;keep mouse within min
         }
      }
      Else If(direction = "S")   ;dragging bottom border
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
         }
         newH := moveY - oY
         newH := newH < guiMin2 ? guiMin2 : newH   ;make sure its not smaller than minimum
         newH := newH > guiMax2 ? guiMax2 : newH   ;make sure its not bigger than maximum
         newW := newH * wProp
         newX=
         newY=
         If(constrainMouse)
         {   moveY := moveY > oY + guiMax2 ? oY + guiMax2 : moveY   ;keep mouse within max
            moveY := moveY < oY + guiMin2 ? oY + guiMin2 : moveY   ;keep mouse within min
         }
      }
      MouseMove, moveX, moveY
      WinMove, ahk_id %guiID%,, %newX%, %newY%, %newW%, %newH%
   }
   Else
   {   SetTimer, sizer, Off
   }
Return

guiClose:
   ExitApp
Return
There is a problem with consistency between the x and y resize. I think I fixed this with the other version, though. I'll compare them.
_________________
Back to top
View user's profile Send private message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Wed Jun 04, 2008 2:22 pm    Post subject: Reply with quote

This is great, ... I wasn't sure what was going on with the other version I had. Yep, I still get the strange problem..... it seems to really happen if you click kinda hap-hazardly over the gui.... sometimes I am not able to regrab the same spot after a few-multi-clicks...., but then a moment later it seems to work again.

like also try this, if you Left-Mouse-Click a side, hold it down, then hover from Right to Left, Left to Right, Right to Left, on and on.... the control will lose focus and pick up on the opposite side... even though you did not release the mouse button. Keep trying this, ... I would be surprised if you cannot recreate it as this behavior happens on two different machines running XP and Vista. Smile

best wishes, FireGirl.

EDIT (2): It seems to work 100% perfectly as designed, if I am careful with it,... there seems to be points if I am sloppy with the mouse then the control will drop focus, in spite of the fact i am still holding the mouse button down which it should probably not do. meaning, if i grab the right hand side, and then bring the mouse over the Left or Top sides (assuming I am having a bad mouse day), the GUI seems to magnetically (For lack of better word) pick up that side and take over Confused do you see what i mean?
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Wed Jun 04, 2008 5:26 pm    Post subject: Reply with quote

Quote:
the GUI seems to ... pick up that side and take over
I put in a latch so this will not happen.

As for the other problem, I think I see what you mean. I'll look into it.

Code:
SetBatchLines, -1
SetWinDelay,0

Gui 2: -Border -caption +ToolWindow +LastFound
Gui 2: Color, D3407E
guiID := WinExist()
Gui, 2:Show, w300 h351
WinGetPos,,,winW, winH

changeArrow=0   ;change the cursor to arrows when over the drag area or not
constrainMouse=0   ;constrain the mouse to the border min/max during drag
fudgeFactor = 3   ;makes the border area larger for easier dragging, seems to be needed on the bottom border
GuiMinSize=300x351
GuiMaxSize=425x496

IDC_SIZEWE = 32644
IDC_SIZENS = 32645
SysGet, SM_CXFIXEDFRAME, 7
SysGet, SM_CYFIXEDFRAME, 8
leftBorder := SM_CXFIXEDFRAME + fudgeFactor
topBorder := SM_CYFIXEDFRAME + fudgeFactor
WM_MOUSEMOVE = 0x200
WM_LBUTTONDOWN = 0x201
 
hProp := winH / winW   ;multiply the current width by hProp to get the new height
wProp := winW / winH   ;multiply the current height by wProp to get the new width
WEcursor := DllCall("LoadCursor", "Uint", 0, "Int", IDC_SIZEWE)    ;load west-east cursor
NScursor := DllCall("LoadCursor", "Uint", 0, "Int", IDC_SIZENS)    ;load north-south cursor
StringSplit, guiMin, GuiMinSize, x   ;guiMin1 is width   ;guiMin2 is height
StringSplit, guiMax, GuiMaxSize, x   ;guiMax1 is width   ;guiMax2 is height

OnMessage(WM_MOUSEMOVE, "CheckDrag")
OnMessage(WM_LBUTTONDOWN, "CheckDrag")

Return

;need to make left and top border work.
;for left, have to make x smaller while making w larger.

CheckDrag(wparam, lparam, msg, hwnd)
{
   global
   MouseGetPos, mX, mY
   WinGetPos, oX, oY, oW, oH, ahk_id %guiID%
   rightBorder := oW - SM_CXFIXEDFRAME - fudgeFactor
   bottomBorder := oH - SM_CYFIXEDFRAME - fudgeFactor
   If(mX < leftBorder) and (!latch)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
      }
      direction = W
      latch=1
      SetTimer, sizer, 0
   }
   Else If(mX >= rightBorder) and (!latch)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
      }
      direction = E
      latch=1
      SetTimer, sizer, 0
   }
   Else If(mY < topBorder) and (!latch)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
      }
      direction = N
      latch=1
      SetTimer, sizer, 0
   }
   Else If(mY > bottomBorder) and (!latch)
   {   If(changeArrow)
      {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
      }
      direction = S
      latch=1
      SetTimer, sizer, 0
   }
}

sizer:
   Critical
   If GetKeyState("LButton","P")
   {   CoordMode, MOUSE, SCREEN
      MouseGetPos, moveX, moveY
      If(direction = "W")   ;dragging left border   ******NOW WORKS*****
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
         }
         newW := moveX > oX ? oW - Abs(moveX - oX) : oW + Abs(moveX - oX)
         newW := newW < guiMin1 ? guiMin1 : newW   ;make sure its not smaller than minimum
         newW := newW > guiMax1 ? guiMax1 : newW   ;make sure its not bigger than maximum
         newH := newW * hProp
         newX := (newW=guiMin1) or (newW=guiMax1) ? : moveX   ;only move if not at limits
         newY :=
      }
      Else If(direction = "N")   ;dragging top border   ******NOW WORKS*****
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
         }
         newH := moveY > oY ? oH - Abs(moveY - oY) : oH + Abs(moveY - oY)
         newH := newH < guiMin2 ? guiMin2 : newH   ;make sure its not smaller than minimum
         newH := newH > guiMax2 ? guiMax2 : newH   ;make sure its not bigger than maximum
         newW := newH * wProp
         newX :=
         newY := (newH=guiMin2) or (newH=guiMax2) ? : moveY   ;only move if not at limits
      }
      Else If(direction = "E")   ;dragging right border
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", WEcursor)   ;set west-east cursor
         }
         newW := moveX - oX
         newW := newW < guiMin1 ? guiMin1 : newW   ;make sure its not smaller than minimum
         newW := newW > guiMax1 ? guiMax1 : newW   ;make sure its not bigger than maximum
         newH := newW * hProp
         newX=
         newY=
         If(constrainMouse)
         {   moveX := moveX > oX + guiMax1 ? oX + guiMax1 : moveX   ;keep mouse within max
            moveX := moveX < oX + guiMin1 ? oX + guiMin1 : moveX   ;keep mouse within min
         }
      }
      Else If(direction = "S")   ;dragging bottom border
      {   If(changeArrow)
         {   DllCall("SetCursor", "uint", NScursor)   ;set north-south cursor
         }
         newH := moveY - oY
         newH := newH < guiMin2 ? guiMin2 : newH   ;make sure its not smaller than minimum
         newH := newH > guiMax2 ? guiMax2 : newH   ;make sure its not bigger than maximum
         newW := newH * wProp
         newX=
         newY=
         If(constrainMouse)
         {   moveY := moveY > oY + guiMax2 ? oY + guiMax2 : moveY   ;keep mouse within max
            moveY := moveY < oY + guiMin2 ? oY + guiMin2 : moveY   ;keep mouse within min
         }
      }
      MouseMove, moveX, moveY
      WinMove, ahk_id %guiID%,, %newX%, %newY%, %newW%, %newH%
   }
   Else
   {   SetTimer, sizer, Off
      latch=0
   }
Return

guiClose:
   ExitApp
Return

_________________
Back to top
View user's profile Send private message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Wed Jun 04, 2008 6:20 pm    Post subject: Reply with quote

Hey, that is sweeet now, Z-Hybrid-Latch... works! Very Happy
Back to top
View user's profile Send private message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Thu Jul 03, 2008 3:43 pm    Post subject: Reply with quote

Micahs... over the last month I have been working with this, I have been trying to make observations of what is not perfect yet, and noticed a minor issue.

For some reason, the GUI acts goofy if it is resized Open to Closed, to Open, back to closed a few repetitions. The GUI basically jumps or hops around the screen slightly, [instead of remaining in the original fixed spot it started from] :] ... sometimes if I resize lots of times, it may even push the GUI to the point of going out of bounds of the display inadvertently (though it takes some effort to make it do that...) Smile

Say, I am very happy & thankful for your work to make this happen. Lots of people have tried, but nobody could really make it 100% clean the way I was hoping for many months ago.

I don't think anything else is wrong with it, and this was the only minor cosmetic thing I could see. Smile Smile

I couldn't see where to lock it down in your code, and was tempted to fix it myself, but frankly I couldn't do it....

THERE IS ONE MORE THING

But this is nothing to do with this model,... it was just some hyper vision I've been interested in.... from my research in AHK absolutely nobody could even remotely get this to happen.

The concept is to make the GUI somehow 'spin able' or rotatable. By grabbing a corner perhaps.... to literally turn the GUI 360 degrees if you wanted to! Smile


... just wondering what you might know here
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Fri Jul 11, 2008 12:53 am    Post subject: Reply with quote

FireGirl wrote:
but frankly I couldn't do it....
I know the feeling! I couldn't pin it down either. I didn't spend a ton of time on it, though. I'll revisit this to try to work out the kinks.

About your other idea - the rotating gui - I have an idea but no time right now. I'm not sure if it would work, either. When I get time, I'll look into this.
_________________
Back to top
View user's profile Send private message
FireGirl



Joined: 04 May 2007
Posts: 88

PostPosted: Sat Jul 12, 2008 6:45 pm    Post subject: Reply with quote

Interesting concepts there .... I am curious if the envelope can be pushed any Very Happy

Best wishes & Times! -- Firegirl.
Back to top
View user's profile Send private message
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Wed Jul 23, 2008 9:56 pm    Post subject: Reply with quote

@FireGirl

Here is working code for the resizing problem. I was on the wrong track with the left and top border dragging function! All the resizing of borders works like it should. Try it now.

This requires the "+Resize" option on the gui to work rather than handling the dragging ourselves. I went back to the "WM_SIZING" message. If you have any questions, give a holler.

Code:
;Thread that I got "InsertIntegerAtAddress" and "WM_SIZING_Edge" from: http://www.autohotkey.com/forum/viewtopic.php?t=2441

Gui, -border +Resize +LastFound
gui1ID := WinExist()
Gui, Color, 0xFF80C0
Gui, Show, w300 h300, MinMax & AutoRatio

setGuiSize(gui1ID, "100%", "", "", "400", True)   ;guiID or guiNum | minwidth | minheight | maxwidth | maxheight | aspect

Return

GuiClose:
   ExitApp
Return

WM_SIZING(wParam, lParam, msg)
{
   Critical
   static guiID, debounce, rightX, bottomY
   static rect_left=0, rect_top=4, rect_right=8, rect_bottom=12   ;some rect constants

   SetBatchLines,-1
    WM_SIZING_Edge := wParam

   CoordMode, MOUSE, SCREEN
   If GetKeyState("LButton","P") and (!debounce)   ;get the gui id the first time only for this resizing
   {   debounce=1
      MouseGetPos, mX, mY, guiID
      WinGetPos, CurrX, CurrY, CurrW, CurrH, ahk_id %guiID%   ;Get beginning rightX and bottomY coords
      rightX := CurrX+CurrW
      bottomY := CurrY+CurrH
   }
   Else If(debounce)   ;not the first time through
   {   MouseGetPos, mX, mY
   }
   If !GetKeyState("LButton","P")   ;mouse released - reset
   {   debounce=0
   }

    WinGetPos, CurrX, CurrY, CurrW, CurrH, ahk_id %guiID%   ;Get current W/H
   getGuiSize(guiID, _ratio, _minWidth, _minHeight, _maxWidth, _maxHeight, _aspect)   ;get the ratio/min/max info for this gui
   IfEqual, _ratio, , Return False   ;if not a handled gui, exit func
   
   If WM_SIZING_Edge in 2,8   ;right and bottom-right border drag
   {   newWcoord := mX < CurrX + _minWidth ? CurrX + _minWidth : mX   ;make sure width isn't smaller than min
      newWcoord := newWcoord > CurrX + _maxWidth ? CurrX + _maxWidth : newWcoord   ;make sure width isn't larger than max
      InsertIntegerAtAddress(newWcoord, lParam, rect_right)   ;set x coord of right side of gui
      
      If(_aspect)
      {   newHcoord := CurrY + Round(CurrW * (1/_Ratio))   ;get the new height
         InsertIntegerAtAddress(newHcoord, lParam, rect_bottom)   ;set y coord of bottom side of gui
      }
   }
   Else If WM_SIZING_Edge in 6   ;bottom border drag
   {   newHcoord := mY < CurrY + _minHeight ? CurrY + _minHeight : mY   ;make sure height isn't smaller than min
      newHcoord := newHcoord > CurrY + _maxHeight ? CurrY + _maxHeight : newHcoord   ;make sure height isn't larger than max
      InsertIntegerAtAddress(newHcoord, lParam, rect_bottom)   ;set y coord of bottom side of gui
      
      If(_aspect)
      {   newWcoord := CurrX + Round(CurrH * _Ratio)   ;get the new width
         InsertIntegerAtAddress(newWcoord, lParam, rect_right)   ;set x coord of right side of gui
      }
   }
   Else If WM_SIZING_Edge in 3,5   ;top and top-right border drag
   {   newYcoord := mY > bottomY-_minHeight ? bottomY-_minHeight : mY   ;make sure height isn't smaller than min
      newYcoord := newYcoord < bottomY-_maxHeight ? bottomY-_maxHeight : newYcoord   ;make sure height isn't larger than max
      InsertIntegerAtAddress(newYcoord, lParam, rect_top)   ;set y coord of top side of gui
      InsertIntegerAtAddress(bottomY, lParam, rect_bottom)   ;set y coord of bottom side of gui
      
      If(_aspect)
      {   newWcoord := CurrX + (CurrH * _Ratio)   ;get the new width
         InsertIntegerAtAddress(newWcoord, lParam, rect_right)   ;set x coord of right side of gui
      }
   }
   Else If WM_SIZING_Edge in 1,7   ;left and bottom-left border drag
   {   newXcoord := mX > rightX-_minWidth ? rightX-_minWidth : mX   ;make sure width isn't smaller than min
      newXcoord := newXcoord < rightX-_maxWidth ? rightX-_maxWidth : newXcoord   ;make sure width isn't larger than max
      InsertIntegerAtAddress(newXcoord, lParam, rect_left)   ;set x coord of left side of gui
      InsertIntegerAtAddress(rightX, lParam, rect_right)   ;set x coord of right side of gui
      
      If(_aspect)
      {   newHcoord := CurrY + Round(CurrW * (1/_Ratio))   ;get the new height
         InsertIntegerAtAddress(newHcoord, lParam, rect_bottom)   ;set y coord of bottom side of gui
      }
   }
   Else If WM_SIZING_Edge in 4   ;top-left border drag
   {   newYcoord := mY > bottomY-_minHeight ? bottomY-_minHeight : mY   ;make sure height isn't smaller than min
      newYcoord := newYcoord < bottomY-_maxHeight ? bottomY-_maxHeight : newYcoord   ;make sure height isn't larger than max
      scaleMX := rightX - ((bottomY-newYcoord)*_Ratio)   ;scale x to y
      newXcoord := scaleMX > rightX-_minWidth ? rightX-_minWidth : scaleMX   ;make sure width isn't smaller than min
      newXcoord := newXcoord < rightX-_maxWidth ? rightX-_maxWidth : newXcoord   ;make sure width isn't larger than max
      
      InsertIntegerAtAddress(newYcoord, lParam, rect_top)   ;set y coord of top side of gui
      InsertIntegerAtAddress(rightX, lParam, rect_right)      ;set x coord of right side of gui
      InsertIntegerAtAddress(bottomY, lParam, rect_bottom)   ;set y coord of bottom side of gui
      InsertIntegerAtAddress(newXcoord, lParam, rect_left)   ;set x coord of left side of gui
   }
   
    return True

   /*
   From MSDN (with edits):
   lParam - RECT Structure containing window coords
      typedef struct _RECT {
         LONG left;    (0) offset in structure
         LONG top;       (4)
         LONG right;    (8)
         LONG bottom;    (12)
      } RECT, *PRECT;
   
   wParam - Specifies which edge of the window is being sized. This
   parameter can be one of the following values.

      WMSZ_LEFT            (1)   Left edge
      WMSZ_RIGHT         (2)   Right edge
      WMSZ_TOP            (3)   Top edge
      WMSZ_TOPLEFT         (4)   Top-left corner
      WMSZ_TOPRIGHT      (5)   Top-right corner
      WMSZ_BOTTOM         (6)   Bottom edge
      WMSZ_BOTTOMLEFT   (7)   Bottom-left corner
      WMSZ_BOTTOMRIGHT   (8)   Bottom-right corner
   */
}


getGuiSize(_0, ByRef _1="", ByRef _2="", ByRef _3="", ByRef _4="", ByRef _5="", ByRef _6="", ByRef _7="", ByRef _8="", ByRef _9="", ByRef _10="", ByRef _11="", ByRef _12="", ByRef _13="", ByRef _14="")   ;get the info for the given gui - vars return blank if no match - allow up to 15 params (maybe the basis of another array handler?)
{
   global
   local tmp1
   IfEqual, _0,, Return Please provide an ID or Gui Number
   If _0 Is Digit   ;must have passed gui number instead of ID
   {   Gui, %_0%:+LastFound
      _0 := WinExist()
   }
   StringSplit, _ggsStuff, %_0%_ggsArray, `,
   IfEqual, _ggsStuff0, 0, Return   ;if not a match, exit func
   Loop, %_ggsStuff0%
   {   tmp1 = _%A_Index%
      %tmp1% := _ggsStuff%A_Index%
   }
}

/*
   defaults:
      _ID = gui1 id
      _minwidth = guiID.width
      _minheight = guiID.height
      _maxWidth = system window max width
      _maxHeight = system window max height
*/
;DEFINE_FUNCTION setGuiSize(ID, Min Width, Min Height, Max Width, Max Height, Aspect)
setGuiSize(_ID=1, _minWidth="", _minHeight="", _maxWidth="", _maxHeight="", _aspect=True)   ;set the ratio/min/max info for the given gui
{
   SysGet, SM_CXMAXTRACK, 59   ;get largest window size
   SysGet, SM_CYMAXTRACK, 60

   If _ID Is Digit   ;must have passed gui number instead of window ID
   {   Gui, %_ID%:+LastFound
      _ID := WinExist()
   }
   WinGetPos,,,guiW, guiH, ahk_id %_ID%   ;get gui w,h and calc the size ratio
   _Ratio := guiW / guiH   ;multiply the current width by _Ratio to get the new height, multiply the current height by (1/_Ratio) to get the new width
   
   ;this sets the vars for max w,h to keep aspect ratio
   If(_minWidth)   ;if minimum width is given
   {   IfInString, _minWidth, `%   ;if a percent is specified
      {   StringReplace, _minWidth, _minWidth, `%,,All
         _minWidth := _minWidth / 100   ;did it this way because _minWidth/100 produced '0' - an integer
         _min1 := Round(guiW * _minWidth)   ;this is the width
         _min2 := Round(_min1 * (1/_Ratio))      ;this is the height
      }
      Else   ;must be 'px'
      {   StringReplace, _minWidth, _minWidth, px,,All   ;just in case
         _min1 := _minWidth         ;this is the width
         _min2 := Round(_min1 * (1/_Ratio))   ;this is the height
      }
   }
   Else If(_minHeight)   ;_minHeight given
   {   IfInString, _minHeight, `%   ;if a percent is specified
      {   StringReplace, _minHeight, _minHeight, `%,,All
         _minHeight := _minHeight / 100   ;did it this way because _minHeight/100 produced '0' - an integer
         _min2 := guiH * _minHeight   ;this is the height
         _min1 := Round(_min2 * _Ratio)      ;this is the width
      }
      Else   ;must be 'px'
      {   StringReplace, _minHeight, _minHeight, px,,All   ;just in case
         _min2 := _minHeight         ;this is the height
         _min1 := Round(_min2 * _Ratio)   ;this is the width
      }
   }
   Else   ;no min given
   {   _min1 := guiW   ;set min w,h = initial gui w,h
      _min2 := guiH
   }

   If(_maxWidth)   ;if maximum width is given
   {   IfInString, _maxWidth, `%   ;if a percent is specified
      {   StringReplace, _maxWidth, _maxWidth, `%,,All
         _maxWidth /= 100
         _max1 := guiW * _maxWidth   ;this is the width
         _max2 := (_max1 * (1/_Ratio))      ;this is the height
      }
      Else   ;must be 'px'
      {   StringReplace, _maxWidth, _maxWidth, px,,All   ;just in case
         _max1 := _maxWidth         ;this is the width
         _max2 := Round(_max1 * (1/_Ratio))   ;this is the height
      }
   }
   Else If(_maxHeight)   ;_maxHeight given
   {   IfInString, _maxHeight, `%   ;if a percent is specified
      {   StringReplace, _maxHeight, _maxHeight, `%,,All
         _maxHeight /= 100
         _max2 := guiH * _maxHeight   ;this is the height
         _max1 := (_max2 * _Ratio)      ;this is the width
      }
      Else   ;must be 'px'
      {   StringReplace, _maxHeight, _maxHeight, px,,All   ;just in case
         _max2 := _maxHeight      ;this is the height
         _max1 := Round(_max2 * _Ratio)   ;this is the width
      }
   }
   Else   ;no max given
   {   _max1 := SM_CXMAXTRACK   ;largest window possible in system
      _max2 := SM_CYMAXTRACK
   }
   %_ID%_ggsArray := _ratio "," _min1 "," _min2 "," _max1 "," _max2 "," _aspect

   globalWrapper(_ID "_ggsArray", %_ID%_ggsArray)

   OnMessage(0x214,"WM_SIZING")   ;this will happen once for every window set, but that shouldn't cause any problems
}

globalWrapper(victim, content)   ;this turns a dynamic local variable into a global variable
{
   global
   %victim% := content
}

InsertIntegerAtAddress(pInteger, pAddress, pOffset = 0, pSize = 4)    ;update this to putnum
{
   mask := 0xFF  ; This serves to isolate each byte, one by one.
   Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
   {
      DllCall("RtlFillMemory", UInt, pAddress + pOffset + A_Index - 1, UInt, 1
       , UChar, (pInteger & mask) >> 8 * (A_Index - 1))
      mask := mask << 8  ; Set it up for isolation of the next byte.
   }
}
Thanks for prodding me to finish this! I probably wouldn't have gotten around to it for a while.
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
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