Skip to Content
author's profile photo Former Member
Former Member

Capturing a screenshot does not work in PB 12.6 anymore


I use the code of TopWiz to capure screenshots of a window. It seems that the sample doesn not work with PB 12.6 anymore (works fine for PB 11.5). The strange is: Copying to clipboard is good, but saving will end up in corrupted file. Maybe there is another behaviour handling blobs in PB.

Any ideas?

// capture bitmap and return as blob

ULong lul_hdc, lul_hdcMem, lul_hBitmap, lul_pixels
Blob lblb_header, lblb_info, lblb_bitmap
BitmapInfo lstr_Info
BitmapFileHeader lstr_Header

// Get the device context of window and allocate memory
lul_hdc = GetDC(aul_hWnd)
lul_hdcMem = CreateCompatibleDC(lul_hdc)
lul_hBitmap = CreateCompatibleBitmap(lul_hdc, aul_width, aul_height)

If lul_hBitmap <> 0 Then
    // Copy the bitmap to memory location
    SelectObject(lul_hdcMem, lul_hBitmap)
   BitBlt(lul_hdcMem, 0, 0, aul_width, aul_height, &
                        lul_hdc, aul_xpos, aul_ypos, SRCCOPY)
    // try to store the bitmap into a blob so we can save it
    lstr_Info.bmiHeader.biSize = 40
    // Get the bitmapinfo
    If GetDIBits(lul_hdcMem, lul_hBitmap, 0, aul_height, &
                            0, lstr_Info, DIB_RGB_COLORS) > 0 Then
        lul_pixels = lstr_Info.bmiHeader.biBitCount
        lstr_Info.bmiColors[lul_pixels] = 0

lblb_bitmap = Blob(Space(lstr_Info.bmiHeader.biSizeImage/2)) // get the actual bits GetDIBits(lul_hdcMem, lul_hBitmap, 0, aul_height, & lblb_bitmap, lstr_Info, DIB_RGB_COLORS) // create a bitmap header lstr_Header.bfType = BITMAPTYPE lstr_Header.bfSize = lstr_Info.bmiHeader.biSizeImage lstr_Header.bfOffBits = 54 + (lul_pixels * 4) // copy the header structure to a blob lblb_header = Blob(Space(14/2)) CopyBitmapFileHeader(lblb_header, lstr_Header, 14) // copy the info structure to a blob lblb_Info = Blob(Space((40 + lul_pixels * 4)/2)) CopyBitmapInfo(lblb_Info, lstr_Info, 40 + lul_pixels * 4) // add all together and we have a window bitmap in a blob lblb_bitmap = lblb_header + lblb_info + lblb_bitmap End If End If // paste bitmap to clipboard If ab_clipboard Then If OpenClipboard(aul_hWnd) Then EmptyClipboard() SetClipboardData(CF_BITMAP, lul_hBitmap) CloseClipboard() Else MessageBox("OpenClipboard Failed", of_GetLastError()) End If End If // Clean up handles DeleteDC(lul_hdcMem) ReleaseDC(aul_hWnd, lul_hdc) Return lblb_bitmap
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on May 19, 2015 at 02:14 PM

    So if Clipboard works, your snippet is o.k., right?

    Take a notice of this thread, in case that dll calls using structures are involved :

    Just an idea to change the external functions that copy structures in momery to use the progma_pack ()

    Subroutine CopyBitmapFileHeader ( ... ) Library "kernel32.dll" Alias For "RtlMoveMemory" progma_pack(1)

    Subroutine CopyBitmapInfo ( ... ) Library "kernel32.dll" Alias For "RtlMoveMemory" progma_pack(1)

    But you need the newest EBF.

    For a quick test, download the updated version of n_bitmap.sru from the topwiz site.


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.