jennico Posted October 23, 2008 Share Posted October 23, 2008 when you create a gui with the size of 400x400, the resulting window is always bigger, depending on the styles, ex styles and the individual system metrix on another computer, as long as you do not create a popup window. 400x400 is the client area size. but very often you have to calculate the real borders of the GUI resp. the actual position of the client area rather than the GUI position in order to position the window correctly. when you write a GUI based program and you don't want to have ugly results on other computers, my functions will help you. i would like to propose to the AutoIt team to replace WinGetClientSize with my _WinGetClientPos, that is analogue to WinGetPos. title: _Borders.au3 expandcollapse popup#cs ;#=#INDEX#==============================================================================================================================# ;# Title .........: _Borders.au3 # ;# Description....: Two GUI based functions to retrieve a window's client area, border size and title and menu bar height # ;# Date ..........: 23.10.08 # ;# Version .......: 1.0 # ;# Author ........: jennico (jennicoattminusonlinedotde) # ;# Remarks .......: Important calculations if you want your gui to work on pcs that use different window themes. # ;# Functions......: _WinGetBorderSize ( $hWnd [, $s_text] ) # ;# _WinGetClientPos ( $hWnd [, $s_text] ) => a modification of WinGetClientSize # ;#======================================================================================================================================# #ce #include-once #cs ;#=#Function#===========================================================================================================================# ;# Name ..........: _WinGetBorderSize ( $hWnd [, $s_text] ) # ;# Description....: Retrieves the size of a given window's border and title and menu bar. # ;# Parameters.....: $hWnd : The title of the window to read. See Title special definition. # ;# $s_text : [optional] The text of the window to read. # ;# Return Value ..: Success: Returns a 2-element array containing the following information: # ;# $array[0] = border size # ;# $array[1] = top border size incl. title and menu bar height # ;# Failure: Returns 0 and sets @error to 1 if windows is not found. # ;# Author ........: jennico (jennicoattminusonlinedotde) # ;# Date ..........: 14.10.08 # ;# Remarks .......: _WinGetBorderSize returns negative numbers such as -32000 for minimized windows, but works fine with # ;# (non-minimized) hidden windows. If multiple windows match the criteria, the most recently active window is used. # ;# Array[1] - Array[0] equals title + menu bar height. # ;# Related .......: _WinGetClientPos, WinGetPos, WinGetClientSize, WinMove # ;# Example........: yes # ;#======================================================================================================================================# #ce Func _WinGetBorderSize($hWnd, $s_text = "") Local $ret[2], $s_pos = WinGetPos($hWnd, $s_text) If @error Then Return SetError(1, 0, 0) Local $s_size = WinGetClientSize($hWnd, $s_text) If @error Then Return SetError(1, 0, 0) $ret[0] = ($s_pos[2] - $s_size[0]) / 2 $ret[1] = $s_pos[3] - $s_size[1] - $ret[0] Return $ret EndFunc ;==>_WinGetBorderSize #cs ;#=#Function#===========================================================================================================================# ;# Name ..........: _WinGetClientPos ( $hWnd [, $s_text] ) # ;# Description....: Retrieves the position and size of a given window' client area. # ;# Parameters.....: $hWnd : The title of the window to read. See Title special definition. # ;# $s_text : [optional] The text of the window to read. # ;# Return Value ..: Success: Returns a 4-element array containing the following information: # ;# $array[0] = X position (absolute screen coordinates) # ;# $array[1] = Y position (absolute screen coordinates) # ;# $array[2] = Width # ;# $array[3] = Height # ;# Failure: Returns 0 and sets @error to 1 if windows is not found. # ;# Author ........: jennico (jennicoattminusonlinedotde) # ;# Date ..........: 14.10.08 # ;# Remarks .......: _WinGetClientPos returns negative numbers such as -32000 for minimized windows, but works fine with # ;# (non-minimized) hidden windows. If multiple windows match the criteria, the most recently active window is used. # ;# Related .......: _WinGetBorderSize, WinGetPos, WinGetClientSize, WinMove # ;# Example........: yes # ;#======================================================================================================================================# #ce Func _WinGetClientPos($hWnd, $s_text = "") Local $s_pos = WinGetPos($hWnd, $s_text) If @error Then Return SetError(1, 0, 0) Local $s_size = WinGetClientSize($hWnd, $s_text) If @error Then Return SetError(1, 0, 0) Local $s_temp = ($s_pos[2] - $s_size[0]) / 2, $ret[4] = [$s_pos[0] + $s_temp, $s_pos[1] + $s_pos[3] - $s_size[1] - $s_temp, $s_size[0], $s_size[1]] Return $ret EndFunc ;==>_WinGetClientPos Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
jennico Posted October 23, 2008 Author Share Posted October 23, 2008 sorry for the line breaks, i cannot edit the post anymore. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
BillLuvsU Posted October 23, 2008 Share Posted October 23, 2008 So this returns the coordnites of the GUI starting from the actual title bar? Ok. I can see a use or two for that but it shouldn't really replace the current func. [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
jennico Posted October 23, 2008 Author Share Posted October 23, 2008 (edited) well, in fact it returns the gui's client area position (and size). i make use of it in about every second script when the client position is critical. you never know what system metrix (theme) the other user of your script has set. j. Edited October 23, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 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