Calculates an appropriate pop-up window position
#include <GuiMenu.au3>
_GUICtrlMenu_CalculatePopupWindowPosition ( $iX, $iY, $iWidth, $iHeight [, $iFlags = 0 [, $tExclude = 0]] )
$iX | The x-coordinate, in logical units, of the specified anchor point. |
$iY | The y-coordinate, in logical units, of the specified anchor point. |
$iWidth | The width, in logical units, of the specified window. |
$iHeight | The height, in logical units, of the specified window. |
$iFlags | [optional] The flags that specify how the function positions the pop-up window horizontally and vertically. $TPM_CENTERALIGN $TPM_LEFTALIGN (Default) $TPM_RIGHTALIGN $TPM_BOTTOMALIGN $TPM_TOPALIGN (Default) $TPM_VCENTERALIGN $TPM_HORIZONTAL (Default) $TPM_VERTICAL $TPM_WORKAREA |
$tExclude | [optional] $tagRECT structure that specifies the exclude rectangle. |
Success: | a $tagRECT structure that contains the pop-up window position. |
Failure: | sets the @error flag to non-zero, call _WinAPI_GetLastError() to get extended error information. |
This function requires Windows 7 or later.
Search CalculatePopupWindowPosition in MSDN Library.
#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIConv.au3>
#include <WinAPISysWin.au3>
Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 400)
Local $idButton = GUICtrlCreateButton('New Window', 145, 366, 110, 23)
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $idButton
_PopupDlg($hForm)
EndSwitch
WEnd
Func _PopupDlg($hParent)
GUISetState(@SW_DISABLE, $hParent)
Local $tPOINT = DllStructCreate($tagPOINT)
For $i = 1 To 2
DllStructSetData($tPOINT, $i, 0)
Next
_WinAPI_ClientToScreen($hParent, $tPOINT)
Local $hDlg = GUICreate('New Window', 400, 400)
Local $idButton = GUICtrlCreateButton('Close', 165, 366, 70, 23)
Local $tRECT = _GUICtrlMenu_CalculatePopupWindowPosition(DllStructGetData($tPOINT, 1), DllStructGetData($tPOINT, 2), _WinAPI_GetWindowWidth($hDlg), _WinAPI_GetWindowHeight($hDlg))
If @error Then
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Require Windows 7 or later.')
Exit
EndIf
WinMove($hDlg, '', DllStructGetData($tRECT, 1), DllStructGetData($tRECT, 2))
GUISetState(@SW_SHOW, $hDlg)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $idButton
ExitLoop
EndSwitch
WEnd
GUISetState(@SW_ENABLE, $hParent)
GUIDelete($hDlg)
EndFunc ;==>_PopupDlg