Gianni Posted February 10, 2019 Share Posted February 10, 2019 (edited) Good morning I'm playing with this little snippet of code to create a simple visual selector for areas of the screen. I'm seeing some problems that I do not know why they occur and how to solve them. to use the snipped you should be able to resize the GUI, drag it on the screen (by clicking within the GUI transparent area and dragging) and use a right click on the GUI (or edge of the gui) to exit and get the coordinates of the selected area. First problem (or rather an oddity): using different values for the $AlphaKey variable, it happens that with some values transparency is only visual, while with other values transparency acts like a real hole that also allows mouse clicks to pass through. (this last behavior prevents the possibility of dragging the window). however with the value 0x00000001 it is only transparent (it acts only on opacity), with 0x0000FF00 for example creates a real 'hole'). What is the logic of operation of the various colors ?? Second problem: this piece of code works on windows7 x64, but when I try it on win 10, for example, it does not work and behaves differently from the expected one, both in terms of appearance and transparency/dragging. (I suppose it may have something to do with 'aero' ?). How can I make it work on both systems? third problem: when I place the 'GUI' a little beyond the top edge of the screen, it is completely brought back into the screen (aero snap). How can I inhibit this 'forced' repositioning even temporarily? at this link there is an example that maybe could work, how to use it here so to disable the 'aero snap' for this GUI only (or also only temporarily)? (excuse the verbosity and if I have been unclear) Every suggestion and advice is welcome Thank you expandcollapse popup#include <GUIConstants.au3> #include <WinAPI.au3> #include <array.au3> _ArrayDisplay(ScreenAreaSelector()) Func ScreenAreaSelector() ; create a GUI Local $hGUI = GUICreate('', 50, 50, -1, -1, BitOR($WS_POPUPWINDOW, $WS_THICKFRAME, 0), BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED, $WS_EX_TOPMOST)) ; Place an empty Label control on the whole GUI surface (to be used as dragging handle) Local $idLabel = GUICtrlCreateLabel("", 0, 0, 50, 50, -1, $GUI_WS_EX_PARENTDRAG) GUICtrlSetResizing($idLabel, $GUI_DOCKBORDERS) ; so the edit control will grow as the window ; change the cursor shape on hovering on the Label control GUICtrlSetCursor($idLabel, 0) ; 0 = hand ; 9 = sizeall ; the color that will be traansparent Local $AlphaKey = 0x00000001 ; 0x0000ff00 ; ; activate transparency GUICtrlSetBkColor($idLabel, $AlphaKey) _WinAPI_SetLayeredWindowAttributes($hGUI, $AlphaKey) GUISetState(@SW_SHOW, $hGUI) ; wait for a RightClic on the GUI to exit Do Until GUIGetMsg() = $GUI_EVENT_SECONDARYUP ; exit on RightClick ; calculates the measurements of the selected area Local $aPos1 = WinGetPos($hGUI) #cs (including borders) $aArray[0] = X position $aArray[1] = Y position $aArray[2] = Width $aArray[3] = Height #ce ; Local $aPos2 = WinGetClientSize($hGUI) #cs (only client area) $aArray[0] = Width of window's client area $aArray[1] = Height of window's client area #ce ; thickness of the edges Local $xEdge = ($aPos1[2] - $aPos2[0]) / 2 ; Local $yEdge = ($aPos1[3] - $aPos2[1]) / 2 ; coordinates of the client area $aPos1[0] += $xEdge ; x position $aPos1[1] += $yEdge ; y position $aPos1[2] = $aPos2[0] ; Width of client area $aPos1[3] = $aPos2[1] ; Height of client area GUIDelete($hGUI) Return $aPos1 EndFunc ;==>ScreenAreaSelector Edited February 10, 2019 by Chimp added link and added explanation of use Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Danp2 Posted February 10, 2019 Share Posted February 10, 2019 57 minutes ago, Chimp said: with the value 0x00000001 it is only transparent (it acts only on opacity), with 0x0000FF00 for example creates a real 'hole') FWIW, on Win10 x64 I get the "hole" effect with both values. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Gianni Posted February 10, 2019 Author Share Posted February 10, 2019 Thanks dan, in fact one of the problems is just that the transparency effect that also gives the possibility to drag does not work on win 10, while it works instead on win 7 (with some right values of the $AlphaKey variable) Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
UEZ Posted February 10, 2019 Share Posted February 10, 2019 This seems to work on Win10 but I don't know on Win7: expandcollapse popup#include <GUIConstants.au3> #include <WinAPI.au3> #include <array.au3> Global $bDock = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop", "DockMoving") If $bDock Then RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "DockMoving", "REG_SZ", 0) _ArrayDisplay(ScreenAreaSelector()) If $bDock Then RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop", "DockMoving", "REG_SZ", 1) Func ScreenAreaSelector() ; the color that will be transparent Local $AlphaKey = 0xABCDEF; 0x0000ff00 ; ; create a GUI Local $hGUI = GUICreate('', 50, 50, -1, -1, BitOR($WS_POPUP, $WS_SIZEBOX), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_LAYERED)) GUISetBkColor($AlphaKey) ; Place an empty Label control on the whole GUI surface (to be used as dragging handle) Local $idLabel = GUICtrlCreateLabel("", 0, 0, 50, 50, -1, $GUI_WS_EX_PARENTDRAG), $hLabel = GUICtrlGetHandle($idLabel) GUICtrlSetResizing($idLabel, $GUI_DOCKBORDERS) ; so the edit control will grow as the window ; change the cursor shape on hovering on the Label control GUICtrlSetCursor($idLabel, 0) ; 0 = hand ; 9 = sizeall ; activate transparency GUICtrlSetBkColor($idLabel, 0xABCDEF) WinSetTrans($hLabel, "", 0x40) _WinAPI_SetLayeredWindowAttributes($hGUI, $AlphaKey, 255, 3) ;change 3 to 4 to get a different GUI style GUISetState(@SW_SHOW, $hGUI) ; wait for a RightClic on the GUI to exit Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN EndSwitch Until False ; calculates the measurements of the selected area Local $aPos1 = WinGetPos($hGUI) #cs (including borders) $aArray[0] = X position $aArray[1] = Y position $aArray[2] = Width $aArray[3] = Height #ce ; Local $aPos2 = WinGetClientSize($hGUI) #cs (only client area) $aArray[0] = Width of window's client area $aArray[1] = Height of window's client area #ce ; thickness of the edges Local $xEdge = ($aPos1[2] - $aPos2[0]) / 2 ; Local $yEdge = ($aPos1[3] - $aPos2[1]) / 2 ; coordinates of the client area $aPos1[0] += $xEdge ; x position $aPos1[1] += $yEdge ; y position $aPos1[2] = $aPos2[0] ; Width of client area $aPos1[3] = $aPos2[1] ; Height of client area GUIDelete($hGUI) Return $aPos1 EndFunc ;==>ScreenAreaSelector Disabling DockMoving doesn't work either. Gianni 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Gianni Posted February 10, 2019 Author Share Posted February 10, 2019 Thanks UEZ Here, on WIn7, the transparent+dragging effect still works using your modified script (I have not a Win10 in this moment to test, but I believe in what you said.... ) Snap to top edge still active however, but is not a big problem. Thanks a lot UEZ, your touch is always magic! Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
UEZ Posted February 10, 2019 Share Posted February 10, 2019 (edited) It look like this on Win10 With parameter 4: Edited February 10, 2019 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Gianni Posted February 10, 2019 Author Share Posted February 10, 2019 (edited) hmmm with parameter 4 here on win 7 nothing appears.... while with parameter 3 appears correctly and is transparent + draggable. the look is more beautiful on win7, since there is regular border on the 4 edges and no title bar. Can be obtained the same look of win7 also on win10?, here a snapshot on WIN7: Edited November 10, 2019 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Deye Posted February 10, 2019 Share Posted February 10, 2019 2 hours ago, Chimp said: How can I inhibit this 'forced' repositioning even temporarily? temporarily disable with $SPI_SETWINARRANGING set to disabled Procedure .. Deye Gianni 1 Link to comment Share on other sites More sharing options...
Gianni Posted February 10, 2019 Author Share Posted February 10, 2019 (edited) Thanks Deye Setting that system-wide parameter to False disables the windows snap indeed, very interesting, Thanks for your tip! here how I've used it on the fly (hope it's the right way): (reference) #include <WinAPI.au3> Local Const $SPI_SETWINARRANGING = 131 ; to disable _WinAPI_SystemParametersInfo($SPI_SETWINARRANGING, False) ; set window arrangement off ; to enable _WinAPI_SystemParametersInfo($SPI_SETWINARRANGING, True) ; set window arrangement on Edited February 10, 2019 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Deye Posted February 10, 2019 Share Posted February 10, 2019 Its OK to run it like that since it wont update any settings permanently To determine if it needs to be toggled back upon exiting the script : $bDock = _IsActive($SPI_GETWINARRANGING) _WinAPI_SystemParametersInfo($SPI_SETWINARRANGING, $bDock) Func _IsActive($iAction) Local Const $bool = DllStructCreate("BOOL") _WinAPI_SystemParametersInfo($iAction, 0, DllStructGetPtr($bool)) Return DllStructGetData($bool, 1) EndFunc ;==>_IsBool Deye Gianni 1 Link to comment Share on other sites More sharing options...
Gianni Posted November 10, 2019 Author Share Posted November 10, 2019 does anyone know how to use in AutoIt the information provided in the answer given to this link to make a window like that? ...also the second answer seems interesting, where (in WIN 10) "to remove the white strip just remove the corresponding value from the first rectangle in NCCALCSIZE"... is there a way to do that in AutoIt?? As always, many thanks to those who want to help Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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