Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > VCL

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 08-18-2010, 07:51 PM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,573
Exclamation help with trayicon (progressbar + text)

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)

Reply With Quote
  #2  
Old 08-20-2010, 07:40 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 6,700
Default

Well, don't have much experience with trayicons, but isn't there something like a Canvas available?
Reply With Quote
  #3  
Old 08-20-2010, 11:11 PM
HarryCL2 HarryCL2 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 163
Default

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.
Reply With Quote
  #4  
Old 08-20-2010, 11:16 PM
HarryCL2 HarryCL2 is offline
Senior Member
 
Join Date: Jun 2010
Posts: 163
Default

Quote:
Originally Posted by Norrit View Post
Well, don't have much experience with trayicons, but isn't there something like a Canvas available?
Hi Norrit,

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
Reply With Quote
  #5  
Old 08-21-2010, 12:41 AM
BaraoZemo BaraoZemo is offline
Senior Member
 
Join Date: Nov 2001
Posts: 3,573
Talking

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.

Quote:
Originally Posted by Norrit View Post
Well, don't have much experience with trayicons, but isn't there something like a Canvas available?
Reply With Quote
  #6  
Old 08-21-2010, 03:04 PM
Glenn1234 Glenn1234 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 112
Default

Quote:
Originally Posted by BaraoZemo View Post
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.
Part of the problem relating to VCL is indeed that a TCanvas isn't available for a TIcon. In other words, TIcon doesn't support it, if you stick with VCL stuff.

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;
AndMask has what you want to show up in black on a white background.
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.
Reply With Quote
  #7  
Old 08-21-2010, 08:04 PM
Glenn1234 Glenn1234 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 112
Default

Quote:
Originally Posted by Glenn1234 View Post
I'll have to play with this more...in a new post.
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;
Once you get the TIcon from the bitmap, all you need to do is use the SaveToFile method to get it on disk.

Last edited by Glenn1234; 08-21-2010 at 08:09 PM.
Reply With Quote
Reply

Tags
trayicon cooltrayicon

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.