i'm trying to capture the entire desktop bmp image:
call GetDC,0
mov hdc,eax
; let's capturing the desktop
mov bmpinfo.bmiHeader.biSize, SIZE bmiHeader
mov bmpinfo.bmiHeader.biWidth, 1024
mov bmpinfo.bmiHeader.biHeight, 768
mov bmpinfo.bmiHeader.biPlanes, 1
mov bmpinfo.bmiHeader.biBitCount, 32
mov bmpinfo.bmiHeader.biCompression, BI_RGB
mov bmpinfo.bmiHeader.biSizeImage, 0
mov bmpinfo.bmiHeader.biClrUsed, 0
mov bmpinfo.bmiHeader.biClrImportant, 0
mov bmpinfo.bmiColors.rgbBlue, 0FFh
mov bmpinfo.bmiColors.rgbGreen, 0FFh
mov bmpinfo.bmiColors.rgbRed, 0FFh
call CreateDIBSection,\
hdc,\ ; // handle to device context
offset bmpinfo,\ ; // pointer to structure containing bitmap size, format, and color data
DIB_RGB_COLORS,\ ; // color data type indicator: RGB values or palette indices
offset bmpPointer,\ ; // pointer to variable to receive a pointer to the bitmap's bit values
NULL,\ ; // optional handle to a file mapping object
NULL
function return a valid handle to bmp but when i go to see the bitmap loaded in memory all the byte of the bitmap colors are set to 00h and i can't understand why. So i can't capturing desktop colors.
Could someone help ?
thanx
call GetDC,0
mov hdc,eax
; let's capturing the desktop
mov bmpinfo.bmiHeader.biSize, SIZE bmiHeader
mov bmpinfo.bmiHeader.biWidth, 1024
mov bmpinfo.bmiHeader.biHeight, 768
mov bmpinfo.bmiHeader.biPlanes, 1
mov bmpinfo.bmiHeader.biBitCount, 32
mov bmpinfo.bmiHeader.biCompression, BI_RGB
mov bmpinfo.bmiHeader.biSizeImage, 0
mov bmpinfo.bmiHeader.biClrUsed, 0
mov bmpinfo.bmiHeader.biClrImportant, 0
mov bmpinfo.bmiColors.rgbBlue, 0FFh
mov bmpinfo.bmiColors.rgbGreen, 0FFh
mov bmpinfo.bmiColors.rgbRed, 0FFh
call CreateDIBSection,\
hdc,\ ; // handle to device context
offset bmpinfo,\ ; // pointer to structure containing bitmap size, format, and color data
DIB_RGB_COLORS,\ ; // color data type indicator: RGB values or palette indices
offset bmpPointer,\ ; // pointer to variable to receive a pointer to the bitmap's bit values
NULL,\ ; // optional handle to a file mapping object
NULL
function return a valid handle to bmp but when i go to see the bitmap loaded in memory all the byte of the bitmap colors are set to 00h and i can't understand why. So i can't capturing desktop colors.
Could someone help ?
thanx
Try this
The CreateCompatibleBitmap function creates a bitmap compatible with the device that is associated with the specified device context.
HBITMAP CreateCompatibleBitmap(
HDC hdc, // handle of device context
int nWidth, // width of bitmap, in pixels
int nHeight // height of bitmap, in pixels
);
Parameters
hdc
Identifies a device context.
nWidth
Specifies the bitmap width, in pixels.
nHeight
Specifies the bitmap height, in pixels.
Return Value
If the function succeeds, the return value is a handle of the bitmap.
The CreateCompatibleBitmap function creates a bitmap compatible with the device that is associated with the specified device context.
HBITMAP CreateCompatibleBitmap(
HDC hdc, // handle of device context
int nWidth, // width of bitmap, in pixels
int nHeight // height of bitmap, in pixels
);
Parameters
hdc
Identifies a device context.
nWidth
Specifies the bitmap width, in pixels.
nHeight
Specifies the bitmap height, in pixels.
Return Value
If the function succeeds, the return value is a handle of the bitmap.
Nguga,
thanks, i've try but again nothing.
now i'm doing:
CreateDIBSection create the correct space ion memory but all fill with 00 (black).
I'm doing somthing wrong. If some help, thanks
thanks, i've try but again nothing.
now i'm doing:
call GetDC,0
mov hdcScreen,eax
call CreateCompatibleDC, hdcScreen
mov Deskdc,eax
call CreateCompatibleBitmap, hdcScreen, 1024, 768
call SelectObject, Deskdc, eax
mov bmpinfo.bmiHeader.biSize, SIZE bmiHeader
mov bmpinfo.bmiHeader.biWidth, 1024
mov bmpinfo.bmiHeader.biHeight, 768
mov bmpinfo.bmiHeader.biPlanes, 1
mov bmpinfo.bmiHeader.biBitCount, 32
mov bmpinfo.bmiHeader.biCompression, BI_RGB
mov bmpinfo.bmiHeader.biSizeImage, 0
mov bmpinfo.bmiHeader.biClrUsed, 0
mov bmpinfo.bmiHeader.biClrImportant, 0
call CreateDIBSection,\
Deskdc,\ ; // handle to device context
offset bmpinfo,\ ; // pointer to structure
DIB_RGB_COLORS,\ ; // color data type
offset bmpPointer,\ ; // pointer to variable s
NULL,\ ; // optional handle
NULL
CreateDIBSection create the correct space ion memory but all fill with 00 (black).
I'm doing somthing wrong. If some help, thanks
This is the code I use
I assume if you change the hWindow to 0 in the GetDC call you'd get the Desktop DC. However I don't think you'll achieve what you want with this alone. Can I assume that you're using a DIBSection is because you want to be able to acess the pixel info directly, other wise you might as well use a compatable Bitmap and stick to GDI.
Also you'll need to BitBlt the Desktop DC to the one you create with the above code. This is very simple, lets assume the desktop dc is still in hDc then:
.data?
hDc dd ?
bDc dd ?
pBb dd ?
hBm dd ?
.code
InitDoubleBuffer Proc
LOCAL bih:BITMAPINFOHEADER
invoke GetDC,hWindow
mov hDc, eax
invoke GetClientRect,hWindow,addr rect
invoke CreateCompatibleDC, hDc
mov bDc, eax
lea edx, bih
mov (BITMAPINFOHEADER ptr [edx]).biSize, sizeof(BITMAPINFOHEADER)
mov eax, rect.right ; You'll want to change these I assume
mov (BITMAPINFOHEADER ptr [edx]).biWidth, eax
mov eax, rect.bottom
mov (BITMAPINFOHEADER ptr [edx]).biHeight, eax
mov (BITMAPINFOHEADER ptr [edx]).biPlanes, 1
mov (BITMAPINFOHEADER ptr [edx]).biBitCount, 32
mov (BITMAPINFOHEADER ptr [edx]).biCompression, BI_RGB
mov (BITMAPINFOHEADER ptr [edx]).biSizeImage, 0
mov (BITMAPINFOHEADER ptr [edx]).biXPelsPerMeter, 0
mov (BITMAPINFOHEADER ptr [edx]).biYPelsPerMeter, 0
mov (BITMAPINFOHEADER ptr [edx]).biClrUsed, 0
mov (BITMAPINFOHEADER ptr [edx]).biClrImportant, 0
invoke CreateDIBSection, bDc, edx, DIB_RGB_COLORS, addr pBb, 0, 0
mov hBm, eax
invoke SelectObject, bDc, eax
ret
InitDoubleBuffer EndP
I assume if you change the hWindow to 0 in the GetDC call you'd get the Desktop DC. However I don't think you'll achieve what you want with this alone. Can I assume that you're using a DIBSection is because you want to be able to acess the pixel info directly, other wise you might as well use a compatable Bitmap and stick to GDI.
Also you'll need to BitBlt the Desktop DC to the one you create with the above code. This is very simple, lets assume the desktop dc is still in hDc then:
invoke BitBlt, bDc, 0, 0, rect.right, rect.bottom,\
hDc, 0, 0, SRCCOPY
If it may help, this is the way i do it for definig the Screen Table in DirectDrawing:
BuildScreenBitMap:
; Ask Win to create a BitMap for the whole screen (this BitMap belongs to Win).
; (This is to ease computation of values if you want another screen Mode).
call 'GDI32.CreateDCA' Display 0 0 0 | mov D?ScreenDcHandle eax
call 'USER32.GetSystemMetrics' &SM_CXSCREEN | mov D?ScreenDim.x eax
call 'USER32.GetSystemMetrics' &SM_CYSCREEN | mov D?ScreenDim.y eax
call 'GDI32.CreateCompatibleBitmap' D?ScreenDcHandle D?ScreenDim.x D?ScreenDim.y
mov D?ScreenBitMapHandle eax
; Ask Win to give us required info for what is this BitMap:
call 'GDI32.GetObjectA' D?ScreenBitMapHandle D?BITMAPlen BITMAP
mov eax D?bmWidthBytes | mul D?bmHeight | mov D?VirtualScreenLen eax
call 'GDI32.DeleteObject' D?ScreenBitMapHandle
call 'GDI32.DeleteDC' D?ScreenDcHandle
ret
Betov.
BuildScreenBitMap:
; Ask Win to create a BitMap for the whole screen (this BitMap belongs to Win).
; (This is to ease computation of values if you want another screen Mode).
call 'GDI32.CreateDCA' Display 0 0 0 | mov D?ScreenDcHandle eax
call 'USER32.GetSystemMetrics' &SM_CXSCREEN | mov D?ScreenDim.x eax
call 'USER32.GetSystemMetrics' &SM_CYSCREEN | mov D?ScreenDim.y eax
call 'GDI32.CreateCompatibleBitmap' D?ScreenDcHandle D?ScreenDim.x D?ScreenDim.y
mov D?ScreenBitMapHandle eax
; Ask Win to give us required info for what is this BitMap:
call 'GDI32.GetObjectA' D?ScreenBitMapHandle D?BITMAPlen BITMAP
mov eax D?bmWidthBytes | mul D?bmHeight | mov D?VirtualScreenLen eax
call 'GDI32.DeleteObject' D?ScreenBitMapHandle
call 'GDI32.DeleteDC' D?ScreenDcHandle
ret
Betov.
all,
many thanks, i'm goin to try now.
many thanks, i'm goin to try now.
i've try your kind suggestions,
again no way to capture this desktop image in memory :(
Zadkiel,
i've try your way but nothing. Space in memory remain blak (all 00h) in anyway.
Betov,
i can get valid info with GetObject but then ? How can i get the bitmap in memory ?
If you will, i hope for some other help. thanks.
again no way to capture this desktop image in memory :(
Zadkiel,
i've try your way but nothing. Space in memory remain blak (all 00h) in anyway.
Betov,
i can get valid info with GetObject but then ? How can i get the bitmap in memory ?
If you will, i hope for some other help. thanks.
excuse me for all this mess,
i've done it !
the code is:
thanks again !!
i've done it !
the code is:
call GetDesktopWindow
call GetDC, eax
mov hdcScreen,eax
call CreateCompatibleDC, hdcScreen
mov Deskdc, eax
call CreateCompatibleBitmap, hdcScreen, 1024, 768
call SelectObject, Deskdc, eax
; let's capturing the desktop
mov bmpinfo.bmiHeader.biSize, SIZE bmiHeader
mov bmpinfo.bmiHeader.biWidth, 1024
mov bmpinfo.bmiHeader.biHeight, 768
mov bmpinfo.bmiHeader.biPlanes, 1
mov bmpinfo.bmiHeader.biBitCount, 32
mov bmpinfo.bmiHeader.biCompression, BI_RGB
mov bmpinfo.bmiHeader.biSizeImage, 0
mov bmpinfo.bmiHeader.biXPelsPerMeter, 0
mov bmpinfo.bmiHeader.biYPelsPerMeter, 0
mov bmpinfo.bmiHeader.biClrUsed, 0
mov bmpinfo.bmiHeader.biClrImportant, 0
call CreateDIBSection, Deskdc, offset bmpinfo, DIB_RGB_COLORS, offset bmpPointer,\
NULL, NULL
call SelectObject, Deskdc, eax
call BitBlt, Deskdc, 0, 0, 1024, 768, hdcScreen, 0, 0, SRCCOPY
thanks again !!