#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Icon_Add=Resourses\yes.ico
#AutoIt3Wrapper_Res_Icon_Add=Resourses\no.ico
#AutoIt3Wrapper_Res_Icon_Add=Resourses\att.ico
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
#include <HotKey.au3>;Yashied, http://autoit-script.ru/index.php/topic,296.0.html
#include <WinAPIEx.au3>;Yashied, http://autoit-script.ru/index.php/topic,47.0.html
#include <File.au3>
#include <FontConstants.au3>
Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 3)
Global Const $VK_ESCAPE = 0x1B
Global Const $VK_F11 = 0x7A
Global $sTitleScript = @ScriptName & '{[/@$@\]}', $sClassWin = '[Class:KMeleon Browser Window]', _
$fExist, $fExist_Old, $aLast_Files[1][2], $fReg, $hAutoIt, $ahTimer, $hPrev, $iStart, _
$nDeleteItem, $nRegItem, $nSaveItem, $nMenuOpen, $nExitItem, $nMsgTray, _
$sDir_Save = @DesktopDir & '\SavedScripts', $fActive, $hWinActive, $ahActive
If WinExists($sTitleScript) Then Exit
AutoItWinSetTitle($sTitleScript)
$hAutoIt = WinGetHandle(AutoItWinGetTitle())
_HotKeyAssign($VK_F11, '_Get_AutoIt_Code_K_Meleon', $HK_FLAG_DEFAULT, $sClassWin);F11 - сохранить
_HotKeyAssign(BitOR($CK_CONTROL, $CK_SHIFT, $VK_ESCAPE), '_Exit');Ctrl+Shift+Esc - выход
_CheckReg()
$nDeleteItem = TrayCreateItem('Удалить утилиту')
If $fReg Then
$nRegItem = TrayCreateItem('Убрать из автозагрузки')
Else
$nRegItem = TrayCreateItem('Добавить в автозагрузку')
EndIf
If Not @Compiled Then
TrayItemSetState($nRegItem, $TRAY_DISABLE)
TrayItemSetState($nDeleteItem, $TRAY_DISABLE)
EndIf
$nSaveItem = TrayCreateItem('Сохранить выделенное.....F11')
$nMenuOpen = TrayCreateMenu('Открыть -->')
TrayItemSetState($nMenuOpen, $TRAY_DISABLE)
TrayCreateItem('')
$nExitItem = TrayCreateItem('Выход.....Ctrl+Shift+Esc')
TraySetState()
TraySetClick(8)
If WinExists($sClassWin) Then
$fExist = True
Else
$fExist = False
EndIf
$fExist_Old = Not $fExist
_WinAPI_EmptyWorkingSet()
While 1
If WinExists($sClassWin) Then
$fExist = True
Else
$fExist = False
EndIf
If $fExist_Old <> $fExist Then
$fExist_Old = $fExist
If $fExist_Old Then
TrayItemSetState($nSaveItem, $TRAY_ENABLE)
If $aLast_Files[0][0] Then
If @Compiled Then
TraySetIcon(@ScriptFullPath, 201)
Else
TraySetIcon(@ScriptDir & '\Resourses\yes.ico')
EndIf
Else
If @Compiled Then
TraySetIcon(@ScriptFullPath, 203)
Else
TraySetIcon(@ScriptDir & '\Resourses\att.ico')
EndIf
EndIf
$ahActive = _CallBack_Init('_GetActive', 500)
Else
TrayItemSetState($nSaveItem, $TRAY_DISABLE)
If @Compiled Then
TraySetIcon(@ScriptFullPath, 202)
Else
TraySetIcon(@ScriptDir & '\Resourses\no.ico')
EndIf
If IsArray($ahActive) Then
_CallBack_Free($ahActive)
$hWinActive = 0
EndIf
EndIf
EndIf
$nMsgTray = TrayGetMsg()
Switch $nMsgTray
Case 0
ContinueLoop
Case $nExitItem
Exit
Case $nDeleteItem
If MsgBox(262436, 'Save Scripts', 'Вы уверены, что хотите удалить утилиту?') = 6 Then
_RegRunDel()
_ScriptDestroy()
EndIf
Case $nRegItem
If @Compiled Then
$fReg = Not $fReg
If $fReg Then
TrayItemSetText($nRegItem, 'Убрать из автозагрузки')
_RegRun()
Else
TrayItemSetText($nRegItem, 'Добавить в автозагрузку')
_RegRunDel()
EndIf
EndIf
Case $nSaveItem
$fActive = True
_HotKeyAssign($VK_F11)
_Get_AutoIt_Code_K_Meleon()
$fActive = False
_HotKeyAssign($VK_F11, '_Get_AutoIt_Code_K_Meleon', $HK_FLAG_DEFAULT, $sClassWin)
_WinAPI_EmptyWorkingSet()
Case Else
If $aLast_Files[0][0] Then
For $i = 1 To $aLast_Files[0][0]
If $aLast_Files[$i][1] = $nMsgTray Then
_Open_Last_AU3($i)
ExitLoop
EndIf
Next
EndIf
EndSwitch
WEnd
Func _GetActive()
Local $a_WinList_K_Meleon
$a_WinList_K_Meleon = WinList($sClassWin)
If Not $a_WinList_K_Meleon[0][0] Then
Return
EndIf
For $i = 1 To $a_WinList_K_Meleon[0][0]
If WinActive($a_WinList_K_Meleon[$i][1]) Then
If $hWinActive <> $a_WinList_K_Meleon[$i][1] Then
$hWinActive = $a_WinList_K_Meleon[$i][1]
EndIf
Return
EndIf
Next
EndFunc ;==>_GetActive
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _Open_Last_AU3($i_Index)
Local $s_FilePath = $sDir_Save & '\' & $aLast_Files[$i_Index][0]
If FileExists($s_FilePath) Then
ShellExecute($s_FilePath)
If @error Then
_WinAPI_MessageBeep(2)
Else
_WinAPI_MessageBeep(3)
EndIf
Else
_WinAPI_MessageBeep(2)
EndIf
EndFunc ;==>_Open_Last_AU3
Func _Get_AutoIt_Code_K_Meleon()
Local $a_WinList_K_Meleon, $h_Win_Handle, $s_Old_ClipGet, $s_New_ClipGet, $i_Timer_Start, $s_Title, _
$s_FileName, $h_File, $i_CountFiles
$iStart = TimerInit()
$ahTimer = _CallBack_Init('_Increment', 100)
If $fActive Then
$h_Win_Handle = $hWinActive
If WinExists($h_Win_Handle) Then
WinActivate($h_Win_Handle)
WinWaitActive($h_Win_Handle)
Else
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
Return
EndIf
Else
$a_WinList_K_Meleon = WinList($sClassWin)
If Not $a_WinList_K_Meleon[0][0] Then
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
Return
EndIf
For $i = 1 To $a_WinList_K_Meleon[0][0]
If WinActive($a_WinList_K_Meleon[$i][1]) Then
$h_Win_Handle = $a_WinList_K_Meleon[$i][1]
ExitLoop
EndIf
Next
EndIf
If Not $h_Win_Handle Then
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
Return
EndIf
$s_Old_ClipGet = ClipGet()
ClipPut('')
If Not ControlSend($h_Win_Handle, '', '', '^{INSERT}') Then
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
ClipPut($s_Old_ClipGet)
Return
EndIf
$s_New_ClipGet = ClipGet()
$i_Timer_Start = TimerInit()
While Not $s_New_ClipGet And TimerDiff($i_Timer_Start) < 3000
$s_New_ClipGet = ClipGet()
Sleep(20)
WEnd
ClipPut($s_Old_ClipGet)
If Not $s_New_ClipGet Then
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
Return
EndIf
$s_Title = WinGetTitle($h_Win_Handle)
If Not $s_Title Then
$s_FileName = @MDAY & '_' & @MON & '_' & @HOUR & '_' & @MIN
Else
$s_FileName = StringReplace($s_Title, ' (K-Meleon)', '')
$s_FileName = StringRegExpReplace($s_FileName, '[^0-9a-zA-Zа-яА-ЯёЁ]', '_')
$s_FileName = StringRegExpReplace($s_FileName, '(_){2,}', '$1')
EndIf
If StringLen($s_FileName) > 20 Then
$s_FileName = StringLeft($s_FileName, 20)
EndIf
If FileExists($sDir_Save & '\' & $s_FileName & '.au3') Then
While 1
$i_CountFiles += 1
If Not FileExists($sDir_Save & '\' & $i_CountFiles & '_' & $s_FileName & '.au3') Then
$s_FileName = $i_CountFiles & '_' & $s_FileName
ExitLoop
EndIf
Sleep(1)
WEnd
EndIf
$s_FileName &= '.au3'
$h_File = FileOpen($sDir_Save & '\' & $s_FileName, 10)
If $h_File = -1 Then
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
Return
EndIf
If Not FileWrite($h_File, $s_New_ClipGet) Then
FileClose($h_File)
_WinAPI_MessageBeep(2)
_CallBack_Free($ahTimer)
Return
EndIf
FileClose($h_File)
Sleep(1000) ;только чтобы успеть увидеть отсчет иконки в трее :)
_WinAPI_MessageBeep(3)
_ReDim_Array_Create_Items($s_FileName, $aLast_Files)
_CallBack_Free($ahTimer)
If Not $fActive Then
_WinAPI_EmptyWorkingSet()
EndIf
Return
EndFunc ;==>_Get_AutoIt_Code_K_Meleon
Func _CheckReg()
Local $s_RegRun = 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
If RegRead($s_RegRun, @ScriptName) = '"' & @ScriptFullPath & '"' Then
$fReg = True
EndIf
EndFunc ;==>_CheckReg
Func _RegRun()
Local $s_RegRun = 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
If RegRead($s_RegRun, @ScriptName) = '' Or RegRead($s_RegRun, @ScriptName) <> '"' & @ScriptFullPath & '"' Then
RegWrite($s_RegRun, @ScriptName, 'REG_SZ', '"' & @ScriptFullPath & '"')
EndIf
EndFunc ;==>_RegRun
Func _RegRunDel()
Local $s_RegRun = 'HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
RegDelete($s_RegRun, @ScriptName)
EndFunc ;==>_RegRunDel
Func _ScriptDestroy()
Local $s_Temp, $s_Path, $s_Temp, $s_Text_Del, $h_File
$s_Temp = _TempFile(@TempDir, '~', '.bat')
$s_Path = FileGetShortName(@ScriptFullPath)
$s_Text_Del = '@echo off' & @CRLF & ':loop' & @CRLF & 'del ' & $s_Path & @CRLF & 'if exist ' & _
$s_Path & ' goto loop' & @CRLF & 'del %0'
$h_File = FileOpen($s_Temp, 2)
FileWrite($h_File, $s_Text_Del)
FileClose($h_File)
Run($s_Temp, '', @SW_HIDE)
Exit
EndFunc ;==>_ScriptDestroy
Func _ReDim_Array_Create_Items($s_String, ByRef $a_Array)
Local $a_Temp_Array
If Not $a_Array[0][0] Then
$a_Array[0][0] = 1
ReDim $a_Array[2][2]
$a_Array[1][0] = $s_String
$a_Array[1][1] = TrayCreateItem($s_String, $nMenuOpen)
TrayItemSetState($nMenuOpen, $TRAY_ENABLE)
If @Compiled Then
TraySetIcon(@ScriptFullPath, 201)
Else
TraySetIcon(@ScriptDir & '\Resourses\yes.ico')
EndIf
Return
EndIf
$a_Temp_Array = $a_Array
$a_Array[0][0] += 1
ReDim $a_Array[$a_Array[0][0] + 1][2]
For $i = 1 To $a_Array[0][0] - 1
TrayItemDelete($a_Array[$i][1])
$a_Array[$i + 1][0] = $a_Temp_Array[$i][0]
Next
$a_Array[1][0] = $s_String
If $a_Array[0][0] > 10 Then
ReDim $a_Array[11][2]
$a_Array[0][0] = 10
EndIf
For $i = 1 To $a_Array[0][0]
$a_Array[$i][1] = TrayCreateItem($a_Array[$i][0], $nMenuOpen)
Next
If @Compiled Then
TraySetIcon(@ScriptFullPath, 201)
Else
TraySetIcon(@ScriptDir & '\Resourses\yes.ico')
EndIf
EndFunc ;==>_ReDim_Array_Create_Items
Func _Increment()
Local $s_Time = StringRight(StringFormat('%.1f', TimerDiff($iStart) / 1000), 3)
_SetAutoItIcon($s_Time, 0xFF0000, 0xFFDEAD)
EndFunc ;==>_Increment
Func _SetAutoItIcon($iCount, $iColor = 0x000000, $iBkColor = 0xFFFFFF)
;Yashied, http://autoit-script.ru/index.php?topic=6030.msg42829#msg42829
Local $hDC, $hBitmap, $hMask, $hIcon, $hFont, $tNID, $tRect
$hDC = _WinAPI_CreateCompatibleDC(0)
$hBitmap = _WinAPI_CreateSolidBitmap(0, $iBkColor, 16, 16)
$hMask = _WinAPI_CreateBitmap(16, 16, 1, 1)
$hFont = _WinAPI_CreateFont(18, 4, 0, 0, $FW_MEDIUM, 0, 0, 0, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $ANTIALIASED_QUALITY, $DEFAULT_PITCH, 'Tahoma')
$tRect = _WinAPI_CreateRectEx(1, 0, 15, 16)
_WinAPI_SelectObject($hDC, $hBitmap)
_WinAPI_SelectObject($hDC, $hFont)
_WinAPI_SetTextColor($hDC, _WinAPI_SwitchColor($iColor))
_WinAPI_SetBkColor($hDC, _WinAPI_SwitchColor($iBkColor))
_WinAPI_DrawText($hDC, $iCount, $tRect, BitOR($DT_CENTER, $DT_SINGLELINE, $DT_VCENTER))
_WinAPI_DeleteDC($hDC)
$hIcon = _WinAPI_CreateIconIndirect($hBitmap, $hMask)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteObject($hMask)
_WinAPI_DeleteObject($hFont)
$tNID = DllStructCreate($tagNOTIFYICONDATA)
DllStructSetData($tNID, 'Size', DllStructGetSize($tNID))
DllStructSetData($tNID, 'hWnd', $hAutoIt)
DllStructSetData($tNID, 'Flags', $NIF_ICON)
DllStructSetData($tNID, 'ID', 1)
DllStructSetData($tNID, 'hIcon', $hIcon)
_WinAPI_ShellNotifyIcon($NIM_MODIFY, $tNID)
If $hPrev Then
_WinAPI_DestroyIcon($hPrev)
EndIf
$hPrev = $hIcon
EndFunc ;==>_SetAutoItIcon
Func _CallBack_Init($sFuncName, $iTime, $sParam = '')
Local $hCallBack = DllCallbackRegister($sFuncName, 'int', $sParam)
Local $aTimer = DllCall('user32.dll', 'uint', 'SetTimer', _
'hwnd', 0, 'uint', 0, 'int', $iTime, 'ptr', DllCallbackGetPtr($hCallBack))
Local $ahCallBack[2] = [$hCallBack, $aTimer[0]]
Return $ahCallBack
EndFunc ;==>_CallBack_Init
Func _CallBack_Free($ahCallBack)
If $ahCallBack[0] <> -1 Then DllCallbackFree($ahCallBack[0])
If $ahCallBack[1] <> -1 Then DllCall('user32.dll', 'int', 'KillTimer', 'hwnd', 0, 'uint', $ahCallBack[1])
EndFunc ;==>_CallBack_Free