为了测试2位颜色位图装载到设备是否出错,编写了下面这段测试代码,如下:
#001 /* test with 2 bits color depth,not likely to succeed */
#002 hbmp = CreateBitmap(16,16,1,2,bits);
#003 ok( hbmp != NULL,"CreateBitmap returns %p/n",hbmp);
#004 oldhbmp = SelectObject( hdcmem,hbmp);
#005 if( bitspixel != 2)
#006 ok( !oldhbmp,"SelectObject of a bitmap with 2 bits/pixel should return NULL/n");
从这段代码可以看到,当内存DC不是两位颜色时,选择加载2位颜色的位图,就需要返回空句柄,否则就是这个SelectObject的API函数实现有问题。在没有修改这个BUG之前,这个函数返回是成功的加载位图了。因此需要修改这个函数的代码如下:
#001 HBITMAP
#002 APIENTRY
#003 NtGdiSelectBitmap(
#004 IN HDC hDC,
#005 IN HBITMAP hBmp)
#006 {
#007 PDC pDC;
#008 PDC_ATTR pdcattr;
#009 HBITMAP hOrgBmp;
#010 PSURFACE psurfBmp,psurfOld;
#011 HRGN hVisRgn;
#012
#013 if (hDC == NULL || hBmp == NULL) return NULL;
#014
#015 pDC = DC_LockDc(hDC);
#016 if (!pDC)
#017 {
#018 return NULL;
#019 }
#020 pdcattr = pDC->pdcattr;
#021
#022 /* must be memory dc to select bitmap */
#023 if (pDC->dctype != DC_TYPE_MEMORY)
#024 {
#025 DC_UnlockDc(pDC);
#026 return NULL;
#027 }
#028
#029 psurfBmp = SURFACE_LockSurface(hBmp);
#030 if (!psurfBmp)
#031 {
#032 DC_UnlockDc(pDC);
#033 return NULL;
#034 }
#035
#036 //判断位图颜色数目是否与设备的颜色数目一样。
#037 if (pDC->ppdev)
#038 {
#039 if (BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat) == 4)
#040 {
#041 //
#042 DPRINT1("BitsPerFormat %d/n",BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat));
#043 DPRINT1("pDC->ppdev->gdiinfo.cBitsPixel %d/n",pDC->ppdev->gdiinfo.cBitsPixel);
#044
#045 if ( BitsPerFormat(psurfBmp->SurfObj.iBitmapFormat) !=
#046 pDC->ppdev->gdiinfo.cBitsPixel)
#047 {
#048 SURFACE_UnlockSurface(psurfBmp);
#049
#050 DC_UnlockDc(pDC);
#051 return NULL;
#052 }
#053 }
#054 }
#055
原文链接:https://www.f2er.com/react/308321.html