RagsRevenge Posted October 15, 2009 Posted October 15, 2009 Hi, I have a HD widescreen monitor at home. WHen I maximise, for example, my web browser the window is mostly empty space. I plan on writing a script to "maximize" the window to the half of the screen on which it currently resides. A double click on the maximize button will maximise the window to the full screen. The repositioning code is no problem, but for the life of me, I can't figure out how to capture the click on the maximize button. I've previously adapted code gotten from this forum to hook double clicks on a list view... Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $oldDate $hWndListView = $lvSchedule If Not IsHWnd($lvSchedule) Then $hWndListView = GUICtrlGetHandle($lvSchedule) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) WinSetOnTop($GuiMaintenance, '', 0) _GUICtrlListView_SetItemSelected($lvSchedule, DllStructGetData($tInfo, "Index")) ;other functionality goes here EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Any help greatly appreciated. D
boogieoompa Posted October 15, 2009 Posted October 15, 2009 Think your looking for While 1 sleep(2000) $state = WinGetState("Inbox", "") If BitAnd($state, 32) Then MsgBox(0, "Example", "Window is maxed") EndIf Wend
RagsRevenge Posted October 20, 2009 Author Posted October 20, 2009 Think your looking for While 1 sleep(2000) $state = WinGetState("Inbox", "") If BitAnd($state, 32) Then MsgBox(0, "Example", "Window is maxed") EndIf Wend Hi, thanks for your reply. I don't think that is what I'm looking for. I want to hook clicks on the maximize button and deal with the functionality myself. With your suggestion, I believe I'd have to have a continuous loop checking the status of each window, allow the window to be maximized and then resize it. I think I need to figure out $wm_sysmenu, WM_SysCommand and $WM_NCLBUTTONDOWN, but unfortunately my WinAPI knowledge is severely limited. Thanks again. D
KaFu Posted October 20, 2009 Posted October 20, 2009 Some code flying around and some quick testing brought me to this... expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 192, 124,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) Local Const $SC_MOVE = 0xF010 Local Const $SC_SIZE = 0xF000 Local Const $SC_CLOSE = 0xF060 If $hWnd = $Form1 Then ; ConsoleWrite(BitAND($wParam, 0xFFF0) & @crlf) ; 61472 Minimize ; 61488 Maximize ; 61728 Revoke Maximize or Minize (Restore) Switch BitAND($wParam, 0xFFF0) Case 61472 ConsoleWrite("Minimize detected" & @CRLF) Case 61488 ConsoleWrite("Maximize detected" & @CRLF) Case 61728 ConsoleWrite("Restore detected" & @CRLF) Case $SC_MOVE ConsoleWrite("WM_Move detected" & @CRLF) Case $SC_SIZE ConsoleWrite("WM_Size detected" & @CRLF) Case $SC_CLOSE ConsoleWrite("WM_Close detected" & @CRLF) ; Return -1 ; to intercept close EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>On_WM_SYSCOMMAND OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
RagsRevenge Posted October 20, 2009 Author Posted October 20, 2009 Some code flying around and some quick testing brought me to this... expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 192, 124,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) Local Const $SC_MOVE = 0xF010 Local Const $SC_SIZE = 0xF000 Local Const $SC_CLOSE = 0xF060 If $hWnd = $Form1 Then ; ConsoleWrite(BitAND($wParam, 0xFFF0) & @crlf) ; 61472 Minimize ; 61488 Maximize ; 61728 Revoke Maximize or Minize (Restore) Switch BitAND($wParam, 0xFFF0) Case 61472 ConsoleWrite("Minimize detected" & @CRLF) Case 61488 ConsoleWrite("Maximize detected" & @CRLF) Case 61728 ConsoleWrite("Restore detected" & @CRLF) Case $SC_MOVE ConsoleWrite("WM_Move detected" & @CRLF) Case $SC_SIZE ConsoleWrite("WM_Size detected" & @CRLF) Case $SC_CLOSE ConsoleWrite("WM_Close detected" & @CRLF) ; Return -1 ; to intercept close EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc ;==>On_WM_SYSCOMMAND Hi KaFu, I believe it was searching through the forums and reading previous posts of yours which put me on the track to WM_SYSCommand, so thanks for that help as well as this post. Modifying what you posted, I get this... expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 447, 192, 124,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_SYSCOMMAND, "On_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func On_WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) if BitAND($wParam, 0xFFF0) = 61488 Then myMaximize() Return 0 ;return 0 to prevent windows carrying out it's standard maximize EndIf Return $GUI_RUNDEFMSG EndFunc ;==>On_WM_SYSCOMMAND func myMaximize() local $leftside $leftside = WindowOnLeftSideOfScreen() if $leftside Then WinMove("Form1", "", 0, 0, @DesktopWidth/2, @DesktopHeight - getHeightOfStartBar()) Else WinMove("Form1", "", @DesktopWidth/2, 0, @DesktopWidth/2, @DesktopHeight - getHeightOfStartBar()) EndIf EndFunc func WindowOnLeftSideOfScreen() ;This function checks to see if the right edge of the window is on the left hand side or right hand side of the screen. local $aPos[4], $rightEdge $aPos = WinGetPos("Form1") $rightEdge = $aPos[0] + $aPos[2] if $rightEdge < @DesktopWidth/2 Then Return 1 Else Return 0 EndIf EndFunc func getHeightOfStartBar() ;returns height of start bar in order to set correct window height. local $aPos[4] $aPos = WinGetPos("[CLASS:Shell_TrayWnd]") return $aPos[3] EndFunc This works, but only for the GUI which we've created. I don't see anything in the documentation for GUIRegisterMsg which allows you to call On_my_SysCommand when maximize is clicked on any window? I realize that in my posted code I explicitly reference Form1 in my WinMove and WindowOnLeftSideOfScreen, but that is only because I haven't figured out how to hook maximize clicks to any window. Any ideas? Also, I'd like to integrate a double click functionality, so that a double click on the maximize button will max as per normal. Thanks, D
KaFu Posted October 20, 2009 Posted October 20, 2009 Maybe take a look at the ShellHook link in my signature under Recommended UDFs. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
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