<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AutoHotkey: Отображение загрузки процессора на кнопке Пуск]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=309</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=309&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AutoHotkey: Отображение загрузки процессора на кнопке Пуск».]]></description>
		<lastBuildDate>Fri, 22 Oct 2010 13:13:19 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AutoHotkey: Отображение загрузки процессора на кнопке Пуск]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=40736#p40736</link>
			<description><![CDATA[<p>Расширение функционала предыдущего скрипта. В дополнение к отражению загрузки процессора, при наведении курсора на кнопку Пуск появляется ToolTip со сведениями о нескольких наиболее загружающих CPU процессах. Имеется возможность настраивать скрипт.<br /></p><div class="codebox"><pre><code>/*
   Скрипт предназначен для отображения сведений о загрузке CPU на кнопке Пуск (вместо
надписи &quot;Пуск&quot;). При наведении курсора на кнопку Пуск появляется ToolTip, в котором
отображается информация о нескольких (по умолчанию 3-х) процессах, занимающих в данный
период (1 секунду) наибольшую часть процессорного времени.

   ToolTip можно передвинуть левой кнопкой мыши в любое удобное место на экране, новое
положение будет сохранено в ini-файле.

   Щёлкнув левой кнопкой мыши по ToolTip&#039;у, можно вызвать Диспетчер задач Windows,
правой — окно настроек. Пункты настроек:

1. Сколько процессов показать?
   Выбрать, сколько процессов, загрузка которых не менее 1% будут отображаться
   в ToolTip&#039;е.

2. Показывать заголовок.
   При снятии галочки в ToolTip&#039;е не будет появляться заголовок &quot;Max Load Info&quot;
   с иконкой.

3. Показывать дату.
   При запуске скрипта уничтожается системная всплывающая подсказка при наведении
   курсора на часы на панели задач с отображением даты. При установленной галочке
   скрипт покажет её. Работает, только если панель задач не растянута в несколько
   строк (при этом дата отображается на панели задач).

4. Настройка размеров кнопки Пуск.
   Можно скорректировать размеры кнопки Пуск, изменяя положение её левой и правой
   границы. Для этого поместите курсор в соответствующее поле, нажмите левую кнопку
   мыши и двигайте влево или вправо. Соответственно будет сдвигаться граница кнопки.
   Новые размеры будут сохранены в ini-файле, по окончании работы скрипта система
   восстановит первоначальные.

5. Знак % на кнопке.
   Показывать ли знак % при отображении загрузки CPU на кнопке Пуск.

Все настройки применяются сразу же, кнопка OK закрывает окно, сохраняя его позицию
в ini-файле.

Прошу свои отзывы о работе скрипта, предложения и сообщения о замеченных багах
оставлять здесь: http://forum.script-coding.com/viewtopic.php?id=5038
*/

   SetBatchLines, -1
   CoordMode, Mouse
   CoordMode, ToolTip
   SetWinDelay, 0

   Title = Max Load Info   ; заголовок ToolTip&#039;а

   AttemptKill = 0
   IniName := A_ScriptDir &quot;\&quot; RegExReplace(A_ScriptName, &quot;(.*)\..*&quot;, &quot;$1&quot;) &quot;.ini&quot;

   IniRead, HowManyProcShow, % IniName, Settings, HowManyProcShow, 3
   IniRead, ShowTitle, % IniName, Settings, ShowTitle, 1
   IniRead, ShowDate, % IniName, Settings, ShowDate, 1
   IniRead, ShowPercent, % IniName, Settings, ShowPercent, 1
   IniRead, xTT, % IniName, Positions, xTT, % &quot; &quot;
   IniRead, yTT, % IniName, Positions, yTT, % &quot; &quot;
   IniRead, xSett, % IniName, Positions, xSett, % &quot; &quot;
   IniRead, ySett, % IniName, Positions, ySett, % &quot; &quot;
   IniRead, xButt, % IniName, Positions, xButt, % &quot; &quot;
   IniRead, wButt, % IniName, Positions, wButt, % &quot; &quot;

   ControlGetPos, _XButt,, _WButt,, Button1, ahk_class Shell_TrayWnd
   WinGetPos, XTray, YTray, WTray, HTray, ahk_class Shell_TrayWnd
   if (xTT = &quot;&quot; || yTT = &quot;&quot;)
   {
      xTT := XTray &gt; 10 ? XTray-120 : XTray+30
      yTT := YTray &gt; 10 ? YTray-100 : 50
   }
   if (xSett = &quot;&quot; || ySett = &quot;&quot;)
   {
      xSett := XTray &gt; 10 ? XTray-220 : XTray+25
      ySett := YTray &gt; 10 ? YTray-230 : 50
   }

   hTT := TrackToolTip(&quot;&quot;, &quot;&quot;, &quot;&quot;)

   AdjustPrivileges()
   EnvGet, NumCPU, NUMBER_OF_PROCESSORS
   OnMessage(WM_LBUTTONDOWN := 0x201, &quot;ToolMove&quot;)
   OnMessage(WM_RBUTTONUP := 0x205, &quot;Settings&quot;)
   SetTimer, CheckCPULoad, 1000

CheckCPULoad:
   WinWait, ahk_class Shell_TrayWnd
   SetFormat, float, 02
   CPULoad := GetCPULoad()
   List := GetProcessList()

   ProcessList := ShortProcessList := &quot;&quot;
   Loop, parse, List, |
   {
      PID := RegExReplace(A_LoopField, &quot;.*?,(.*),.*&quot;, &quot;$1&quot;)
      Time%PID% := RegExReplace(A_LoopField, &quot;.*,(.*)&quot;, &quot;$1&quot;)

      Load := Round((Time%PID% - OldTime%PID%)/NumCPU/10000000 * 100)
      OldTime%PID% := Time%PID%
      ProcessList .= Load . &quot;%&quot; . RegExReplace(A_LoopField, &quot;(.*?),.*&quot;, &quot;$1&quot;) &quot;`n&quot;
   }
   if !once
   {
      once = 1
      Return
   }

   ControlMove, Button1, xButt ? XButt : _XButt - 5,
      , wButt ? wButt : (WTray &gt; 100 ? _WButt + 10 : _WButt + 15)

   if ShowPercent
      ControlSetText, Button1, % CPULoad &lt; 100 ? &quot; &quot; CPULoad &quot; %&quot; : CPULoad &quot;%&quot;
   Else
      ControlSetText, Button1, % CPULoad &lt; 100 ? &quot;  &quot; CPULoad : &quot; &quot; CPULoad

   MouseGetPos,, yMouse, WinID, Control
   WinGetClass, Class, ahk_id %WinID%

   if (ShowDate &amp;&amp; Class = &quot;Shell_TrayWnd&quot; &amp;&amp; Control = &quot;TrayClockWClass1&quot;)
   {
      FormatTime, Date
      WinGetPos, XTray, YTray, WTray, HTray, ahk_class Shell_TrayWnd
      if !((WTray &gt; 200 &amp;&amp; HTray &gt; 40) || (HTray &gt; 200 &amp;&amp; WTray &gt; 40))
      {
         if !(AttemptKill &gt; 2 || ToolTipDead)
            ToolTipDead := ToolTipKill(A_YYYY), ++AttemptKill
         Date := RegExReplace(Date, &quot;.*:.. +(.*)&quot;, &quot; $1&quot;)
         ToolTip, % Date,, YTray &gt; 40 ? YTray - 25 : YTray + HTray + 10
      }
   }
   Else
      ToolTip

   if !((Class = &quot;Shell_TrayWnd&quot; &amp;&amp; Control = &quot;Button1&quot;) || WinID = hTT)
   {
      SetTimer, CloseToolTip, -300
      Return
   }

   if !(AttemptKill &gt; 2 || ToolTipDead)
      ToolTipDead := ToolTipKill(&quot;Начните работу&quot;), ++AttemptKill

   StringTrimRight, ProcessList, ProcessList, 1
   Sort, ProcessList, N R D`n

   EmptyString =
   Loop % HowManyProcShow
      EmptyString .= &quot;`n&quot;

   Loop, parse, ProcessList, `n
   {
      if (RegExReplace(A_LoopField, &quot;(.*)%.*&quot;, &quot;$1&quot;) = 0 || A_Index = HowManyProcShow + 1)
         Break
      ShortProcessList .= A_LoopField . &quot;`n&quot;
      StringTrimRight, EmptyString, EmptyString, 1
   }

   SPL := RegExReplace(SubStr(ShortProcessList, 1, -1), &quot;m`a)(.*%)(.*)&quot;, &quot;$2   $1&quot;)
   ToolTipText := SPL ? SPL . EmptyString : &quot;Нет загрузки&quot; . SubStr(EmptyString, 1, -1)

   TrackToolTip(xTT, yTT, ToolTipText, ShowTitle ? Title : &quot;&quot;, 1)
   PosCorrection()
   Return

CloseToolTip:
   DllCall(&quot;SendMessage&quot;, UInt, hTT, UInt, 1041, UInt, 0, UInt, &amp;TOOLINFO)   ; TTM_TRACKACTIVATE
   Return

ToolTipKill(Text)
{
   local PID
   DetectHiddenWindows, On
   WinGet, TTList, List, ahk_class tooltips_class32
   Loop % TTList
   {
      ControlGetText, Content,, % &quot;ahk_id &quot; TTList%A_Index%
      if InStr(Content, Text)
      {
         WinGet, PID, PID, % &quot;ahk_id &quot; TTList%A_Index%
         if (PID != DllCall(&quot;GetCurrentProcessId&quot;))
            WinClose, % &quot;ahk_id &quot; TTList%A_Index%
         if !WinExist(&quot;ahk_id &quot; TTList%A_Index%)
            ToolTipDead = 1
         Break
      }
   }
   Return ToolTipDead
}

AdjustPrivileges()
{
   Process, Exist  ; sets ErrorLevel to the PID of this running script
   ; Get the handle of this script with PROCESS_QUERY_INFORMATION (0x0400)
   h := DllCall(&quot;OpenProcess&quot;, &quot;UInt&quot;, 0x0400, &quot;Int&quot;, false, &quot;UInt&quot;, ErrorLevel)
   ; Open an adjustable access token with this process (TOKEN_ADJUST_PRIVILEGES = 32)
   DllCall(&quot;Advapi32.dll\OpenProcessToken&quot;, &quot;UInt&quot;, h, &quot;UInt&quot;, 32, &quot;UIntP&quot;, t)
   VarSetCapacity(ti, 16, 0)  ; structure of privileges
   NumPut(1, ti, 0)  ; one entry in the privileges array...
   ; Retrieves the locally unique identifier of the debug privilege:
    if A_IsUnicode
        DllCall(&quot;Advapi32.dll\LookupPrivilegeValueW&quot;, &quot;UInt&quot;, 0, &quot;Str&quot;, &quot;SeDebugPrivilege&quot;
                                               , &quot;Int64P&quot;, luid)
    else
        DllCall(&quot;Advapi32.dll\LookupPrivilegeValueA&quot;, &quot;UInt&quot;, 0, &quot;Str&quot;, &quot;SeDebugPrivilege&quot;
                                               , &quot;Int64P&quot;, luid)
   NumPut(luid, ti, 4, &quot;int64&quot;)
   NumPut(2, ti, 12)  ; enable this privilege: SE_PRIVILEGE_ENABLED = 2
   ; Update the privileges of this process with the new access token:
   DllCall(&quot;Advapi32.dll\AdjustTokenPrivileges&quot;, &quot;UInt&quot;, t, &quot;Int&quot;, false
                                               , &quot;UInt&quot;, &amp;ti, &quot;UInt&quot;, 0
                                               , &quot;UInt&quot;, 0, &quot;UInt&quot;, 0)
   DllCall(&quot;CloseHandle&quot;, &quot;UInt&quot;, h)  ; close this process handle to save memory
}

GetCPULoad()
{
   static
   global NumCPU
   IdleTime0 = %IdleTime%  ; Save previous values
   Tick0 = %Tick%
   if !IdleTicksCapacity
      IdleTicksCapacity := VarSetCapacity(IdleTicks, 8)
   DllCall(&quot;kernel32.dll\GetSystemTimes&quot;, UInt, &amp;IdleTicks, UInt, 0, UInt, 0)
   IdleTime := *(&amp;IdleTicks)
   Loop 7                  ; Ticks when Windows was idle
     IdleTime += *( &amp;IdleTicks + A_Index ) &lt;&lt; ( 8 * A_Index )
   Tick := A_TickCount     ; Ticks all together
   load := 100 - 0.01*(IdleTime - IdleTime0)/NumCPU/(Tick - Tick0)
   Return, InStr(load, &quot;-&quot;) ? 00 : load
}

GetProcessList()
{
   s := 4096  ; size of buffers and arrays (4 KB)

   hModule := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;Psapi.dll&quot;)  ; increase performance by preloading the libaray
   s := VarSetCapacity(a, s)  ; an array that receives the list of process identifiers:
   DllCall(&quot;Psapi.dll\EnumProcesses&quot;, &quot;UInt&quot;, &amp;a, &quot;UInt&quot;, s, &quot;UIntP&quot;, r)
   Loop, % r // 4  ; parse array for identifiers as DWORDs (32 bits):
   {
      id := NumGet(a, A_Index * 4)
      ; Open process with: PROCESS_VM_READ (0x0010) | PROCESS_QUERY_INFORMATION (0x0400)
      h := DllCall(&quot;OpenProcess&quot;, &quot;UInt&quot;, 0x0010 | 0x0400, &quot;Int&quot;, false, &quot;UInt&quot;, id)

      VarSetCapacity(n, s, 0)  ; a buffer that receives the base name of the module:
      e := DllCall(&quot;Psapi.dll\GetModuleBaseName&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;)
         , &quot;UInt&quot;, h, &quot;UInt&quot;, 0, &quot;Str&quot;, n, &quot;UInt&quot;, s)

      DllCall(&quot;GetProcessTimes&quot;, &quot;Uint&quot;, h, &quot;int64P&quot;, CreationTime, &quot;int64P&quot;
              , ExitTime, &quot;int64P&quot;, KrnlTime, &quot;int64P&quot;, UserTime)

      DllCall(&quot;CloseHandle&quot;, &quot;UInt&quot;, h)  ; close process handle to save memory
      if (n &amp;&amp; e)  ; if image is not null add to list:
         l .= n . &quot;,&quot; . id . &quot;,&quot; . KrnlTime + UserTime . &quot;|&quot;
   }

   Process, Exist, System
   id := ErrorLevel
   h := DllCall(&quot;OpenProcess&quot;, &quot;UInt&quot;, 0x0400, &quot;Int&quot;, false, &quot;UInt&quot;, id)
   DllCall(&quot;GetProcessTimes&quot;, &quot;Uint&quot;, h, &quot;int64P&quot;, CreationTime, &quot;int64P&quot;
           , ExitTime, &quot;int64P&quot;, KrnlTime, &quot;int64P&quot;, UserTime)
   DllCall(&quot;CloseHandle&quot;, &quot;UInt&quot;, h)
   l .= &quot;System,&quot; . id . &quot;,&quot; . KrnlTime + UserTime

   DllCall(&quot;FreeLibrary&quot;, &quot;UInt&quot;, hModule)  ; unload the library to free memory
   Return l
}

