Jump to content

Double Parent GUI


Recommended Posts

I am making a sort of widget bar for the side of the desktop. I have a sample "widget" for testing purposes. I want each widget to follow the constraints of the "widgetbar". In other words, I don't want the gui to be able to be moved outside the edges of the widgetbar. I tried to use the _MouseTrap() function before line 23 but that didn't work. Then I tried it after line 23 and it still didn't work. I think the send message function is overriding the mouse trap. Is there any other way to accomplish what I want?

New_AutoIt_v3_Script.au3

Edited by dantay9
Link to comment
Share on other sites

I am making a sort of widget bar for the side of the desktop. I have a sample "widget" for testing purposes. I want each widget to follow the constraints of the "widgetbar". In other words, I don't want the gui to be able to be moved outside the edges of the widgetbar. I tried to use the _MouseTrap() function before line 23 but that didn't work. Then I tried it after line 23 and it still didn't work. I think the send message function is overriding the mouse trap. Is there any other way to accomplish what I want?

If you made the "widget have the style $WS_CILD instead of $WS_POPUP and set the parent as your widget bar it would stay inside but then you couldn't have the extended style $WS_EX_LAYERED. So maybe you could stop it moving outside like this.

#include <windowsconstants.au3>
  #include <guiconstantsEx.au3>
  $gui = GUICreate("")
  GUISetState()
  
  GUIRegisterMsg($WM_MOVE,"restrain")
  
  while GUIGetMsg() <> -3
      
  WEnd
  
  func restrain($hWnd,$iMsg,$Wp,$lP)
      
      Local $x,$y
      
      $x = BitAnd($lP,0xFFFF)
    ; $y = BitAnd($lP,0xFFFF0000)/0x10000
      if $x < 200 then mouseup("left")
     
      return $GUI_RUNDEFMSG 
      
      
  EndFunc

Edit:Simplified a bit

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

You could also do like I did in Franks Gadget. After a widget was moved I loop through them gathering their position (height) and then I move them to the "sidebar" in the correct order. It's hard to explain but if you ever tried Franks Gadget you would know how I mean.

It's only a WinGetPos(), WinMove(), a couple of loops and a few arrays.

Link to comment
Share on other sites

Just a comment on Frank's Gadgets. When the clock and the counter are active and the clock is moved, the numbers from the clock are left behind while the rest of the gui moves. The numbers seem to duplicate. I also don't see the constraint loop for the widget bar. Could you point me in the right direction?

Link to comment
Share on other sites

No constraint. I meant if you start 2 gadgets and move the upper one under the lower they will automatically correct their position. It's doesn't look very fancy but it works.

I never got the graphics right, bad coding in the gadget I guess.

Edit: See line 157 and down in Genfile.au3 for the moving code.

Edit2: Waaaait, why are your png the exact same size as mine from Franks Gadget? And both are created in Adobe ImageReady and look identical.... Would you mind explaining this?

Edited by AdmiralAlkex
Link to comment
Share on other sites

Thanks! I'll look around that area. Your program works fairly good, but you're right, the graphics aren't up to par. The structure of the code looks good though.

Yes that is your image. I forgot to credit the image to you, but I did credit the background function to you. Sorry about that. I will credit you at the top of my code. Updated the first post.

Edited by dantay9
Link to comment
Share on other sites

Oh I didn't even notice the credit for the SetBitmap(), but I don't think I deserve that credit, I think it's a straight copy from THIS (I may remember wrong, I am to lazy to check atm).

You may have noticed I used the GPL licence but never really released all the source (due to computer hardware problems) but if you pm me your email I can send you what I believe is the last edition of the source.

I also feel obliged to tell you that I have been working a little on and off on something that is a potential successor to Franks Gadget. But I hope you will succeed in this, as they say, competition is good :)

Link to comment
Share on other sites

@martin

Is there any way to put up a "wall" a certain distance from the right side of the screen so the widgets could not pass that "wall"?

Something like this perhaps

