• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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
0
wipnav
Asked:
wipnav
  • 3
1 Solution
 
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.
0
 
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;
0
 
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?
0
 
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;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now