Best way to handle multiple color depth bitmaps

Hi,

I want my application to work well when the display is set for different color depths. Specifically, I want to be able to display 16 color bitmaps in my speed buttons when the display is set to 256 colors, and 256 color bitmaps when the display is set to a higher color depth setting.

My question is, how should I store the different color depth bitmaps, and how do I automatically switch them when the display settings change?

Regards,

Bill
LVL 1
wipnavAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZhaawZSoftware DeveloperCommented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    procedure onDisplayChange (var msg : TMessage); message wm_displaychange;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.onDisplayChange(var msg : TMessage);
begin
// this procedure is the place where you should switch pics
ShowMessage(Format('%d x %d @ %d bits', [msg.lParam and $ffff, msg.lParam shr 16 and $ffff, msg.wParam]));
end;

end.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZhaawZSoftware DeveloperCommented:
About switching images... I'm not sure, but it could be done like this:


procedure TForm1.onDisplayChange(var msg : TMessage);
var
  ImageList : TImageList;
begin
if msg.wParam <= 4 then begin // 16 colors or less
  ImageList := ImageList2;
end else begin // more than 16 colors
  ImageList1 := ImageList1;
end;
ImageList.GetBitmap(0, SpeedButton1.Glyph);
ImageList.GetBitmap(1, SpeedButton2.Glyph);
end;
wipnavAuthor Commented:
Thank you that helps.

Also, is there a way to check the color depth when my application starts up so that I can assign the correct initial imagelist?
ZhaawZSoftware DeveloperCommented:
Sure, there is. Put this in onCreate event:

var
  dev : DevMode;
begin
ZeroMemory(@dev, sizeof(dev));
dev.dmSize := sizeof(dev);
// we need only color depth, so set dmFields to dm_bitsperpel
dev.dmFields := dm_bitsperpel;
// get current screen settings (in our case - only color depth)
EnumDisplaySettings(nil, {enum_current_settings} $ffffffff, dev);
// dev.dmBitsPerPel will be current screen resolution, so send it as wParam
// resolution is not needed in our case, so we can leave 0 as lParam
SendMessage(handle, wm_displaycnage, dev.dmBitsPerPel, 0);
end;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.