jcpetu Posted January 20, 2015 Share Posted January 20, 2015 Hi people, using a code sniped I got from the WEB, I'm trying to create a sizeable title less Window on Desktop but when I click out of the Window it Exits. Any Help will be appreciated. thanks in advance and regards. expandcollapse popup#include <GuiConstantsEx.au3> #include <Windowsconstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> Global Const $SC_DRAGMOVE = 0xF012 Global $hGUI HotKeySet("{ESC}", "On_Exit") ; Set distance from edge of window where resizing is possible Global Const $iMargin = 4 ; Set max and min GUI sizes Global Const $iGUIMinX = 150, $iGUIMinY = 150, $iGUIMaxX = 300, $iGUIMaxY = 300 ; Create GUI $hGUI = GUICreate("Y", 100, 100, -1, -1, BitOR($WS_POPUP, $WS_CHILD), $WS_EX_TRANSPARENT, _WinAPI_GetDesktopWindow()) GUISetBkColor(0x00FF00) GUISetState() ; Register message handlers GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change ;<======== GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits While 1 Sleep(10) WEnd ; Set cursor to correct resizing form if mouse is over a border Func _SetCursor() Local $iCursorID Switch _Check_Border() Case 0 $iCursorID = 2 Case 1, 2 $iCursorID = 13 Case 3, 6 $iCursorID = 11 Case 5, 7 $iCursorID = 10 Case 4, 8 $iCursorID = 12 EndSwitch GUISetCursor($iCursorID, 1) EndFunc ;==>_SetCursor ; Check cursor type and resize/drag window as required Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Local $iCursorType = _Check_Border() If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message $iResizeType = 0xF000 + $iCursorType _SendMessage($hGUI, $WM_SYSCOMMAND, $iResizeType, 0) Else Local $aCurInfo = GUIGetCursorInfo($hGUI) If $aCurInfo[4] = 0 Then ; Mouse not over a control _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndIf EndIf EndFunc ;==>_WM_LBUTTONDOWN ; Determines if mouse cursor over a border Func _Check_Border() Local $aCurInfo = GUIGetCursorInfo() Local $aWinPos = WinGetPos($hGUI) Local $iSide = 0 Local $iTopBot = 0 If $aCurInfo[0] < $iMargin Then $iSide = 1 If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2 If $aCurInfo[1] < $iMargin Then $iTopBot = 3 If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6 Return $iSide + $iTopBot EndFunc ;==>_Check_Border ; Set min and max GUI sizes Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tMinMaxInfo, 7, $iGUIMinX) DllStructSetData($tMinMaxInfo, 8, $iGUIMinY) DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX) DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY) Return 0 EndFunc ;==>_WM_GETMINMAXINFO Func On_Exit() Exit EndFunc ;==>On_Exit Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted January 20, 2015 Share Posted January 20, 2015 (edited) From the help file " $WS_POPUP 0x80000000 Creates a pop-up window. This style cannot be used with the WS_CHILD style. $WS_CHILD 0x40000000 Creates a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style. Edited January 20, 2015 by DicatoroftheUSA Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
jcpetu Posted January 20, 2015 Author Share Posted January 20, 2015 DicatoroftheUSA, even with a popup the same behaviour: expandcollapse popup#include <WinAPI.au3> #include <GuiConstantsEx.au3> #include <Windowsconstants.au3> #include <SendMessage.au3> Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{ESC}", "On_Exit") ; Set distance from edge of window where resizing is possible Global Const $iMargin = 4 ; Set max and min GUI sizes Global Const $iGUIMinX = 50, $iGUIMinY = 50, $iGUIMaxX = 300, $iGUIMaxY = 300 ; Create GUI $hGUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP) GUISetBkColor(0x00FF00) GUISetState() ; Register message handlers GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits While 1 Sleep(10) WEnd ; Set cursor to correct resizing form if mouse is over a border Func _SetCursor() Local $iCursorID Switch _Check_Border() Case 0 $iCursorID = 2 Case 1, 2 $iCursorID = 13 Case 3, 6 $iCursorID = 11 Case 5, 7 $iCursorID = 10 Case 4, 8 $iCursorID = 12 EndSwitch GUISetCursor($iCursorID, 1) EndFunc ;==>SetCursor ; Check cursor type and resize/drag window as required Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Local $iCursorType = _Check_Border() If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message $iResizeType = 0xF000 + $iCursorType _SendMessage($hGUI, $WM_SYSCOMMAND, $iResizeType, 0) Else Local $aCurInfo = GUIGetCursorInfo($hGUI) If $aCurInfo[4] = 0 Then ; Mouse not over a control _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndIf EndIf EndFunc ;==>WM_LBUTTONDOWN ; Determines if mouse cursor over a border Func _Check_Border() Local $aCurInfo = GUIGetCursorInfo() Local $aWinPos = WinGetPos($hGUI) Local $iSide = 0 Local $iTopBot = 0 If $aCurInfo[0] < $iMargin Then $iSide = 1 If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2 If $aCurInfo[1] < $iMargin Then $iTopBot = 3 If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6 Return $iSide + $iTopBot EndFunc ;==>_Check_Border ; Set min and max GUI sizes Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tMinMaxInfo, 7, $iGUIMinX) DllStructSetData($tMinMaxInfo, 8, $iGUIMinY) DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX) DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY) Return 0 EndFunc ;==>_WM_GETMINMAXINFO Func On_Exit() Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 20, 2015 Moderators Share Posted January 20, 2015 (edited) If it abruptly exits, it's more than likely because you're not catching errors. Specifically, I'd be willing to bet an Array error. After everyone of your position calls that return an array, always do something like (pseudo call): ;position call for an array return If Not IsArray($positioncallarray) Then Return SetError(1, 0, 0) EndIf You will probably need to adjust your function calls to check for an error returned as well. Edit: These are the funcs I'd fix: expandcollapse popup; Set cursor to correct resizing form if mouse is over a border Func _SetCursor() Local $iCursorID Local $iCheckBorder = _Check_Border() If Not @error Then ; check for error in case it wasn't an array Switch $iCheckBorder Case 0 $iCursorID = 2 Case 1, 2 $iCursorID = 13 Case 3, 6 $iCursorID = 11 Case 5, 7 $iCursorID = 10 Case 4, 8 $iCursorID = 12 EndSwitch GUISetCursor($iCursorID, 1) EndIf EndFunc ;==>SetCursor ; Check cursor type and resize/drag window as required Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Local $iCursorType = _Check_Border() If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message $iResizeType = 0xF000 + $iCursorType _SendMessage($hGUI, $WM_SYSCOMMAND, $iResizeType, 0) Else Local $aCurInfo = GUIGetCursorInfo($hGUI) If IsArray($aCurInfo) Then ; validate it's an array If $aCurInfo[4] = 0 Then ; Mouse not over a control _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndIf EndIf EndIf EndFunc ;==>WM_LBUTTONDOWN ; Determines if mouse cursor over a border Func _Check_Border() Local $aCurInfo = GUIGetCursorInfo() Local $aWinPos = WinGetPos($hGUI) If Not IsArray($aWinPos) Then Return SetError (1, 0, 0) EndIf Local $iSide = 0 Local $iTopBot = 0 If $aCurInfo[0] < $iMargin Then $iSide = 1 If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2 If $aCurInfo[1] < $iMargin Then $iTopBot = 3 If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6 Return $iSide + $iTopBot EndFunc ;==>_Check_Border Edited January 20, 2015 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
jcpetu Posted January 20, 2015 Author Share Posted January 20, 2015 thanks SmOke_NÂ I'll give it a try. Link to comment Share on other sites More sharing options...
DicatoroftheUSA Posted January 20, 2015 Share Posted January 20, 2015 Why would you use $ws_child if it is not a child. Statism is violence, Taxation is theft. Autoit Wiki Link to comment Share on other sites More sharing options...
jcpetu Posted January 21, 2015 Author Share Posted January 21, 2015 Why would you use $ws_child if it is not a child. I was just experimenting, I'm using now: $hGUI = GUICreate("", 100, 100, -1, -1, $WS_POPUP, $WS_EX_TRANSPARENT, _WinAPI_GetDesktopWindow()) Â Link to comment Share on other sites More sharing options...
jcpetu Posted January 21, 2015 Author Share Posted January 21, 2015 and the complete corrected code just in case it would be interesting for someone is: expandcollapse popup#include <WinAPI.au3> #include <GuiConstantsEx.au3> #include <Windowsconstants.au3> #include <SendMessage.au3> Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{ESC}", "On_Exit") Global Const $iMargin = 4; Set distance from edge of window where resizing is possible Global Const $iGUIMinX = 50, $iGUIMinY = 50, $iGUIMaxX = 300, $iGUIMaxY = 300; Set max and min GUI sizes $hGUI = GUICreate("", 100, 100, -1, -1, $WS_POPUP, $WS_EX_TRANSPARENT, _WinAPI_GetDesktopWindow()) GUISetBkColor(0x00FF00) GUISetState() ; Register message handlers GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize/drag GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits While 1 Sleep(10) WEnd ; Set cursor to correct resizing form if mouse is over a border Func _SetCursor() Local $iCursorID Switch _Check_Border() Case 0 $iCursorID = 2 Case 1, 2 $iCursorID = 13 Case 3, 6 $iCursorID = 11 Case 5, 7 $iCursorID = 10 Case 4, 8 $iCursorID = 12 EndSwitch GUISetCursor($iCursorID, 1) EndFunc ;==>_SetCursor ; Check cursor type and resize/drag window as required Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Local $iCursorType = _Check_Border() If $iCursorType > 0 Then ; Cursor is set to resizing style so send appropriate resize message $iResizeType = 0xF000 + $iCursorType _SendMessage($hGUI, $WM_SYSCOMMAND, $iResizeType, 0) Else Local $aCurInfo = GUIGetCursorInfo($hGUI) If Not @error And $aCurInfo[4] = 0 Then _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0); Mouse not over a control EndIf EndFunc ;==>_WM_LBUTTONDOWN ; Determines if mouse cursor over a border Func _Check_Border() Local $aCurInfo = GUIGetCursorInfo($hGUI) If @error Or Not IsArray($aCurInfo) Then Return SetError(1) Local $aWinPos = WinGetPos($hGUI) Local $iSide, $iTopBot If $aCurInfo[0] < $iMargin Then $iSide = 1 If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2 If $aCurInfo[1] < $iMargin Then $iTopBot = 3 If $aCurInfo[1] > $aWinPos[3] - $iMargin Then $iTopBot = 6 Return $iSide + $iTopBot EndFunc ;==>_Check_Border ; Set min and max GUI sizes Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) $tMinMaxInfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tMinMaxInfo, 7, $iGUIMinX) DllStructSetData($tMinMaxInfo, 8, $iGUIMinY) DllStructSetData($tMinMaxInfo, 9, $iGUIMaxX) DllStructSetData($tMinMaxInfo, 10, $iGUIMaxY) ;Return 0 EndFunc ;==>_WM_GETMINMAXINFO Func On_Exit() Exit EndFunc ;==>On_Exit Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now