TrackToolTip(x, y, sText, sTitle = &quot;&quot;, h_icon = 0)
{
   ; h_icon — 0: None, 1:Info, 2: Warning, 3: Error. n &gt; 3: assumed to be an hIcon.
   static
   global hTT, TOOLINFO
   WS_EX_TOPMOST := 8, TTS_NOPREFIX := 2, TTS_ALWAYSTIP := 1

   if !hTT
   {
      hWnd := DllCall(&quot;CreateWindowEx&quot; , UInt, WS_EX_TOPMOST
                                       , Str, &quot;tooltips_class32&quot;
                                       , Str, &quot;&quot;
                                       , UInt, TTS_NOPREFIX|TTS_ALWAYSTIP
                                       , Int, 0, Int, 0, Int, 0, Int, 0
                                       , UInt, 0, UInt, 0, UInt, 0, UInt, 0)

      VarSetCapacity(TOOLINFO, 40, 0)
      NumPut(40, TOOLINFO)
      NumPut(0x20, TOOLINFO, 4)      ; TTF_TRACK = 0x20
      NumPut(&amp;sText, TOOLINFO, 36)

      VarSetCapacity(Rect, 16)
      NumPut(4, Rect)
      NumPut(5, Rect, 4)
      NumPut(5, Rect, 8)
      NumPut(5, Rect, 12)

      VarSetCapacity(Rect0, 16)
      NumPut(0, Rect0)
      NumPut(0, Rect0, 4)
      NumPut(0, Rect0, 8)
      NumPut(0, Rect0, 12)

   ; используется DllCall, т. к. работает и со скрытыми окнами, в отличие от SendMessage.
      DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1048, UInt, 0, UInt, 500)      ; TTM_SETMAXTIPWIDTH
      DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1028, UInt, 0, UInt, &amp;TOOLINFO)   ; TTM_ADDTOOL
      Return hWnd
   }
   else
   {
      if sTitle
         DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1050, UInt, 0, UInt, &amp;Rect0)   ; TTM_SETMARGIN
      Else
         DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1050, UInt, 0, UInt, &amp;Rect)   ; TTM_SETMARGIN

      NumPut(&amp;sText, TOOLINFO, 36)
      if A_IsUnicode
      {
         DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1057, UInt, h_icon            ; TTM_SETTITLEW
             , UInt, &amp;sTitle)
         DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1081, UInt, 0, UInt, &amp;TOOLINFO)   ; TTM_UPDATETIPTEXTW
      }
      Else
      {
         DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1056, UInt, h_icon            ; TTM_SETTITLE
             , UInt, &amp;sTitle)
         DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1036, UInt, 0, UInt, &amp;TOOLINFO)   ; TTM_UPDATETIPTEXT
      }
      DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1042, UInt, 0, UInt         ; TTM_TRACKPOSITION
         , (x &amp; 0xFFFF)|(y &amp; 0xFFFF)&lt;&lt;16)
      DllCall(&quot;SendMessage&quot;, UInt, hWnd, UInt, 1041, UInt, 1, UInt, &amp;TOOLINFO)   ; TTM_TRACKACTIVATE
   }
}

