AutoHotkey Community

It is currently May 25th, 2012, 10:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: November 27th, 2007, 5:09 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
tic wrote:
write me the machine code for hex to binary
Give me a day, or so.
tic wrote:
what exactly do you want me to make a new function to do?
This was Maj’s idea, but, if you work with 16x16 icons, the input could be an array of 14 values (corresponding the x positions), each between 0 and 13 (the y value).

You could allow specifying the color under the curve, and another color above, a third: the color of the curve. One of them could be transparent…


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 6:36 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
Simple curves may already be created with the TrayBars function. try this code. it will give a moving wave:

Code:
Curve := "50|50|60|60|70|70|75|75|70|70|60|60|50|50|40|40|30|30|20|20|15|15|20|20|30|30|40|40|50|50|60|60"

Loop, 200
{
   Sleep, 20

   ErrorLevel := TrayBars(Curve, "000000", "000000", "50")
   StringTrimRight, Curve, Curve, 3
   Curve := SubStr(Curve, 82, 3) . Curve
}
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 9:44 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Quote:
Perhaps the hIcon would be faster, with Shell_NotifyIcon, if anyone wants to write some tester code for me to add:

Yup, one of the good ways to improve it is to use Shell_Notify.
I will see what I can do about this.


Quote:
what exactly do you want me to make a new function to do?

I like curve in tray alot, it has very useful applications for many monitoring purposes. Input can be either what Laszlo suggested or what I did - I don't see why I do have to repeat 13 or so values all the time when 11 are the same. Acctually, since curve is the same all the time - its only moved to the left (translation) - creating specialized code will be far more efficent as youcan do the same thing with picture (move it left and draw only last value). Acordingly, we can have only 1 value as input, and it should be value of apcise = 32). You will have to remember previous image in static variable and just process it with new value on next call.

About interface, it would be kewl to have one function to do them all. You can for instance choose to use single parameter with string definition of curve/bar/number.

With ability to add new tray icons this can be very useful. For instance, I can create one tray icon with 3 bars for temperatures of my 3 hard discks, 1 tray number for free RAM and 1 tray icon for CPU curve. This is for instance done by Everest monitoring program (highly recommended). It can acctually create arbitrary number of senzors in the tray and u can customize each of them the same way as with your function. If we can utilize Shell_Notify, we are not that far from making that in AHK.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 27th, 2007, 8:16 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
I agree maj that it would be neice to plot points and not have to add each new point if not wanted and will add that, but I dont think that they should all be 1 function. They should all be included in 1 file, but say I want use the bar part but not the number part, then that is an awful lot of code to include and not use. I believe they should all be included in an ahk file, and then a function can be deleted if necessary.

I also think that the part that sets the tray icon and the filedelete should be removed. I have been playing more, and have been using it with adding pictures at 256*256 and guicontrolling them, and it works very well. I will release all my new additions later and I think you'll see that its nice just to create a compatible ico, and then let the user decide what they wish to do with it.

Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 12:41 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Very nice.

I will see one of these days to check how much needs to be done for controling tray icons.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 12:59 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
As per one of your requests Maj I have added the ability to either shift all the colums along left and add the new parameter to the right, or just add a new column on the left hand side:

http://www.autohotkey.net/~tic/tic-TrayBars-1.05.zip

I will update the 1st post when I have finished with these current updates.

I have removed the trayicon command and filedelete from the end of the function, as I feel the user should be given the option with what they want to do with the created icon. the example shows of its use.

I have added the ability for the numbers part to specify either + or < as the 1st character. Specifying + will add a new bar or bars to the end of whatever the last call to the function created, and specifying < will add as many bars as specified, and delete that same number of bars from the left hand side. The new number of colours can be specified for added bars, or optionally only 1 to make all new added bars the same colour (also occurs if fewer colours are specified than numbers). I will soon also add the ability to use > in order to tell them to shift right and - to add new bars to the left.

Currently if you try to immediately set < or + without having any previous values, it will return with errorlevel -4.

Examples of new usage:
Code:
; First set a starting value
ErrorLevel := TrayBars("25|50|75", "ff0000|00ff00|0000ff")

; Next add a new bar to the end
ErrorLevel := TrayBars("+100", "400040")

; Next shift all bars by 2 left and add 2 more green bars
ErrorLevel := TrayBars("<75|50", "00ff00")

; Next shift all bars 2 left and add a red and blue bar
ErrorLevel := TrayBars("<25|100", "ff0000|0000ff")


Let me know of bugs and tell me your thoughts and remember that you cant leave parameters blank in the example gui as it will actually send a blank variable! :oops: ...Enjoy

