<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LMD Innovative Blog &#187; taskbar</title>
	<atom:link href="http://blog.lmd.de/tag/taskbar/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.lmd.de</link>
	<description>News, Tutorials</description>
	<lastBuildDate>Mon, 16 Jan 2012 18:38:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>New Windows 7 API support for Taskbar &#8211; Part 1</title>
		<link>http://blog.lmd.de/2009/12/new-windows-7-api-for-taskbar-part-1/</link>
		<comments>http://blog.lmd.de/2009/12/new-windows-7-api-for-taskbar-part-1/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 17:16:53 +0000</pubDate>
		<dc:creator>Alexander</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[taskbar]]></category>
		<category><![CDATA[windows 7]]></category>

		<guid isPermaLink="false">http://blog.lmd.de/?p=87</guid>
		<description><![CDATA[The latest OS release from Microsoft introduces to us a lot of new features that (can) make life of developers easier and improve usability of own applications. This post is about small part of new Windows API that allows to customize taskbar button of your application. Pictures and source code are telling more than 1000 [...]]]></description>
			<content:encoded><![CDATA[<p>The latest OS release from Microsoft introduces to us a lot of new features that (can) make life of developers easier and improve usability of own applications. This post is about small part of new Windows API that allows to customize taskbar button of your application.<br />
<span id="more-87"></span><br />
Pictures and source code are telling more than 1000 words, hence we start immediately with practical examples:<br />
Here is picture of what we will get after compiling <a href="http://blog.lmd.de/uN">sample project</a> &#8211; we will create project that has buttons on it&#8217;s taskbar thumbnail, that allow to control progressbar and another part is reflect progressbar state on application taskbar button:</p>
<p><div id="attachment_90" class="wp-caption alignnone" style="width: 546px"><a rel="lightbox[screenshot1.png]" href="http://blog.lmd.de/La" title="windows7-part1-1"><img class="size-full wp-image-90 cboxModal" title="windows7-part1-1" src="http://blog.lmd.de/La" alt="Sample project screenshot. Windows 7" width="536" height="249" /></a><p class="wp-caption-text">Sample project screenshot. Windows 7</p></div><strong>NB #1</strong> To compile code from this post you should have updated units from Delphi 2010 or unit from LMD Tools 2010 &#8211; LMDWindows7Utils.pas</p>
<p><strong>NB #2</strong> All manipulatations with taskbar buttons must be done after button will be created, to catch this moment we should subscribe to WM_TASKBARBUTTONCREATED event, that must firstly registered by RegisterWindowMessage(&#8216;TaskbarButtonCreated&#8217;); &#8211; I reccomend you to add this registration to initialization section of unit with your form:</p>
<pre class="brush:delphi">//.....//
initialization
  WM_TASKBARBUTTONCREATED := RegisterWindowMessage('TaskbarButtonCreated');
end.</pre>
<p><strong>NB #3</strong> You must be sure that Application.MainFormOnTaskbar is True; or drop on form TLMDFormVista for delphi 6-2005 versions</p>
<p>Now, when we registered message we can handle it in WndProc method to setup taskbar button:</p>
<pre class="brush:delphi">type
  TForm8 = class(TForm)
    Timer1: TTimer;
    ImageList1: TImageList;
    ProgressBar1: TProgressBar;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FTick: Int64;
    FButtons: array[0..2] of TThumbButton;
    FNormalIcon: Cardinal;
    FPauseIcon: Cardinal;
    FTaskBar: ITaskbarList3;
  protected
    procedure WndProc(var Message: TMessage); override;
    { Private declarations }
  public
    { Public declarations }
  end;
//...//
procedure TForm8.WndProc(var Message: TMessage);
begin
  inherited;
  // Is tasbar button created?
  if Message.Msg = WM_TASKBARBUTTONCREATED then
  begin
    // Create instance of ITaskbarList3
    CoCreateInstance(CLSID_TaskbarList, nil, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, FTaskBar);
    // Init
    FTaskBar.HrInit;
    // This method set progress state of tasbar button.
    // Button has next states: error, paused, normal and indetermintate
    FTaskBar.SetProgressState(Handle, TBPF_NORMAL);
    FNormalIcon := LoadIcon(0, IDI_ASTERISK);
    FPauseIcon := LoadIcon(0, IDI_WARNING);
    // Set overlay icon for taskbar button - "!" - asterix
    FTaskBar.SetOverlayIcon(Handle, FNormalIcon, 'In progress');

    // Buttons setup
    // Set imagelist handle that contains glyphs for our buttons
    FTaskBar.ThumbBarSetImageList(Handle, ImageList1.Handle);
    // This identificator will be used to determinate what button pressed
    FButtons[0].iId := 40001;
    FButtons[0].dwFlags := THBF_ENABLED;
    FButtons[0].iBitmap := 0;
    StringToWideChar('Reset', FButtons[0].szTip, 260);
    FButtons[0].dwMask := THB_BITMAP or THB_FLAGS or THB_TOOLTIP;

    FButtons[1].iId := 40002;
    FButtons[1].dwFlags := THBF_DISABLED;
    FButtons[1].iBitmap := 1;
    StringToWideChar('Play', FButtons[1].szTip, 260);
    FButtons[1].dwMask := THB_BITMAP or THB_FLAGS or THB_TOOLTIP;

    FButtons[2].iId := 40003;
    FButtons[2].dwFlags := THBF_ENABLED;
    FButtons[2].iBitmap := 2;
    StringToWideChar('Pause', FButtons[2].szTip, 260);
    FButtons[2].dwMask := THB_BITMAP or THB_FLAGS or THB_TOOLTIP;
    // Add buttons to thumbnail
    FTaskBar.ThumbBarAddButtons(Handle, 3, @FButtons[0]);
    FTaskBar.SetThumbnailTooltip(Handle, 'Test');
    Timer1.Enabled := True;
  end;
end;</pre>
<p>To handle buttons click we need to catch WM_COMMAND message, WParamLo field will contains id of clicked button:</p>
<pre class="brush:delphi">procedure TForm8.WndProc(var Message: TMessage);
begin
  //...//
  if Message.Msg = WM_COMMAND then
  begin
    // Handle 'Reset' button
    if Message.WParamLo = 40001 then
    begin
      Timer1.Enabled := True;
      FTaskBar.SetProgressState(Handle, TBPF_NORMAL);
      FTick := 0;
    end;
    // Handle 'Play' button
    if Message.WParamLo = 40002 then
    begin
      // Run timer again
      Timer1.Enabled := True;
      FTaskBar.SetProgressState(Handle, TBPF_NORMAL);
      // Set overlay icon to asterix icon
      FTaskBar.SetOverlayIcon(Handle, FNormalIcon, 'In progress');
      ProgressBar1.State := pbsNormal;
      // Disable 'Play' button
      FButtons[1].dwFlags := THBF_DISABLED;
      // Enable 'Pause' button
      FButtons[2].dwFlags := THBF_ENABLED;
      // Update buttons
      FTaskBar.ThumbBarUpdateButtons(Handle, 3, @FButtons[0])
    end;
    // Handle 'Pause' button. Almost the same as for 'Play'
    if Message.WParamLo = 40003 then
    begin
      Timer1.Enabled := False;
      FTaskBar.SetProgressState(Handle, TBPF_PAUSED);
      FTaskBar.SetOverlayIcon(Handle, FPauseIcon, 'Paused');
      ProgressBar1.State := pbsPaused;
      FButtons[1].dwFlags := THBF_ENABLED;
      FButtons[2].dwFlags := THBF_DISABLED;
      FTaskBar.ThumbBarUpdateButtons(Handle, 3, @FButtons[0])
    end;
  end;
end;</pre>
<p>And finally OnTimer handler code:</p>
<pre class="brush:delphi">procedure TForm8.Timer1Timer(Sender: TObject);
begin
  FTaskBar.SetProgressValue(Handle, FTick, 200);
  ProgressBar1.Position := FTick;
  Inc(FTick);
  // It's all?
  if FTick &gt;= 200 then
  begin
    // Set indeterminate progress mode for tasbar button
    FTaskBar.SetProgressState(Handle, TBPF_INDETERMINATE);
    Timer1.Enabled := False;
  end;
end;</pre>
<p>That&#8217;s all for &#8220;Part 1&#8243; &#8211; I hope that it will be useful for someone.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.lmd.de/2009/12/new-windows-7-api-for-taskbar-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

