AutoHotkey Community

It is currently May 27th, 2012, 8:48 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Scrolling tray icon
PostPosted: July 13th, 2006, 10:15 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
This is a proof of concept, only. It works with 256 color 32x32 pixel bmp files, as tray icons, although it is easy to modify it for other sizes and bit-map formats, like .ico files.

The actual bitmap, one byte of color information for each pixel, is at the end of the file. We keep the beginning of the image file, read the first 31 rows of the image and the last row, and write into the same file swapped. Setting this as the new tray icon has the effect of the picture scrolled up cyclically by one pixel. Scrolling down is similar.

The hotkey Win-1 scrolls up, Win-2 scrolls down and Win-0 stops the icon. You can use your favorite one, or use the 3rd script to decode the Ascii85 encoded example.
Code:
file0= %A_ScriptDir%\l0.bmp   ; <-- your bmp file
file = %A_ScriptDir%\l.bmp    ; working copy
GoTo #0

#1::
   SetTimer ScrollUp,  50
   SetTimer ScrollDown,Off
Return

#2::
   SetTimer ScrollUp,  Off
   SetTimer ScrollDown,50
Return

#0::
   SetTimer ScrollUp,  Off
   SetTimer ScrollDown,Off
   FileCopy %file0%, %file%, 1
   Menu Tray, Icon, %file%
Return

ScrollUp:
   Menu Tray, Icon, %file%
   BinRead( file, D1, 992,-1024)
   BinRead( file, D2,  32,  -32)
   BinWrite(file, D2,  32,-1024)
   BinWrite(file, D1, 992, -992)
Return

ScrollDown:
   Menu Tray, Icon, %file%
   BinRead( file, D1,  32,-1024)
   BinRead( file, D2, 992, -992)
   BinWrite(file, D2, 992,-1024)
   BinWrite(file, D1,  32,  -32)
Return

BinWrite(file, ByRef data, n=0, offset=0) {  ; n = #bytes/all; neg offset from end, "A" = Append
   h := DllCall("CreateFile",Str,file, UInt,0x40000000, UInt,0, UInt,0, UInt,4, UInt,0, UInt,0)
   m := 2*(offset+0 < 0)                  ; offset >= 0 : m = 0; offset < 0, non-numeric: m = 2
   offset += 0                            ; non-numeric -> 0
   DllCall("SetFilePointerEx",UInt,h, Int64,offset, UIntP,p, Int,m)
   m := VarSetCapacity(data)
   If n not between 1 and %m%
      n = %m%
   DllCall("WriteFile",UInt,h, Str,data, UInt,n, UIntP,U, UInt,0)
   DllCall("CloseHandle", UInt,h)
}

BinRead(file, ByRef data, n=0, offset=0)  {  ; n = #bytes/all; neg offset from end
   h := DllCall("CreateFile",Str,file, UInt,0x80000000, UInt,3, UInt,0, UInt,3, UInt,0, UInt,0)
   m := 2*(offset < 0)                       ; offset >= 0 : m = 0; offset < 0: m = 2
   DllCall("SetFilePointerEx",UInt,h, Int64,offset, UIntP,U, Int,m)
   m := DllCall("GetFileSize",UInt,h, Int64P,r)
   If n not between 1 and %m%
      n = %m%
   VarSetCapacity(data, n)
   DllCall("ReadFile",UInt,h, Str,data, UInt,n, UIntP,r, UInt,0)
   DllCall("CloseHandle", UInt,h)
   Return r
}

You can encode your favorite bmp file (for copying from the MsgBox to the script) with the following script:
Code:
nD := BinRead(file, D)   ; include file and BinRead from above
Ascii85Encode(C, D, nD)