ToolMove(wParam, lParam, msg, hwnd)
{
   global
   if (hwnd = hSett)
      PostMessage, WM_NCLBUTTONDOWN := 0xA1, HTCAPTION := 2

   if (hwnd != hTT)
      Return

   StartTime := A_TickCount
   MouseGetPos, _MouseX, _MouseY
   SetTimer, CheckCPULoad, Off

   While GetKeyState(&quot;Lbutton&quot;, &quot;P&quot;)
   {
      MouseGetPos, MouseX_, MouseY_
      WinMove, ahk_id %hTT%,, MouseX_ - _MouseX + xTT, MouseY_ - _MouseY + yTT
      Sleep, 10
   }

   if (A_TickCount - StartTime) &lt; 200
      Run Taskmgr
   else
   {
      xTT += (MouseX_ - _MouseX), yTT += (MouseY_ - _MouseY)
      DllCall(&quot;SendMessage&quot;, UInt, hwnd, UInt, 1042, UInt, 0, UInt         ; TTM_TRACKPOSITION
         , (xTT &amp; 0xFFFF)|(yTT &lt;&lt;16))
      IniWrite, % xTT, % IniName, Positions, xTT
      IniWrite, % yTT, % IniName, Positions, yTT
      PosCorrection()
   }
   SetTimer, CheckCPULoad, On
}

