Best way to handle multiple color depth bitmaps


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?


Who is Participating?

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

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;


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

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

  Form1: TForm1;


{$R *.dfm}

procedure TForm1.onDisplayChange(var msg : TMessage);
// 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]));


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);
  ImageList : TImageList;
if msg.wParam <= 4 then begin // 16 colors or less
  ImageList := ImageList2;
end else begin // more than 16 colors
  ImageList1 := ImageList1;
ImageList.GetBitmap(0, SpeedButton1.Glyph);
ImageList.GetBitmap(1, SpeedButton2.Glyph);
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:

  dev : DevMode;
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);
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.