We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Best way to handle multiple color depth bitmaps

wipnav
wipnav asked
on
Medium Priority
266 Views
Last Modified: 2013-12-03
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
Comment
Watch Question

Software Developer
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
ZhaawZSoftware Developer

Commented:
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;

Author

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 Developer

Commented:
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;
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.