Settings(wParam, lParam, msg, hwnd)
{
   local Str
   if (hwnd != hTT || WinExist(&quot;Настройки CPULoad ahk_class AutoHotkeyGUI&quot;))
      Return
   DllCall(&quot;SendMessage&quot;, UInt, hTT, UInt, 1041, UInt, 0, UInt, &amp;TOOLINFO)   ; TTM_TRACKACTIVATE
   Gui, -Caption +Border +AlwaysOnTop +Owner +LastFound
   WinGet, hSett
   Gui, Color, FFFEE1
   Gui, Add, Text, gWinMove x0 y0 w209 h12 +0x5
   Gui, Add, Text, x7 yp+24, Сколько процессов показать?
   Loop 10
      Str .= A_Index &quot;|&quot;
   StringReplace, Str, Str, % HowManyProcShow &quot;|&quot;, % HowManyProcShow &quot;||&quot;
   Gui, Add, DDL, vHowManyProcShow gSettChange xp+160 yp-3 w35, % Str
   Gui, Add, Checkbox, vShowTitle gSettChange x8 yp+29, Показывать заголовок
   Gui, Add, Checkbox, VShowDate gSettChange xp yp+28, Показывать дату
   Gui, Add, GroupBox, x8 yp+28 w193 h60, Настройка размеров кнопки Пуск
   Gui, Add, Text, x105 yp+17 w1 hp-24 +0x8
   Gui, Add, Text, vLeft gButtonMove x9 yp-4 w96 h46 cAAAAAA BackgroundTrans Center, `nЛевая сторона
   Gui, Add, Text, vRight gButtonMove x106 yp wp-1 hp cAAAAAA BackgroundTrans Center, `nПравая сторона
   Gui, Add, Checkbox, vShowPercent gSettChange x8 y185, Знак `% на кнопке
   Gui, Add, Button, x150 y187 w53 h23 Default, OK

   GuiControl,, ShowTitle, % ShowTitle ? 1 : 0
   GuiControl,, ShowPercent, % ShowPercent ? 1 : 0
   GuiControl,, ShowDate, % ShowDate ? 1 : 0

   Gui, Show, x%xSett% y%ySett% w209 h218, Настройки CPULoad
   GuiControl, Focus, Static1
   Return

SettChange:
   Gui, Submit, NoHide
   IniWrite, % %A_GuiControl%, % IniName, Settings, % A_GuiControl
   Return

WinMove:
   PostMessage, WM_NCLBUTTONDOWN := 0xA1, HTCAPTION := 2
   Return

ButtonMove:
   WinWait, ahk_class Shell_TrayWnd
   SetTimer, CheckCPULoad, Off
   Gui, Font, c00AA00
   GuiControl, Font, % A_GuiControl
   MouseGetPos, xM
   ControlGetPos, xB,, wB,, Button1, ahk_class Shell_TrayWnd
   hCursor := DllCall(&quot;LoadCursor&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;), UInt, 0, Int, OCR_SIZEWE := 32644)
   DllCall(&quot;SetSystemCursor&quot;, Uint, hCursor, Int, OCR_NORMAL := 32512)

   While GetKeyState(&quot;LButton&quot;, &quot;P&quot;)
   {
      MouseGetPos, xM_
      Shift := (xM_ - xM)/4
      if A_GuiControl = Left
         ControlMove, Button1, xButt := xB + Shift,, wButt := wB - Shift
      Else
         ControlMove, Button1,,, wButt := wB + Shift
      Sleep, 10
   }
;   DllCall(&quot;SystemParametersInfo&quot; . (A_IsUnicode ? &quot;W&quot; : &quot;A&quot;)      ; на офф. форуме восстанавливают
;      , UInt, SPI_SETCURSORS := 0x57, UInt, 0, UInt, 0, UInt, 0)   ; курсор так
   DllCall(&quot;SetSystemCursor&quot;, UInt, hCursor, Int, OCR_NORMAL := 32512)   ; но вроде, можно и так

   Gui, Font, cAAAAAA
   GuiControl, Font, % A_GuiControl
   IniWrite, % xButt, % IniName, Positions, xButt
   IniWrite, % wButt, % IniName, Positions, wButt
   SetTimer, CheckCPULoad, On
   Return

GuiClose:
GuiEscape:
   Gui, Destroy
   Return

ButtonOK:
   WinGetPos, xSett, ySett,,, ahk_id %hSett%
   Gui, Destroy
   IniWrite, % xSett, % IniName, Positions, xSett
   IniWrite, % ySett, % IniName, Positions, ySett
   Return
}

PosCorrection()
{
   global
   WinGetPos, _xTT, _yTT, _wTT, _hTT, ahk_id %hTT%
   if (yTT != _yTT || xTT != _xTT)
   {
      yTT := (yTT - _yTT &gt; 300) ? A_ScreenHeight - _hTT - 5 : _yTT
      xTT := _xTT
      WinMove, ahk_id %hTT%,, xTT, yTT
      DllCall(&quot;SendMessage&quot;, UInt, hwnd, UInt, 1042, UInt, 0, UInt         ; TTM_TRACKPOSITION
         , (xTT &amp; 0xFFFF)|(yTT &lt;&lt;16))
      IniWrite, % xTT, % IniName, Positions, xTT
      IniWrite, % yTT, % IniName, Positions, yTT
   }
}</code></pre></div><p>Прошу свои отзывы о работе скрипта, предложения и сообщения о замеченных багах оставлять в <a href="http://forum.script-coding.com/viewtopic.php?id=5038">этой</a> теме.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 22 Oct 2010 13:13:19 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=40736#p40736</guid>
		</item>
		<item>
			<title><![CDATA[Re: AutoHotkey: Отображение загрузки процессора на кнопке Пуск]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=2413#p2413</link>
			<description><![CDATA[<p>Оказалось, что на компьютерах с двухъядерными процессорами на кнопку выводится отрицательное число. Причина, видимо, в том, что используемая в скрипте функция GetSystemTimes учитывает время простоя для каждого из ядер и потом суммирует результаты.<br />Чтобы сделать скрипт более универсальным, учитывающим количество процессоров/ядер, можно использовать переменную окружения NUMBER_OF_PROCESSORS.</p><p>И ещё одно замечание: как следует из описания упомянутой функции на MSDN, для её нормальной работы требуется по крайней мере Windows XP SP1.</p><div class="codebox"><pre><code>#Persistent
EnvGet, NumCPU, NUMBER_OF_PROCESSORS    ; Добавлено.
VarSetCapacity(IdleTicks, 8)
SetTimer, CheckCPULoad, 1000
return 

CheckCPULoad:
  ControlMove, Button1, -7,, 110,, ahk_class Shell_TrayWnd
  SetFormat, float, 02
  ControlSetText, Button1, % &quot; &quot; GetCPULoad() &quot; %&quot;, ahk_class Shell_TrayWnd 
return 

GetCPULoad() 
{ 
  Global
  SetBatchLines, -1 
  IdleTime0 = %IdleTime%  ; Save previous values 
  Tick0 = %Tick% 
  DllCall(&quot;kernel32.dll\GetSystemTimes&quot;, &quot;uint&quot;,&amp;IdleTicks, &quot;uint&quot;,0, &quot;uint&quot;,0) 
  IdleTime := *(&amp;IdleTicks) 
  Loop 7                  ; Ticks when Windows was idle 
    IdleTime += *( &amp;IdleTicks + A_Index ) &lt;&lt; ( 8 * A_Index ) 
  Tick := A_TickCount     ; Ticks all together 
  load := 100 - 0.01*(IdleTime - IdleTime0)/NumCPU/(Tick - Tick0)  ; Изменено.
  Return, load 
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Tue, 03 Apr 2007 06:51:57 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=2413#p2413</guid>
		</item>
		<item>
			<title><![CDATA[AutoHotkey: Отображение загрузки процессора на кнопке Пуск]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=1846#p1846</link>
			<description><![CDATA[<p>Скрипт взят с форума AutoHotkey из темы&nbsp; <a href="http://www.autohotkey.com/forum/topic13044.html">CPU usage</a>.</p><p>Я добавил в него только 2 команды. Одна - <strong>VarSetCapacity(IdleTicks, 8)</strong> - задаёт размер переменной IdleTicks. Как я понял, это требуется для новых версий AutoHotkey. Вторая - <strong>ControlMove, Button1, -7,, 110,, ahk_class Shell_TrayWnd</strong> - связана с тем, что кнопка &quot;Пуск&quot; оказалась коротковата, чтобы аккуратно вместить весь требуемый текст. Знак процента частично вылезал за границу видимости. Я расширил кнопку до 110 пикселов и сдвинул влево на 7, чтобы она не так наезжала на панель быстрого запуска.<br /></p><div class="codebox"><pre><code>#Persistent
VarSetCapacity(IdleTicks, 8)
SetTimer, CheckCPULoad, 1000
return 

CheckCPULoad:
  ControlMove, Button1, -7,, 110,, ahk_class Shell_TrayWnd
  SetFormat, float, 02
  ControlSetText, Button1, % &quot; &quot; GetCPULoad() &quot; %&quot;, ahk_class Shell_TrayWnd 
return 

GetCPULoad() 
{ 
  Global
  SetBatchLines, -1 
  IdleTime0 = %IdleTime%  ; Save previous values 
  Tick0 = %Tick% 
  DllCall(&quot;kernel32.dll\GetSystemTimes&quot;, &quot;uint&quot;,&amp;IdleTicks, &quot;uint&quot;,0, &quot;uint&quot;,0) 
  IdleTime := *(&amp;IdleTicks) 
  Loop 7                  ; Ticks when Windows was idle 
    IdleTime += *( &amp;IdleTicks + A_Index ) &lt;&lt; ( 8 * A_Index ) 
  Tick := A_TickCount     ; Ticks all together 
  load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0) 
  Return, load 
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (YMP)]]></author>
			<pubDate>Sat, 03 Feb 2007 14:25:12 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=1846#p1846</guid>
		</item>
	</channel>
</rss>
