#NoTrayIcon Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. ; Tray menu/item state values Const $TRAY_CHECKED = 1 Const $TRAY_UNCHECKED = 4 Const $TRAY_ENABLE = 64 Const $TRAY_DISABLE = 128 Const $TRAY_FOCUS = 256 Const $TRAY_DEFAULT = 512 Dim $DocMHandle Dim $DocMState Dim $SPPRHandle Dim $SPPRState $ShowDocM = TrayCreateItem("Show DocM") $HideDocM = TrayCreateItem("Hide DocM") TrayCreateItem("") $ShowSPPR = TrayCreateItem("Show SPPR") $HideSPPR = TrayCreateItem("Hide SPPR") TrayCreateItem("") $ExitItem = TrayCreateItem("Exit Minimizer") TraySetState() $begin = TimerInit() FindApp("[REGEXPTITLE:(Документооборот\s8\sКОРП); CLASS:V8TopLevelFrameSDI]", $ShowDocM, $HideDocM, $DocMHandle, $DocMState) FindApp("[REGEXPTITLE:(Система проектирования прикладных решений); CLASS:V8TopLevelFrameSDI]", $ShowSPPR, $HideSPPR, $SPPRHandle, $SPPRState) While 1 $dif = TimerDiff($begin) If $dif > 1000 Then FindApp("[REGEXPTITLE:(Документооборот\s8\sКОРП); CLASS:V8TopLevelFrameSDI]", $ShowDocM, $HideDocM, $DocMHandle, $DocMState) FindApp("[REGEXPTITLE:(Система проектирования прикладных решений); CLASS:V8TopLevelFrameSDI]", $ShowSPPR, $HideSPPR, $SPPRHandle, $SPPRState) RefineDesigners("[REGEXPTITLE:(Конфигуратор\s-)|(Designer\s-); CLASS:V8TopLevelFrame]") $begin = TimerInit() EndIf $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $ShowDocM ShowApp($DocMHandle, $ShowDocM, $HideDocM, $DocMState) Case $msg = $HideDocM HideApp($DocMHandle, $ShowDocM, $HideDocM, $DocMState) Case $msg = $ShowSPPR ShowApp($SPPRHandle, $ShowSPPR, $HideSPPR, $SPPRState) Case $msg = $HideSPPR HideApp($SPPRHandle, $ShowSPPR, $HideSPPR, $SPPRState) Case $msg = $ExitItem ShowApp($DocMHandle, $ShowDocM, $HideDocM, $DocMState) ShowApp($SPPRHandle, $ShowSPPR, $HideSPPR, $SPPRState) ExitLoop EndSelect WEnd Exit Func FindApp($AppTitle, $ShowCommand, $HideCommand, ByRef $AppHandle, ByRef $AppState) $AppHandle = WinGetHandle($AppTitle) If @error Then TrayItemSetState($ShowCommand, $TRAY_DISABLE + $TRAY_UNCHECKED) TrayItemSetState($HideCommand, $TRAY_DISABLE + $TRAY_UNCHECKED) Else $state = WinGetState($AppHandle) If BitAnd($state, 16) Then ; window is minimized $AppState = $state HideApp($AppHandle, $ShowCommand, $HideCommand, $AppState) Else If BitAnd($state, 2) Then ; windows is visible TrayItemSetState($ShowCommand, $TRAY_DISABLE + $TRAY_UNCHECKED) TrayItemSetState($HideCommand, $TRAY_ENABLE + $TRAY_UNCHECKED) Else TrayItemSetState($ShowCommand, $TRAY_ENABLE + $TRAY_UNCHECKED) TrayItemSetState($HideCommand, $TRAY_DISABLE + $TRAY_UNCHECKED) EndIf EndIf EndIf EndFunc Func ShowApp($AppHandle, $ShowCommand, $HideCommand, $AppState) If WinExists($AppHandle) Then WinSetState($AppHandle, "", @SW_SHOW) If BitAnd($AppState, 16) Then WinSetState($AppHandle, "", @SW_RESTORE) EndIf TrayItemSetState($ShowCommand, $TRAY_DISABLE + $TRAY_UNCHECKED) TrayItemSetState($HideCommand, $TRAY_ENABLE + $TRAY_UNCHECKED) EndIf EndFunc Func HideApp($AppHandle, $ShowCommand, $HideCommand, $AppState) If WinExists($AppHandle) Then WinSetState($AppHandle, "", @SW_HIDE) TrayItemSetState($ShowCommand, $TRAY_ENABLE + $TRAY_UNCHECKED) TrayItemSetState($HideCommand, $TRAY_DISABLE + $TRAY_UNCHECKED) EndIf EndFunc Func RefineDesigners($AppTitle) Local $Designers = WinList($AppTitle) For $i = 1 To $Designers[0][0] $DesignerPID = WinGetProcess($Designers[$i][1]) $DesignerCmdLine = _ProcessGetCommandLine($DesignerPID) $DesignerPath = StringRegExp($DesignerCmdLine, '/(IBName|F|S|f|s)\s*\"(.+)\"', 1) $DesignerTitle = WinGetTitle($Designers[$i][0]) If IsArray($DesignerPath) And StringInStr($DesignerTitle, $DesignerPath[1], 2) = 0 Then ;Tooltip($DesignerPath[4] & " - " & $DesignerTitle, 0, 50) WinSetTitle($Designers[$i][1], "", $DesignerPath[1] & " - " & $DesignerTitle) EndIf Next EndFunc Func _ProcessGetCommandLine($iPID) Local $aCall = DllCall("kernel32.dll", "handle", "OpenProcess", _ "dword", 1040, _ ; PROCESS_VM_READ | PROCESS_QUERY_INFORMATION "bool", 0, _ "dword", $iPID) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") EndIf Local $hProcess = $aCall[0] Local $tPROCESS_BASIC_INFORMATION = DllStructCreate("dword_ptr ExitStatus;" & _ "ptr PebBaseAddress;" & _ "dword_ptr AffinityMask;" & _ "dword_ptr BasePriority;" & _ "dword_ptr UniqueProcessId;" & _ "dword_ptr InheritedFromUniqueProcessId") $aCall = DllCall("ntdll.dll", "int", "NtQueryInformationProcess", _ "handle", $hProcess, _ "dword", 0, _ ; ProcessBasicInformation "ptr", DllStructGetPtr($tPROCESS_BASIC_INFORMATION), _ "dword", DllStructGetSize($tPROCESS_BASIC_INFORMATION), _ "dword*", 0) If @error Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) Return SetError(2, 0, "") EndIf Local $tPEB = DllStructCreate("byte InheritedAddressSpace;" & _ "byte ReadImageFileExecOptions;" & _ "byte BeingDebugged;" & _ "byte Spare;" & _ "ptr Mutant;" & _ "ptr ImageBaseAddress;" & _ "ptr LoaderData;" & _ "ptr ProcessParameters;" & _ "ptr SubSystemData;" & _ "ptr ProcessHeap;" & _ "ptr FastPebLock;" & _ "ptr FastPebLockRoutine;" & _ "ptr FastPebUnlockRoutine;" & _ "dword EnvironmentUpdateCount;" & _ "ptr KernelCallbackTable;" & _ "ptr EventLogSection;" & _ "ptr EventLog;" & _ "ptr FreeList;" & _ "dword TlsExpansionCounter;" & _ "ptr TlsBitmap;" & _ "dword TlsBitmapBits[2];" & _ "ptr ReadOnlySharedMemoryBase;" & _ "ptr ReadOnlySharedMemoryHeap;" & _ "ptr ReadOnlyStaticServerData;" & _ "ptr AnsiCodePageData;" & _ "ptr OemCodePageData;" & _ "ptr UnicodeCaseTableData;" & _ "dword NumberOfProcessors;" & _ "dword NtGlobalFlag;" & _ "ubyte Spare2[4];" & _ "int64 CriticalSectionTimeout;" & _ "dword HeapSegmentReserve;" & _ "dword HeapSegmentCommit;" & _ "dword HeapDeCommitTotalFreeThreshold;" & _ "dword HeapDeCommitFreeBlockThreshold;" & _ "dword NumberOfHeaps;" & _ "dword MaximumNumberOfHeaps;" & _ "ptr ProcessHeaps;" & _ "ptr GdiSharedHandleTable;" & _ "ptr ProcessStarterHelper;" & _ "ptr GdiDCAttributeList;" & _ "ptr LoaderLock;" & _ "dword OSMajorVersion;" & _ "dword OSMinorVersion;" & _ "dword OSBuildNumber;" & _ "dword OSPlatformId;" & _ "dword ImageSubSystem;" & _ "dword ImageSubSystemMajorVersion;" & _ "dword ImageSubSystemMinorVersion;" & _ "dword GdiHandleBuffer[34];" & _ "dword PostProcessInitRoutine;" & _ "dword TlsExpansionBitmap;" & _ "byte TlsExpansionBitmapBits[128];" & _ "dword SessionId") $aCall = DllCall("kernel32.dll", "bool", "ReadProcessMemory", _ "ptr", $hProcess, _ "ptr", DllStructGetData($tPROCESS_BASIC_INFORMATION, "PebBaseAddress"), _ "ptr", DllStructGetPtr($tPEB), _ "dword", DllStructGetSize($tPEB), _ "dword*", 0) If @error Or Not $aCall[0] Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) Return SetError(3, 0, "") EndIf Local $tPROCESS_PARAMETERS = DllStructCreate("dword AllocationSize;" & _ "dword ActualSize;" & _ "dword Flags;" & _ "dword Unknown1;" & _ "word LengthUnknown2;" & _ "word MaxLengthUnknown2;" & _ "ptr Unknown2;" & _ "handle InputHandle;" & _ "handle OutputHandle;" & _ "handle ErrorHandle;" & _ "word LengthCurrentDirectory;" & _ "word MaxLengthCurrentDirectory;" & _ "ptr CurrentDirectory;" & _ "handle CurrentDirectoryHandle;" & _ "word LengthSearchPaths;" & _ "word MaxLengthSearchPaths;" & _ "ptr SearchPaths;" & _ "word LengthApplicationName;" & _ "word MaxLengthApplicationName;" & _ "ptr ApplicationName;" & _ "word LengthCommandLine;" & _ "word MaxLengthCommandLine;" & _ "ptr CommandLine;" & _ "ptr EnvironmentBlock;" & _ "dword Unknown[9];" & _ "word LengthUnknown3;" & _ "word MaxLengthUnknown3;" & _ "ptr Unknown3;" & _ "word LengthUnknown4;" & _ "word MaxLengthUnknown4;" & _ "ptr Unknown4;" & _ "word LengthUnknown5;" & _ "word MaxLengthUnknown5;" & _ "ptr Unknown5;") $aCall = DllCall("kernel32.dll", "bool", "ReadProcessMemory", _ "ptr", $hProcess, _ "ptr", DllStructGetData($tPEB, "ProcessParameters"), _ "ptr", DllStructGetPtr($tPROCESS_PARAMETERS), _ "dword", DllStructGetSize($tPROCESS_PARAMETERS), _ "dword*", 0) If @error Or Not $aCall[0] Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) Return SetError(4, 0, "") EndIf $aCall = DllCall("kernel32.dll", "bool", "ReadProcessMemory", _ "ptr", $hProcess, _ "ptr", DllStructGetData($tPROCESS_PARAMETERS, "CommandLine"), _ "wstr", "", _ "dword", DllStructGetData($tPROCESS_PARAMETERS, "MaxLengthCommandLine"), _ "dword*", 0) If @error Or Not $aCall[0] Then DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) Return SetError(5, 0, "") EndIf DllCall("kernel32.dll", "bool", "CloseHandle", "handle", $hProcess) Return $aCall[3] EndFunc