the Chromium logo

The Chromium Projects

Leak GDI Objects in Windows


Anti Patterns

DeleteObject with HICON

DeleteObject WIN32 API works all GDI objects except for icon (97559)

We must use DestroyIcon.


810 HICON empty_icon = 811 IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap()); 812 ImageList_AddIcon(image_list, empty_icon); 813 ImageList_AddIcon(image_list, empty_icon); 814 DeleteObject(empty_icon);

Leak Screen DC aka GetDC(NULL)

GetDC(NULL) returns newly created screen DC. So, you must release it by using ReleaseDC. You may want to use ScopedGetDC (

I would like to draw in bitmap (


235 // Page used alpha blend, but printer doesn't support it. Rewrite the

236 // metafile and flatten out the transparency.

237 HDC bitmap_dc = CreateCompatibleDC(GetDC(NULL));

238 if (!bitmap_dc)

Easy way to know screen DPI:


299 int screen_dpi = GetDeviceCaps(GetDC(NULL), LOGPIXELSX);

300 xform.eM11 = xform.eM22 =

301 static_cast<float>(screen_dpi) / static_cast<float>(render_dpi);

Play Enhanced Metafile Record More Than Once

Oops, some devices don't support alpha blending. We should do alpha blending by ourselves by using bitmap DC (

Since, metafile records having GDI object creation command and stores into lpHandleTable of second parameter of EnhMetaFileProc.

In crhome/renderer/

40 // Play this command to the bitmap DC.

41 PlayEnhMetaFileRecord(*bitmap_dc, handle_table, record, num_objects);


68 // Play this command to the metafile DC.

69 PlayEnhMetaFileRecord(dc, handle_table, record, num_objects);