Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft C# .NET
CreateCompatibleBitmap returns NULL
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Guest, post: 5603045"] I'm capturing the screen using the following code , but the problem i have that after 43 calls of the functions the NULL reference object is returned , SIZE size; //Here we get the handle to the desktop device context. IntPtr hDC = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetDesktopWindow()); //Here we make a compatible device context in memory for screen device context. IntPtr hMemDC = PlatformInvokeGDI32.CreateCompatibleDC(hDC); //We pass SM_CXSCREEN constant to GetSystemMetrics to get the X coordinates of screen. size.cx = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CXSCREEN); //We pass SM_CYSCREEN constant to GetSystemMetrics to get the Y coordinates of screen. size.cy = PlatformInvokeUSER32.GetSystemMetrics(PlatformInvokeUSER32.SM_CYSCREEN); //We create a compatible bitmap of screen size and using screen device context. m_HBitmap = PlatformInvokeGDI32.CreateCompatibleBitmap(hDC, size.cx, size.cy); //Here m_HBitmap return be NULL(Zero) after 43 calls of the function...WHY? //As m_HBitmap is IntPtr we can not check it against null. For this purspose IntPtr.Zero is used. if (m_HBitmap!=IntPtr.Zero) { //Here we select the compatible bitmap in memeory device context and keeps the refrence to Old bitmap. IntPtr hOld = (IntPtr) PlatformInvokeGDI32.SelectObject(hMemDC, m_HBitmap); //We copy the Bitmap to the memory device context. PlatformInvokeGDI32.BitBlt(hMemDC, 0, 0,size.cx,size.cy, hDC, 0, 0, PlatformInvokeGDI32.SRCCOPY); //We select the old bitmap back to the memory device context. PlatformInvokeGDI32.SelectObject(hMemDC, hOld); //We delete the memory device context. PlatformInvokeGDI32.DeleteDC(hMemDC); //We release the screen device context. PlatformInvokeUSER32.ReleaseDC(PlatformInvokeUSER32.GetDesktopWindow(), hDC); //Image is created by Image bitmap handle and returned. return System.Drawing.Image.FromHbitmap(m_HBitmap); } //If m_HBitmap is null retunrn null. return null; [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft C# .NET
CreateCompatibleBitmap returns NULL
Top