Edit: theres a bug if you specify < and then fewer numbers than colours. ill fix it


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 5:27 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You might not need it, after all, but you can find the promised Hex2Bin machine code function here.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 11:18 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
The script takes about half as long to generate the icon when its working with a RAM disk (vs the hard drive.)

I'm sure it would be much faster if you rendered the bars into an in-memory bitmap using GDI, then created the icon from that. GDI's not the simplest beast to figure out, though...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 11:38 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I am currently working on Shell_IconNotify encapsulation. I succeded to add arbitrary number of tray icons in the tray menu, but still working on interface and APIs.

I will make sure that you can set icon using path and using HWND. Second option, will make this function able to set icon with temporary files, directly from memory.

So, I suggest you to continue optmisiation in other directions, if thats still needed.

-----------
I played abit with latest version and discovered some thngs.
I was adding with +, like +15 , 3 times, then +50 etc... I noticed that after some time it stops working (after 32 updates).

This + thing you did, is realy nice, we have curves now. Just a little bit polishing and this can go into production stage 8)

BTW, I am suggesting you to update your example with another section, the one that will monitor CPU. You can easily find Laszlos function on the forum.

_________________
Image


Last edited by majkinetor on November 28th, 2007, 11:54 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 11:46 am 
Offline

Joined: July 20th, 2007, 10:23 am
Posts: 257
Location: Paris, France
majkinetor wrote:
I am currently working on Shell_IconNotify encapsulation. I succeded to add arbitrary number of tray icons in the tray menu, but still working on interface and APIs.
Great, I was thinking about doing it; but you save me time :) And you'll surely reach the goal sooner that I could.
I'll wait for it with a lot of interest.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 2:15 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Heheheh. Blazingly fast dynamic icon generation, anyone?
Code:
#NoEnv

backclr = 0x7F000000
marginx = 1
marginy = 1
bars = 3
barpadding = 1
pct1 = 25
pct2 = 50
pct3 = 75
clr1 = 0x0000FF
clr2 = 0x00FF00
clr3 = 0xFF0000

width = 16
height = 16

display_gui = 1
if display_gui
{
    Gui, Add, Picture, hwndpic, shell32.dll
    Gui, Show, % "W" (width<100 ? 100 : width+20) "H" height+10
}

Loop {  ; Test loop and random numbers to demonstrate speed!!!.
Loop, 3
    Random, pct%A_Index%, 0, 100

if !(hdcScreen := DllCall("GetDC","uint",0))
    return

VarSetCapacity(buf,40,0), NumPut(40,buf), NumPut(1,buf,12,"ushort")
NumPut(width,buf,4), NumPut(height,buf,8), NumPut(32,buf,14,"ushort")

; Note that a compatible bitmap's format depends on the current display settings.
; Changing the display depth after creating the icon may cause colour loss.
;if hbm := DllCall("CreateCompatibleBitmap","uint",hdcScreen,"int",width,"int",height)

if hbm := DllCall("CreateDIBSection","uint",hdcScreen,"uint",&buf,"uint",0
                            ,"uint*",pBits,"uint",0,"uint",0)
{
    if hdc := DllCall("CreateCompatibleDC","uint",hdcScreen)
    {
        ; Select the bitmap into a device context to draw on it.
        ; Note that the previous bitmap should always be reselected afterwards.
        if hbm_old := DllCall("SelectObject","uint",hdc,"uint",hbm)
        {
            ; Calculate the (maximum) bar size.
            barwidth := floor((width-marginx*2-(bars-1)*barpadding)/bars)
            barheight := height-marginy*2
   
            ; Draw the bars!
            x := marginx
            Loop, %bars%
            {
                RECT(rc
                    , x
                    , marginy+barheight*(pct%A_Index%/100)
                    , x+barwidth
                    , height-marginy)
                hbr := DllCall("CreateSolidBrush","uint",clr%A_Index%)
                DllCall("FillRect","uint",hdc,"uint",&rc,"uint",hbr)
                DllCall("DeleteObject","uint",hbr), hbr:=0
                x += barwidth+barpadding
            }
           
            DllCall("SelectObject","uint",hdc,"uint",hbm_old)
        }

        ; Since GDI doesn't support alpha-blending, we must manually set the
        ; pixels to our background colour. We must also set the alpha component
        ; of each bar pixel to 255, otherwise bars become mostly invisible.
        offset = 0
        Loop, %height% {
            Loop, %width% {
                px := NumGet(pBits+offset)
                NumPut(px ? 255<<24|px : backclr, pBits+offset)
                offset += 4
            }
        }

        VarSetCapacity(mask,64,0)
        hbm_mask := DllCall("CreateBitmap","int",width,"int",height,"uint",1,"uint",1,"uint",&mask)

        DllCall("DeleteDC","uint",hdc)
    }
}
DllCall("ReleaseDC","uint",0,"uint",hdcScreen)

hicon_old := hicon

VarSetCapacity(ii,20,0), NumPut(1,ii,0), NumPut(hbm,ii,16), NumPut(hbm_mask,ii,12)
hicon := DllCall("CreateIconIndirect","uint",&ii)
; "The system copies the bitmaps in the ICONINFO structure before creating the icon or cursor."
DllCall("DeleteObject","uint",hbm)
DllCall("DeleteObject","uint",hbm_mask)

; Prepare the NOTIFYICONDATA struct.
VarSetCapacity(nid,444,0), NumPut(444,nid)
; Set nid.hWnd to the script's main window.
DetectHiddenWindows, On
Process, Exist
NumPut(WinExist("ahk_class AutoHotkey ahk_pid " ErrorLevel), nid,4)
DetectHiddenWindows, Off
; Set nid.uID to AHK_NOTIFYICON. hWnd and uID identify the tray icon.
NumPut(1028,nid,8)
; Set nid.hIcon=hicon and nid.uFlags=NIF_ICON.
NumPut(hicon,nid,20), NumPut(0x2,nid,12)
; Set the new icon. (NIM_MODIFY=0x1)
DllCall("shell32\Shell_NotifyIcon","uint",0x1,"uint",&nid)

if display_gui
    SendMessage, 0x170, hicon,,, ahk_id %pic%

if hicon_old
    DllCall("DestroyIcon","uint",hicon)

} ; end test loop

