Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

GDI/GDI+ C++ Capture o'content of Window - order of commands

  • Please log in to reply
No replies to this topic
  • Members
  • 691 posts
  • Last active: Oct 21 2015 09:41 PM
  • Joined: 21 May 2012

I want to make the same thing as kon did in this thread:

In his code he used function Gdip_BitmapFromHWND. I need to understand why there is selected object of bitmap on line 6. It doesn't make sense to me because PrintWindow() does not use hbitmap but hdc. Why select object in the moment when we don't work with it?

    // Part 1: get the DC
    WinGetPos,,, Width, Height, ahk_id %hwnd%
    hbm := CreateDIBSection(Width, Height)
    hdc := CreateCompatibleDC()
  obm := SelectObject(hdc, hbm)

    // Part 2:  "copy" pixels from window into bitmap
    PrintWindow(hwnd, hdc)
    pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)

    // Finish
    SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
    return pBitmap

See my C++ code:
0. GpBitmap *pBitmap = NULL;

1. HDC HDevice = CreateCompatibleDC(NULL);
2. HBitmap = CreateDIBSection(HDevice, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);
3.(a)? Select object HBitmap into HDevice now? (HDC = HDevice)
4. create compatible DC for HWND
5.(b ) ----
6. PrintWindow(HWND, HDevice);
7. GdipCreateBitmapFromHBitmap(HBITMAP, 0, GpBitmap);

At point 3.a and 5.b I am not sure if 3.a should not be placed in position 5.b?
At point 7 I am not sure about third argument, because it is null. And I don't know what do to to get handle. If think it should be output, so can it be.

Still I will ask on forum. I am just interested about the order.