2011. május 30., hétfő

Use PBM_SETMARQUEE and PBS_MARQUEE in Delphi


Problem/Question/Abstract:

According to Microsoft you could use a progress bar with style set to PBS_MARQUEE if you don't know the final value. It will show a progress bar with only a gradient going from left to right. I find no other references to these constants except from MSDN. Anyone know how to use them in Delphi?

Answer:

It's defined in CommCtrl.h:

#if (_WIN32_WINNT >= 0x0501)
#define PBS_MARQUEE             0x08
#define PBM_SETMARQUEE          (WM_USER+10)
#endif      // _WIN32_WINNT >= 0x0501

In Delphi (untested):

{ ... }
const
  PBS_MARQUEE = $08;
  PBM_SETMARQUEE = (WM_USER + 10);

You set this style by subclassing the TProgressBar.CreateParams methods and setting PBS_MARQUEE:

procedure TMyProgressBar.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.Style := Params.Style or PBS_MARQUEE;
end;

You can now turn on the marquee:

SendMessage(MyProgressBar1.Handle, PBS_SETMARQUEE, 1, 200);

and off:

SendMessage(MyProgressBar1.Handle, PBS_SETMARQUEE, 0, 200);

The 200 is the number of milliseconds between animation updates.

Nincsenek megjegyzések:

Megjegyzés küldése