Screen capture problem - CreateCompatibleBitmap API


J

Juan Romero

Guys,

I am trying to capture the desktop screen (everything).
I am having a problem with the "CreateCompatibleBitmap" API call. For some
reason the function is creating a 1x1 pixels bitmap EVERYTIME. I am
correctly passing the handles to the function (to the best of my knowledge
at least) but it just refuses to create a bitmap in memory with the
dimensions I provide. Here is the code:

'Get the desktop handle
hDesktop = User32.GetDesktopWindow()

'Get the Desktop device context handle
hDesktopDC = User32.GetDC(hDesktop)

'Create a compatible Device context in memory
hMemDC = GDI32.CreateCompatibleDC(hDesktopDC)

'Get the size of the screen in pixels
'ssize.Width = User32.GetSystemMetrics(User32.SystemMetrics_SM_CXSCREEN)
'ssize.Height = User32.GetSystemMetrics (User32.SystemMetrics_SM_CYSCREEN)
ssize.Height = 768
ssize.Width = 1024
'Create a compatible bitmap from the desktop device context
hBitmap = GDI32.CreateCompatibleBitmap(hDesktopDC, ssize.Width,
ssize.Height)
-------------------------
When I run the debugger, everything before that executes appropiately, I get
the handles from the other functions, but the bitmap returned by the handle
from last instruction is a 1x1 pixel bitmap!

Another problem I am having (I might as well mention it here too) is that
the GetSystemMetrics API call returns some weird numbers when I try to get
the screen height and width. Very long numbers like: 17452454615467

It is supposed to return 1024 and 768 (in my case) but it doesn't for some
reason. I have a VB application that calls the same function and in VB it
does return these numbers, with the same function declaration....

Any ideas of why vb .NET does this?

Thank you in advance.
 
Ad

Advertisements

Ad

Advertisements

J

Juan Romero

Thank you OHM. The code works great indeed. I appreciate your help!

Regards,
Juan Romero
(To e-mail me remove the underscores from my e-mail address.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top