Welcome to MSDN Blogs Sign in | Join | Help

GDI has a method call GetObject which can be used to get information about a GDI object. On Windows CE you can use GetObject to get the pixel format for any bitmap by passing in a DIBSECTION instead of a BITMAP. Here's an example:

   DIBSECTION ds;
   HDC        hdc = GetDC(NULL);
   HGDIOBJ    bmp = GetCurrentObject(hdc, OBJ_BITMAP);

   GetObject(bmp, sizeof (ds), &ds);

Obviously, in production code you'd want to actually check return values, but this is the general idea. If (ds.dsBm.bmBitsPixel > 8) and (ds.dsBmih.biCompression == BI_BITFILEDS), ds.dsBitfields will contain the bit masks for the three color channels. If ds.dsBmih.biCompression is BI_RGB, the bitmap is either an RGB surface, or a palettized surface and ds.dsBitfields will be 0.

This behavior makes it relatively easy to create a DIB section that has the same pixel format as another bitmap.

FYI: I don't believe this works on the desktop.

1 Comments
Filed under: ,

If I'm going to ever talk about writing code on Windows CE, I'll need to get started. Probably the most obvious place to start is WinMain. Wait, that's the desktop's version of WinMain, since I'm writing code on Windows CE, I'll want to look at the Windows CE version of WinMain. Why would CE have a different prototype for WinMain than XP? Well the answer to that is simple: Windows CE uses UNICODE. Most (maybe all?) of the Win32 functions that have ASCII or wide chacarcter variants on XP, only have the wide character variant on CE. This cuts down on the number of entries in coredll, and helps to promote writing international-safe apps.

The prototype for XP's version of WinMain is:

int WINAPI WinMain(
  HINSTANCE hInstance, 
  HINSTANCE hPrevInstance, 
  LPSTR lpCmdLine, 
  int nShowCmd 
); 

The prototype for CE's version of WinMain is:

int WINAPI WinMain(
  HINSTANCE hInstance, 
  HINSTANCE hPrevInstance, 
  LPWSTR lpCmdLine, 
  int nShowCmd 
); 

The only difference is with the lpCmdLine parameter. On CE it's always of type LPWSTR.

Well, that's the first difference I wanted to point out. It's probably obvious to most people, but I think it's a decent place to start.

4 Comments
Filed under: ,

Welcome to the new home for my sporadically updated blog. I'm particularly fond of fixed width fonts, so you'll probably be seeing a lot of them.

Over the next couple of days, I'll be playing around with the formatting of this site (and probably posting a bunch of “test” messages to see how things look or work.

5 Comments
Filed under:
 
Page view tracker