![]() |
|
|
|
#1
|
|||
|
|||
|
Hi,
I have tried some trayicon components to make this , but I'm giving up ![]() the best that I used is Cooltrayicon (i use with d7 and d2007). I need to to put a progress bar with text. progress bar (could have two display, top , bottom, etc) and text must have 4 digits (with good visualization) please, take a look (picture below)
|
|
#2
|
|||
|
|||
|
Well, don't have much experience with trayicons, but isn't there something like a Canvas available?
|
|
#3
|
|||
|
|||
|
What are you using for the Icon holder?
Check the Help for a TImageList, then AddIcon and AddMasked Not an easy process but fairly straightforward. Assign the appropriate icon as the SystemTray app. The Mask will handle the Transparency for you. The progress bar might best be done with several icons each having the bar a little wider and you cycle through and Assign them in sequence. Harry Last edited by HarryCL2; 08-20-2010 at 11:17 PM. |
|
#4
|
|||
|
|||
|
Quote:
Nope, it is just an icon that is displayed in the SystemTray. The idea is to change icons as an Animated GIF does to give the appearance of movement. Similar principle. Harry |
|
#5
|
|||
|
|||
|
Hi Norrit,
Yes, I think that the canvas property is the start, and I'm not experience to work with canvas, so I created this thread (but I'm studing canvas at now... because I need to solve this...) and about HarryCL2 suggestion.This is not a solution to me , a faked a progressbar in the past and it's really bad and didn't solved my second big problem that is display 4 visible letters-digits in trayicon.. so I'm waiting another solution. |
|
#6
|
|||
|
|||
|
Quote:
Heavily Edited: I figured this out. So to stick with VCL stuff, I've figured out that you have to draw it as a TBitmap and then copy it through something that will support writing TIcon. That something is CreateIconInDirect(), since the VCL doesn't seem to support it well. Then update the systray icon with your TIcon. Code:
var
IconSizeX : integer;
IconSizeY : integer;
AndMask : TBitmap;
XOrMask : TBitmap;
IconInfo : TIconInfo;
Icon : TIcon;
begin
ProgressBar1.Position := SpinEdit1.Value;
IconSizeX := GetSystemMetrics(SM_CXICON);
IconSizeY := GetSystemMetrics(SM_CYICON);
{Create the "And" mask}
AndMask := TBitmap.Create;
AndMask.Monochrome := true;
AndMask.Width := IconSizeX;
AndMask.Height := IconSizeY;
AndMask.Canvas.Font.Height := 32;
AndMask.Canvas.Font.Color := clBlack;
AndMask.Canvas.TextOut(0, 0, intToStr(SpinEdit1.Value));
{Create the "XOr" mask}
XOrMask := TBitmap.Create;
XOrMask.Width := IconSizeX;
XOrMask.Height := IconSizeY;
XOrMask.Canvas.Brush.Color := clBlack;
XOrMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
XorMask.Canvas.Font.Height := 32;
XorMask.Canvas.Font.Color := clRed;
XorMask.Canvas.TextOut(0, 0, intToStr(SpinEdit1.Value));
{Create a icon}
Icon := TIcon.Create;
IconInfo.fIcon := true;
IconInfo.xHotspot := 0;
IconInfo.yHotspot := 0;
IconInfo.hbmMask := AndMask.Handle;
IconInfo.hbmColor := XOrMask.Handle;
Icon.Handle := CreateIconIndirect(IconInfo);
{Destroy the temporary bitmaps}
AndMask.Free;
XOrMask.Free;
{Assign the application icon}
Application.Icon := Icon;
CounterTray.Icon := Icon;
{Force a repaint}
InvalidateRect(Application.Handle, nil, true);
{Free the icon}
Icon.Free;
Application.ProcessMessages;
CounterTray.AppTitle := InttoStr(SpinEdit1.Value);
CounterTray.ModifyTray;
XorMask has what you want to show up in the color you want on a black background. The result is an icon that is transparent in the parts that are white on the first and black on the second. I'll have to play with this more...in a new post. This part is still valid Of course, being an icon you are limited to 32x32, and the only solution to get any kind of movement or progress bar is to change the icon repetitively (eg HarryCL2's solution). So it seems like you might need to revise your expectations on what can be shown in the TIcon. Last edited by Glenn1234; 08-21-2010 at 04:24 PM. Reason: Went ahead and figured out the problem with my program doing this. |
|
#7
|
|||
|
|||
|
This seems to work for the purposes I want it to work in creating transparent icons out of bitmaps.
Code:
procedure BitMapToIcon(myBitmap: TBitmap; var MyIcon: TIcon; MaskColor: TColor);
var
IconSizeX : integer;
IconSizeY : integer;
AndMask : TBitmap;
oldcol : integer;
XOrMask : TBitmap;
IconInfo : TIconInfo;
begin
IconSizeX := myBitmap.Width;
IconSizeY := myBitmap.Height;
{Create the "And" mask}
AndMask := TBitmap.Create;
AndMask.Width := IconSizeX;
AndMask.Height := IconSizeY;
oldcol := SetBkColor(myBitmap.Canvas.Handle, ColorToRGB(MaskColor));
AndMask.Monochrome := true;
AndMask.Canvas.CopyMode := cmSrcCopy;
AndMask.Canvas.Draw(0, 0, myBitmap);
SetBkColor(myBitmap.Canvas.Handle, oldcol);
// draw the first two bitmap samples.
Form1.Canvas.Brush.Color := clBtnFace;
Form1.Canvas.FillRect(Rect(0, 0, IconSizeX * 6, IconSizeY));
Form1.Canvas.Draw(0, 0, myBitmap);
Form1.Canvas.Draw(IconSizeX * 2, 0, AndMask);
{Create the "XOr" mask}
XOrMask := TBitmap.Create;
XOrMask.Width := IconSizeX;
XOrMask.Height := IconSizeY;
XOrMask.Canvas.Brush.Color := clBlack;
XOrMask.Canvas.FillRect(Rect(0, 0, IconSizeX, IconSizeY));
// oldcol := SetBkColor(myBitmap.Canvas.Handle, ColorToRGB(MaskColor));
{ line below is just a kludge to get the color right, comment this and
uncomment the other two lines to get the color you specify above.
The icon won't be transparent if you don't get the color precisely
right at this point. Actually you can go out and find the color at an
edge pixel before you call this, and likely get this right }
MyBitmap.Transparent := true;
XorMask.Canvas.Draw(0, 0, myBitmap);
MyBitmap.Transparent := false;
// SetBkColor(myBitmap.Canvas.Handle, oldcol);
Form1.Canvas.Draw(IconSizeX * 6, 0, XorMask);
{Create a icon}
IconInfo.fIcon := true;
IconInfo.xHotspot := 0;
IconInfo.yHotspot := 0;
IconInfo.hbmMask := andMask.Handle;
IconInfo.hbmColor := xorMask.Handle;
myIcon.Handle := CreateIconIndirect(IconInfo);
{Destroy the temporary bitmaps}
AndMask.Free;
XOrMask.Free;
end;
Last edited by Glenn1234; 08-21-2010 at 08:09 PM. |
![]() |
| Tags |
| trayicon cooltrayicon |
| Thread Tools | |
| Display Modes | |
|
|