Mega Code Archive

 
Categories / Delphi / Hardware
 

Checking the current display mode of a computer

Title: Checking the current display mode of a computer Question: How do you check the display mode of the computer your program is running on to adjust graphics etc? Answer: You've probably noticed in many products that their splash screens vary on the color depth of your monitor settings. But what I've always wanted to know is how this is done, so I looked into the Windows API and came up with a solution. Please note, there may be better ways to do this but at present this is the only way I know. The peice of information you want to know is how many colors the system is currently running at. To do this all you need to do is use the Windows API function GetDeviceCaps in combination with GetDC and GetDesktopWindow. Hence whatever color mode the Desktop is running at the GetDeviceCaps function will return the bits per pixel/pel. Here is a small table of color informations: Mode: Bits per pixel/pel: Black and White 2 16 Colors 4 256 Colors 8 High Color 16 True Color 24 When do you alter graphics? Good question, really you should alter graphics below 256 colors if they look shoddy in 16 colors. To show you how such a system can be implemented look at the demo below. It can easily be adapted to suite other color modes. procedure TForm1.FormCreate(Sender: TObject); var BPP: Integer; // Bits per pixel begin BPP := GetDeviceCaps(GetDC(GetDesktopWindow),BITSPIXEL); if (BPP 2) and (BPP B&W and begin Image1.Picutre.Bitmap.LoadFromFile('16color.bmp'); end else begin Image1.Picture.Bitmap.LoadFromFile('256color.bmp'); end; end; In the above example, if the color mode is 16 colors (or anything above B&W but below 256 color) then it loads the appropriate graphic, otherwise it loads the normal graphic. Simple yet powerful...