How to find out DC's dimensions?

前端 未结 6 970
一向
一向 2020-12-31 05:53

Let\'s say I have a handle to device context (naturally, in Windows environment):

HDC hdc;

How can I get the width and height of it?

6条回答
  •  借酒劲吻你
    2020-12-31 06:24

    but if get Calculator' window_dc dimension, it will failed at “GetCurrentObject” or "GetObject", i think maybe the window attribute include "ws_ex_noredirectionbitmap", how to get dismension in this case?

    HDC win_dc = ::GetWindowDC(hwnd);
    BITMAP bm = { 0 };
    HGDIOBJ hBitmap = GetCurrentObject(win_dc, OBJ_BITMAP);
    if (hBitmap)
    {
        if (GetObject(hBitmap, sizeof(BITMAP), &bm))
        {
            windc_dimension.cx = bm.bmWidth;
            windc_dimension.cy = bm.bmHeight;
        }
    }
    

提交回复
热议问题