By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,719 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,719 IT Pros & Developers. It's quick & easy.

Screen capture problem - CreateCompatibleBitmap API

P: n/a
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_CX SCREEN)
'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.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Try this code instead.( Works a treat )

http://www.planet-source-code.com/vb...=309&lngWId=10

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Juan Romero" <ju******@optonline.net> wrote in message
news:e1**************@TK2MSFTNGP15.phx.gbl...
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_CX SCREEN)
'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.

Nov 21 '05 #2

P: n/a
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.)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.