return


GuiClose:
ExitApp


; helper function for readability
RECT(ByRef rc, left, top, right, bottom) {
    VarSetCapacity(rc,16), NumPut(bottom,NumPut(right,NumPut(top,NumPut(left,rc,0))))
}

It needs a bit of cleaning up, but hopefully you can make sense of it. It isn't really meant to be a reusable function. You can probably tell that I hacked the loop and DestroyIcon call in at the last moment...

Note that it might not work correctly on older versions of Windows (which don't support 32-bit tray icons.) :roll: Supposedly the icon should be 4-bit on Windows 9x/NT4, and no higher than the current display depth on Win2k.

If you'd like to use any or all of it in your script, feel free to do so.
majkinetor wrote:
I am currently working on Shell_IconNotify encapsulation. I succeded to add arbitrary number of tray icons in the tray menu, but still working on interface and APIs.
Sounds good. Modifying the existing icon is easy, but you see the default green icon for a (very!) brief moment as the script starts up. :?


Last edited by Lexikos on November 29th, 2007, 9:47 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 4:11 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thx for your code lex (Lutor?).

Quote:
but you see the default green icon for a (very!) brief moment as the script starts up.

Use #NoTrayIcon as the first line in your script.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 5:47 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
Yes nice work lex. How have you created a header for the icon? and couldnt gdi+ be used for the transparency part?

Ill wait until I can try out the machine code to see what speed that gives before using some of your code Lex. (I probably have quite a few questions about the code :)).Thanks again


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 5:52 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
I just read your edit. I think I've fixed all the bugs with + and < but I may wait to release it when I can get Laszlos machine code integrated.

Please could you help suggest prefixs for the different modes.

I need one to shift everything right, one to shift everything left, one to add a bar to the right, one to add a bar to the left, one to delete a bar from the right and one to delete a bar from the left.

They can be 2 characters if necessary, but they must all be all the same length to make things easier

+> add right?
+< add left?
<< shift left?
>> shift right?
-< remove left?
-> remove right?

thats what i thought it could be, but Id like opinions. When I have done this, the curve part shouldnt take long at all, as itll just be the same code but a bit shorter.

Oh and I will add several new examples. thers one very cool 1 Ive thought of that will remain a secret, but I think you'll find it funny :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2007, 8:53 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
Initial tests with machine code appear good. Lexikos' gdi code can perform 100 loops with no sleep in averaging 344ms on my comp and my machine code example now does it in 981ms average (down from over 9000 lol), and the machine code is creating 32pixel icos not 16 (so they can be added as pictures as well). When reduced to 16 as a test, the machine code could do it in averaging 620ms, and I havent tightened the code yet and there are many extra things added that take time. I will release it when I have fixed some bugs, and created some examples. I would also really like to know which signs people think would be good as prefixs! :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 53 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: tidbit and 5 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