Windows – ExtCreatePen and Windows 7 GDI

gdi+winapiwindows 7

I created DIBPATTERN pens with ExtCreatePen API for custom pattern pens.

It sucessfully draws desired lines on Windows XP,

But on Windows 7 (x64 for my case), it does not draw any lines; no changes on screen.

(Other simply created pens, for example CreatePen(PS_DOT,1,0), are working.)

I found that calling SetROP2(hdc, R2_XORPEN) makes the following line-drawing API calls draw something but with XOR operation. I don't want XOR drawing.

Here is my code to create the pen. It has no problem on Windows XP:

LOGBRUSH lb;
lb.lbStyle = BS_DIBPATTERN;
lb.lbColor = DIB_RGB_COLORS;
int cb = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + 8*4; 
HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, cb);                
BITMAPINFO* pbmi = (BITMAPINFO*) GlobalLock(hg);
ZeroMemory(pbmi, cb);
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
pbmi->bmiHeader.biWidth = 8; 
pbmi->bmiHeader.biHeight = 8; 
pbmi->bmiHeader.biPlanes = 1; 
pbmi->bmiHeader.biBitCount = 1; 
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = 8;
pbmi->bmiHeader.biClrUsed = 2;
pbmi->bmiHeader.biClrImportant = 2;
pbmi->bmiColors[1].rgbBlue =
pbmi->bmiColors[1].rgbGreen =
pbmi->bmiColors[1].rgbRed = 0xFF;
DWORD* p = (DWORD*) &pbmi->bmiColors[2];
for(int k=0; k<8; k++) *p++ = patterns[k];
GlobalUnlock(hg);
lb.lbHatch = (LONG) hg;
s_aSelectionPens[i] = ExtCreatePen(PS_GEOMETRIC, 1, &lb, 0, NULL);
ASSERT(s_aSelectionPens[i]); // success on both XP and Win7
GlobalFree(hg);

Is it bug only on my PC? Please check this problem.
Thank you.

Best Answer

I will admit, I was dubious as first, but I compiled and ran your program, and it does indeed fail to draw the second line on Windows 7, buy only in aero mode

By switching to Windows basic or classic mode, all four lines are drawn, as expected.

I can only assume that this is some kind of bad interaction with your custom pen and the new way aero mode implements GDI calls. This seems like it might be a Microsoft bug, perhaps you can post this question on one of their message boards?

Related Topic