#include <windowsconstants.au3>
   #include <guiconstantsEx.au3>
   
   Global $wp, $cp, $border, $TitleHt
   Global Const $RestrainTop=100, $RestrainBottom = 800,$RestrainLeft = 200, $RestrainRight = 800
   
   Global $gui = GUICreate("",230,200,$RestrainLeft+20,$RestrainTop+50)
   GUISetState()
   
   $wp = WinGetPos($gui)
   $cp = WinGetClientSize($gui)
   $border = ($wp[2] - $cp[0]) / 2
   $TitleHt = $wp[3] - $border - $cp[1]
   
   $back = GUICreate("",$RestrainRight - $RestrainLeft,$RestrainBottom - $RestrainTop,$RestrainLeft-$Border,$RestrainTop-$TitleHt,$WS_POPUP)
   GUISetBkColor(0)
   WinSetTrans($back,"",122)
   GUISetState()
   GUISetState(@SW_DISABLE)
   WinSetOnTop($gui,"",1)
   
   $g2 = GUICreate("2",150,150,$RestrainLeft+50,$restrainTop+300)
   GUISetState()
   
   GUIRegisterMsg($WM_MOVE, "restrain")
   
   While GUIGetMsg() <> -3
   
   
   WEnd
   
   Func restrain($hWnd, $iMsg, $wp, $lP)
   
       Local $x, $y,$p,$z,$gp
       if $hWnd <> $back then Winsetontop($hWnd,"",1)
     $gp = wingetpos($hWnd)
      
       $x = BitAND($lP, 0xFFFF)
       $y = BitAND($lP, 0xFFFF0000) / 0x10000
       If $x < $RestrainLeft Or $x + $gp[2] >= $RestrainRight Or _
           $y < $RestrainTop Or $y + $gp[3] > $RestrainBottom Then
           If $x < $RestrainLeft then $x=$RestrainLeft
           If $x + $Gp[2] >= $RestrainRight then $x = - $Gp[2] + $RestrainRight 
           If $y < $RestrainTop+$TitleHt Then $y = $RestrainTop;+ $TitleHt
           If $y + $Gp[3] > $RestrainBottom Then $y = $RestrainBottom - $Gp[3]
           MouseUp("left")
           WinMove($hWnd, "", $x- $border, $y - $TitleHt)
           
       EndIf
       Return $GUI_RUNDEFMSG
   
   
   EndFunc ;==>restrain
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

That works great! I updated the first post with the fixed script.

You confused me! I created an answer to your post but you changed it! You asked if I could stop the window moving out of the area and I looked at this again. I have concluded that your idea of _MouseTrap works much better than my idea and I feel a bit silly that I didn't look at that more carefully to begin with.

See what you think.

#include <windowsconstants.au3>
#include <guiconstantsEx.au3>
#include <misc.au3>
Global Const $WM_ENTERSIZEMOVE = 0x231, $WM_EXITSIZEMOVE = 0x232
Global $wp, $cp, $border, $TitleHt
Global Const $RestrainTop = 100, $RestrainBottom = 800, $RestrainLeft = 200, $RestrainRight = 800
Global $aMT[4]
Global $gui = GUICreate("", 230, 200, $RestrainLeft + 20, $RestrainTop + 50)
GUISetState()

$wp = WinGetPos($gui)
$cp = WinGetClientSize($gui)
$border = ($wp[2] - $cp[0]) / 2
$TitleHt = $wp[3] - $border - $cp[1]

$back = GUICreate("", $RestrainRight - $RestrainLeft, $RestrainBottom - $RestrainTop, $RestrainLeft - $border, $RestrainTop - $TitleHt, $WS_POPUP)
GUISetBkColor(0)
WinSetTrans($back, "", 122)
GUISetState()
GUISetState(@SW_DISABLE)
WinSetOnTop($gui, "", 1)

$g2 = GUICreate("2", 150, 150, $RestrainLeft + 50, $RestrainTop + 300)
GUISetState()

GUIRegisterMsg($WM_MOVE, "startclip")
GUIRegisterMsg($WM_ENTERSIZEMOVE, "preparemove")
GUIRegisterMsg($WM_EXITSIZEMOVE, "stopclip")
While 1
    switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch


WEnd


Func preparemove($hWnd)
    winsetontop($hWnd,"",1)
EndFunc

Func startclip($hWnd, $iMsg, $wParam, $lParam)
 Local $mcmode = Opt("MouseCoordMode", 0)
    Local $mp = mousegetpos()
    Local $wp = WinGetPos($hWnd)
    Local $tp = WinGetPos($back)
    $aMT[0] = $tp[0] + $mp[0]
    $aMT[1]= $tp[1] + $mp[1]
    $aMT[2] = $tp[0] + $tp[2] - $wp[2] + $mp[0]
    $aMT[3] = $tp[1] + $tp[3] - $wp[3] + $mp[1]

    _MouseTrap($aMT[0],$aMT[1],$aMT[2],$aMT[3])
    Opt("MouseCoordMode", $mcmode)
EndFunc
Func stopclip()
    _MouseTrap()
EndFunc  ;==>stopclip

I found that setting the mouse trap on ENTERSIZEMOVE produced varuable results which I don't understand so I set the mouse trap in WM_MOVE.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Oh! ok, but my idea did not include GUIRegisterMsg($WM_MOVE, at all. That was all your idea. I tried to insert _MouseTrap() before and after the _SendMessage() which wouldn't work. This was all your idea and it worked great. End of story!

P.S. This doesn't work while the window is being dragged. I changed my mind. I like the code I have now best.

Edited by dantay9
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...