VOID FASTCALL co_IntDrawCaret(PWND pWnd, PTHRDCARETINFO CaretInfo) { HDC hdc, hdcMem; HBITMAP hbmOld; BOOL bDone = FALSE; hdc = UserGetDCEx(pWnd, 0, DCX_USESTYLE | DCX_WINDOW); if (!hdc) { ERR("GetDC failed\n"); return; } if (pWnd->hrgnUpdate) { NtGdiSaveDC(hdc); } if(CaretInfo->Bitmap && NtGdiGetBitmapDimension(CaretInfo->Bitmap, &CaretInfo->Size)) { hdcMem = NtGdiCreateCompatibleDC(hdc); if (hdcMem) { hbmOld = NtGdiSelectBitmap(hdcMem, CaretInfo->Bitmap); bDone = NtGdiBitBlt(hdc, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, hdcMem, 0, 0, SRCINVERT, 0, 0); NtGdiSelectBitmap(hdcMem, hbmOld); GreDeleteObject(hdcMem); } } if (!bDone) { NtGdiPatBlt(hdc, CaretInfo->Pos.x, CaretInfo->Pos.y, CaretInfo->Size.cx, CaretInfo->Size.cy, DSTINVERT); } if (pWnd->hrgnUpdate) { NtGdiRestoreDC(hdc, -1); } UserReleaseDC(pWnd, hdc, FALSE); }
static VOID WINAPI IntSynthesizeBitmap(PWINSTATION_OBJECT pWinStaObj, PCLIP pBmEl) { HDC hdc = NULL; PBITMAPINFO pBmi, pConvertedBmi = NULL; HBITMAP hBm = NULL; PCLIPBOARDDATA pMemObj; PCLIP pDibEl; ULONG Offset; TRACE("IntSynthesizeBitmap(%p, %p)\n", pWinStaObj, pBmEl); pDibEl = IntIsFormatAvailable(pWinStaObj, CF_DIB); ASSERT(pDibEl && !IS_DATA_SYNTHESIZED(pDibEl)); if(!pDibEl->fGlobalHandle) return; pMemObj = (PCLIPBOARDDATA)UserGetObject(gHandleTable, pDibEl->hData, TYPE_CLIPDATA); if (!pMemObj) return; pBmi = (BITMAPINFO*)pMemObj->Data; if (pMemObj->cbData < sizeof(DWORD) && pMemObj->cbData < pBmi->bmiHeader.biSize) goto cleanup; pConvertedBmi = DIB_ConvertBitmapInfo(pBmi, DIB_RGB_COLORS); if (!pConvertedBmi) goto cleanup; Offset = DIB_BitmapInfoSize(pBmi, DIB_RGB_COLORS); hdc = UserGetDCEx(NULL, NULL, DCX_USESTYLE); if (!hdc) goto cleanup; hBm = GreCreateDIBitmapInternal(hdc, pConvertedBmi->bmiHeader.biWidth, pConvertedBmi->bmiHeader.biHeight, CBM_INIT, pMemObj->Data + Offset, pConvertedBmi, DIB_RGB_COLORS, 0, pMemObj->cbData - Offset, 0); if (hBm) { GreSetObjectOwner(hBm, GDI_OBJ_HMGR_PUBLIC); pBmEl->hData = hBm; } cleanup: if (hdc) UserReleaseDC(NULL, hdc, FALSE); if (pConvertedBmi) DIB_FreeConvertedBitmapInfo(pConvertedBmi, pBmi, -1); }
HANDLE FASTCALL renderBITMAPfromDIB(LPBYTE pDIB) { HDC hdc; HBITMAP hbitmap; PBITMAPINFO pBmi, pConvertedBmi = NULL; NTSTATUS Status ; UINT offset = 0; /* Stupid compiler */ pBmi = (BITMAPINFO*)pDIB; //hdc = UserGetDCEx(NULL, NULL, DCX_USESTYLE); hdc = UserGetDCEx(ClipboardWindow, NULL, DCX_USESTYLE); /* Probe it */ _SEH2_TRY { ProbeForRead(&pBmi->bmiHeader.biSize, sizeof(DWORD), 1); ProbeForRead(pBmi, pBmi->bmiHeader.biSize, 1); ProbeForRead(pBmi, DIB_BitmapInfoSize(pBmi, DIB_RGB_COLORS), 1); pConvertedBmi = DIB_ConvertBitmapInfo(pBmi, DIB_RGB_COLORS); if(!pConvertedBmi) { Status = STATUS_INVALID_PARAMETER; } else { offset = DIB_BitmapInfoSize((BITMAPINFO*)pBmi, DIB_RGB_COLORS); ProbeForRead(pDIB + offset, pConvertedBmi->bmiHeader.biSizeImage, 1); } } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { Status = _SEH2_GetExceptionCode(); } _SEH2_END if(!NT_SUCCESS(Status)) { UserReleaseDC(ClipboardWindow, hdc, FALSE); return NULL; } hbitmap = GreCreateDIBitmapInternal(hdc, pConvertedBmi->bmiHeader.biWidth, pConvertedBmi->bmiHeader.biHeight, CBM_INIT, pDIB+offset, pConvertedBmi, DIB_RGB_COLORS, 0, 0); //UserReleaseDC(NULL, hdc, FALSE); UserReleaseDC(ClipboardWindow, hdc, FALSE); DIB_FreeConvertedBitmapInfo(pConvertedBmi, pBmi); return hbitmap; }
HDC APIENTRY NtUserGetDCEx(HWND hWnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) { PWND Wnd=NULL; DECLARE_RETURN(HDC); TRACE("Enter NtUserGetDCEx: hWnd %p, ClipRegion %p, Flags %x.\n", hWnd, ClipRegion, Flags); UserEnterExclusive(); if (hWnd && !(Wnd = UserGetWindowObject(hWnd))) { RETURN(NULL); } RETURN( UserGetDCEx(Wnd, ClipRegion, Flags)); CLEANUP: TRACE("Leave NtUserGetDCEx, ret=%p\n", _ret_); UserLeave(); END_CLEANUP; }
static VOID NTAPI IntSynthesizeDib( PWINSTATION_OBJECT pWinStaObj, HBITMAP hbm) { HDC hdc; ULONG cjInfoSize, cjDataSize; PCLIPBOARDDATA pClipboardData; HANDLE hMem; INT iResult; struct { BITMAPINFOHEADER bmih; RGBQUAD rgbColors[256]; } bmiBuffer; PBITMAPINFO pbmi = (PBITMAPINFO)&bmiBuffer; /* Get the display DC */ hdc = UserGetDCEx(NULL, NULL, DCX_USESTYLE); if (!hdc) { return; } /* Get information about the bitmap format */ iResult = GreGetDIBitsInternal(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS, 0, sizeof(bmiBuffer)); if (iResult == 0) { goto cleanup; } /* Get the size for a full BITMAPINFO */ cjInfoSize = DIB_BitmapInfoSize(pbmi, DIB_RGB_COLORS); /* Calculate the size of the clipboard data, which is a packed DIB */ cjDataSize = cjInfoSize + pbmi->bmiHeader.biSizeImage; /* Create the clipboard data */ pClipboardData = (PCLIPBOARDDATA)UserCreateObject(gHandleTable, NULL, NULL, &hMem, TYPE_CLIPDATA, cjDataSize); if (!pClipboardData) { goto cleanup; } /* Set the data size */ pClipboardData->cbData = cjDataSize; /* Copy the BITMAPINFOHEADER */ memcpy(pClipboardData->Data, pbmi, sizeof(BITMAPINFOHEADER)); /* Get the bitmap bits and the color table */ iResult = GreGetDIBitsInternal(hdc, hbm, 0, abs(pbmi->bmiHeader.biHeight), (LPBYTE)pClipboardData->Data + cjInfoSize, (LPBITMAPINFO)pClipboardData->Data, DIB_RGB_COLORS, pbmi->bmiHeader.biSizeImage, cjInfoSize); /* Add the clipboard data */ IntAddFormatedData(pWinStaObj, CF_DIB, hMem, TRUE, TRUE); /* Release the extra reference (UserCreateObject added 2 references) */ UserDereferenceObject(pClipboardData); cleanup: UserReleaseDC(NULL, hdc, FALSE); }
HDC FASTCALL UserGetWindowDC(PWND Wnd) { return UserGetDCEx(Wnd, 0, DCX_USESTYLE | DCX_WINDOW); }