- Сообщения
- 5,379
- Репутация
- 2,724
Код:
#NoTrayIcon
#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>
Opt('OnExitFunc', '_AutoItExit')
Opt('WinTitleMatchMode', 3)
Opt('WinWaitDelay', 0)
$Title = 'Untitled - Notepad'
$hParent = GUICreate('', 0, 0, 0, 0, 0, $WS_EX_TOOLWINDOW)
$hForm = GUICreate('MyGUI', 400, 100, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), $WS_EX_DLGMODALFRAME, $hParent)
$hIcon = _WinAPI_GetClassLong($hForm, $GCL_HICON)
_WinAPI_FreeIcon($hIcon)
_WinAPI_SetClassLong($hForm, $GCL_HICON, 0)
_WinAPI_SetClassLong($hForm, $GCL_HICONSM, 0)
GUISetState()
GUIRegisterMsg(_WinAPI_RegisterWindowMessage('SHELLHOOK'), '_ShellHookProc')
_WinAPI_RegisterShellHookWindow($hForm)
Run('notepad.exe')
If Not WinWaitActive($Title, '', 5) Then
Exit
EndIf
Do
If WinExists($Title) Then
If BitAND(WinGetState($Title), 16) Then
If BitAND(WinGetState($hForm), 2) Then
WinSetState($hForm, '', @SW_HIDE)
EndIf
Else
If Not BitAND(WinGetState($hForm), 2) Then
WinSetState($hForm, '', @SW_SHOW)
EndIf
EndIf
Else
ExitLoop
EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func _ShellHookProc($hWnd, $iMsg, $wParam, $lParam)
Local $ExStyle
Switch $hWnd
Case $hForm
Switch $wParam
Case $HSHELL_WINDOWACTIVATED
If BitAND(WinGetState('Untitled - Notepad'), 8) Then
WinSetOnTop($hForm, '', 1)
Else
WinSetOnTop($hForm, '', 0)
$ExStyle = _WinAPI_GetWindowLong($lParam, $GWL_EXSTYLE)
WinSetOnTop($lParam, '', 1)
If Not BitAND($ExStyle, $WS_EX_TOPMOST) Then
WinSetOnTop($lParam, '', 0)
EndIf
EndIf
EndSwitch
EndSwitch
EndFunc ;==>_ShellHookProc
Func _AutoItExit()
_WinAPI_DeregisterShellHookWindow($hForm)
EndFunc ;==>_AutoItExit