StringReplace C, C, ``, ````, All
StringReplace C, C, `%, ```%, All
StringReplace C, C, `), ```), All
Loop % (StrLen(C)+79)//80
{
   StringMid x, C, A_Index*80-79, 80
   B = %B%%x%`n
}
MsgBox %B%

Ascii85Encode(ByRef code, ByRef data, n=0) {
   If n not between 1 and % VarSetCapacity(data)
      n := StrLen(data)          ; If no \0 in data, can omit n
   x = 0
   code = <~
   Loop %n% {
      x += *(&data+A_Index-1) << (24-8*((A_Index-1)&3))
      If !(A_Index & 3) {        ; Mod(i,4) = 0
         IfEqual x,0, SetEnv code,%code%z
         Else Loop 5
            code := code  Chr(33+Mod(x//85**(5-A_Index),85))
         x = 0
      }
   }
   If (n & 3)                    ; Mod(n,4) > 0
      Loop % (n&3)+1
         code := code  Chr(33+Mod(x//85**(5-A_Index),85))
   code = %code%~>
}

Pressing Ctrl-C when the message box is active, copies the content to the clipboard, which you can paste to the script in an editor. This is how the encoded file is used (as Veovis suggested).
Code:
C =
(
<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,&5"U,&5!!!0+"U,&5
"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0+"U,&5"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0+"U,
&5"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0+"U,&5"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0+"
U,&5"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0+"U,&5"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0
+"U,&5"U,&5"U,&5"U,`)7"pP&-"U,&5"U,&5!!!0+"U,&5"U,&5"U,&5"U,`)7"pP&1"U,&5"U,&5!!
!0+"U,&5"U,&5"U,&5"U,`)7"pP57"U,&5"U,&5!!!0+"U,&5"U,&5"U,&5"U+u4"p5#4"U,&5"U,&5!
!!0+"U,&5"U,&5"U,&5"U,&5"U,&5"U,&5"U,&5!<E?-"U,&5"U,&5"U,&5"U,&5"U,&5"U,&5"U,&5!<E~>
)
Ascii85Decode(B,C,nB)
BinWrite(file0, B, nB)   ; use file0 and BinWrite from the 1st script

Ascii85Decode(ByRef data, code, ByRef len) {
   StringReplace, code, code, <~
   StringReplace, code, code, ~>
   StringReplace, code, code, `n,, All
   StringReplace, code, code, `r,, All
   StringReplace, code, code, %A_Space%,,All

   StringCaseSense On         ; needed for z -> !!!!!
   StringReplace, code, code, z, !!!!!, All

   m := Mod(StrLen(code),5) - (Mod(StrLen(code),5)>0) ; 12345 -> ?1230
   len := (StrLen(code)//5)*4 + m
   VarSetCapacity(data,len,0)
   p := &data
   x = 0
   Loop Parse, code
      If Mod(A_Index,5) = 0 {
         x := x*85 + Asc(A_LoopField)-33
         Loop 4 {
            DllCall("RtlFillMemory",UInt,p, UInt,1, UChar,x>>(32-8*A_Index))
            p++
         }
         x = 0
      }
      Else
         x := x*85 + Asc(A_LoopField)-33
   x := (x+1) * 85**(4-m) ; omitted code chars -> 85+33, carry stops at trailing 0's of x
   Loop %m%  {
      DllCall("RtlFillMemory",UInt,p, UInt,1, UChar,x>>(32-8*A_Index))
      p++
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2006, 11:04 pm 
C8)8)LASZL:wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2006, 12:19 am 
Offline
User avatar

Joined: December 20th, 2004, 12:19 pm
Posts: 798
Location: LooseChange911.com Ask Questions, Demand Answers █ The WTC bldgs █ shouldn't have fallen █ that fast
Code:
[size=18][color=blue][b]C[/b][/size]8)8)[size=18]
[color=red][b]L[/b][/size][b][size=18]ASZL[/size][/b]:wink:

...can be written...

Code:
[b][size=18][color=blue]C8)8)[color=red]LASZL[/size][/b]:wink:

...if the whole thing is bold 18, then you don't need to keep opening & closing em...

overkill ---> C8)8)LASZL:wink: = C8)8)LASZL:wink: <--- compact

_________________
AutoHotkey-Hotstring.ahk - Helping the world spell "AutoHotkey" correctly! (btw, it's a lowercase k!)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2006, 7:32 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
:D :D :D

Thank you very much, Sir.

:D :D :D

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2006, 9:16 am 
Quote:
...if the whole thing is bold 18, then you don't need to keep opening & closing em...
During its design I changed the variants multiple times. Therefore that code is less jsloverished as it should have been, confirmed. :lol:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2006, 9:24 am 
Offline

Joined: July 11th, 2006, 3:30 pm
Posts: 11
You have problems... :shock:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2006, 3:27 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
WarrenFaith wrote:
You have problems... :shock:
Never mind... JSlover is also a venerable member of the "mine is shorter than yours" camp.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: tomoe_uehara, Xx7 and 8 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group