Advertisement
AZJIO

MsgBox в виде функции дочернего

Sep 16th, 2011
818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.79 KB | None | 0 0
  1. #include <WindowsConstants.au3>
  2.  
  3. $Gui = GUICreate('My program', 420, 250)
  4. $MsgFile = GUICtrlCreateButton("Button", 20, 20, 90, 30)
  5. GUISetState()
  6.  
  7. While 1
  8.     Switch GUIGetMsg()
  9.         Case $MsgFile
  10.             _MsgFile()
  11.         Case -3
  12.             Exit
  13.     EndSwitch
  14. WEnd
  15.  
  16. Func _MsgFile()
  17.     Local $EditBut, $Gui1, $GP, $msg, $StrBut
  18.     $GP = _ChildCoor($Gui, 410, 240)
  19.     GUISetState(@SW_DISABLE, $Gui)
  20.    
  21.     $Gui1 = GUICreate('Сообщение', $GP[2], $GP[3], $GP[0], $GP[1], $WS_CAPTION + $WS_SYSMENU + $WS_POPUP, -1, $Gui)
  22.     GUICtrlCreateLabel('Что будем делать сейчас?', 20, 10, 180, 23)
  23.     $EditBut = GUICtrlCreateButton('Редактор', 10, 40, 80, 22)
  24.     $StrBut = GUICtrlCreateButton('Калькулятор', 100, 40, 80, 22)
  25.     GUISetState(@SW_SHOW, $Gui1)
  26.     While 1
  27.         Switch GUIGetMsg()
  28.             Case $EditBut
  29.                 Run('Notepad.exe')
  30.             Case $StrBut
  31.                 ShellExecute('Calc.exe')
  32.             Case -3
  33.                 GUISetState(@SW_ENABLE, $Gui)
  34.                 GUIDelete($Gui1)
  35.                 ExitLoop
  36.         EndSwitch
  37.     WEnd
  38. EndFunc
  39.  
  40. ; вычисление координат дочернего окна
  41. ; 1 - дескриптор родительского окна
  42. ; 2 - ширина дочернего окна
  43. ; 3 - высота дочернего окна
  44. ; 4 - тип 0 - по центру, или 0 - к левому верхнему родительского окна
  45. ; 5 - отступ от краёв
  46. Func _ChildCoor($Gui, $w, $h, $c = 0, $d = 0)
  47.     Local $aWA = _WinAPI_GetWorkingArea(), _
  48.             $GP = WinGetPos($Gui), _
  49.             $wgcs = WinGetClientSize($Gui)
  50.     Local $dLeft = ($GP[2] - $wgcs[0]) / 2, _
  51.             $dTor = $GP[3] - $wgcs[1] - $dLeft
  52.     If $c = 0 Then
  53.         $GP[0] = $GP[0] + ($GP[2] - $w) / 2 - $dLeft
  54.         $GP[1] = $GP[1] + ($GP[3] - $h - $dLeft - $dTor) / 2
  55.     EndIf
  56.     If $d > ($aWA[2] - $aWA[0] - $w - $dLeft * 2) / 2 Or $d > ($aWA[3] - $aWA[1] - $h - $dLeft + $dTor) / 2 Then $d = 0
  57.     If $GP[0] + $w + $dLeft * 2 + $d > $aWA[2] Then $GP[0] = $aWA[2] - $w - $d - $dLeft * 2
  58.     If $GP[1] + $h + $dLeft + $dTor + $d > $aWA[3] Then $GP[1] = $aWA[3] - $h - $dLeft - $dTor - $d
  59.     If $GP[0] <= $aWA[0] + $d Then $GP[0] = $aWA[0] + $d
  60.     If $GP[1] <= $aWA[1] + $d Then $GP[1] = $aWA[1] + $d
  61.     $GP[2] = $w
  62.     $GP[3] = $h
  63.     Return $GP
  64. EndFunc
  65.  
  66. Func _WinAPI_GetWorkingArea()
  67.     Local Const $SPI_GETWORKAREA = 48
  68.     Local $stRECT = DllStructCreate("long; long; long; long")
  69.  
  70.     Local $SPIRet = DllCall("User32.dll", "int", "SystemParametersInfo", "uint", $SPI_GETWORKAREA, "uint", 0, "ptr", DllStructGetPtr($stRECT), "uint", 0)
  71.     If @error Then Return 0
  72.     If $SPIRet[0] = 0 Then Return 0
  73.  
  74.     Local $sLeftArea = DllStructGetData($stRECT, 1)
  75.     Local $sTopArea = DllStructGetData($stRECT, 2)
  76.     Local $sRightArea = DllStructGetData($stRECT, 3)
  77.     Local $sBottomArea = DllStructGetData($stRECT, 4)
  78.  
  79.     Local $aRet[4] = [$sLeftArea, $sTopArea, $sRightArea, $sBottomArea]
  80.     Return $aRet
  81. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement