Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   [win32][gdi32] Copying HDC to another? (http://www.programmingforums.org/showthread.php?t=15241)

null_ptr0 Feb 22nd, 2008 7:13 PM

[win32][gdi32] Copying HDC to another?
 
I've tried to do CreateCompatibleDC(source_device) but it contains a result the same height and size as source_device but every pixel as black. Any help?
:

const int SCREEN_WIDTH = GetSystemMetrics(SM_CXSCREEN) - 1;
const int SCREEN_HEIGHT = GetSystemMetrics(SM_CXSCREEN) - 1;
...
    int x;
    HDC screen_device = GetDC(NULL);
    HDC copy = CreateCompatibleDC(screen_device);
    for (x = 0; x <= SCREEN_WIDTH; ++x) {
        for (int y = 0; y <= SCREEN_HEIGHT; ++y) {
            SetPixel(screen_device, x, y,  GetPixel(copy, SCREEN_WIDTH - x, y));
        }
    }
...


EDIT:
I see I have to use BitBlt? If so, may I have an example? I have an inefficiency in understanding win32 argument names.

The Dark Feb 22nd, 2008 7:43 PM

Re: [win32][gdi32] Copying HDC to another?
 
You code seems to be setting the pixels in the screen device from the copy, I think it should be the other way around.

Ooble Feb 23rd, 2008 7:48 AM

Re: [win32][gdi32] Copying HDC to another?
 
In your second line, you use SM_CXSCREEN when it should be SM_CYSCREEN. I think The Dark found your main problem though.

null_ptr0 Feb 23rd, 2008 2:06 PM

Re: [win32][gdi32] Copying HDC to another?
 
Quote:

Originally Posted by Ooble (Post 141404)
In your second line, you use SM_CXSCREEN when it should be SM_CYSCREEN. I think The Dark found your main problem though.

aha. thanks.
@The Dark:
My goal is to create a copy of the screen, and then reverse the screen from reversing the pixels on my copy.

Ooble Feb 23rd, 2008 2:25 PM

Re: [win32][gdi32] Copying HDC to another?
 
From the CreateCompatibleDC page:

Quote:

A memory DC exists only in memory. When the memory DC is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory DC for drawing operations, it must select a bitmap of the correct width and height into the DC. To select a bitmap into a DC, use the CreateCompatibleBitmap function, specifying the height, width, and color organization required.
I'd recommend reading the rest of the stuff under the Remarks heading too.

null_ptr0 Feb 23rd, 2008 2:45 PM

Re: [win32][gdi32] Copying HDC to another?
 
your link points to GetDC

edit:
how would i set the newly created HBITMAP's pixels?

Ooble Feb 23rd, 2008 3:08 PM

Re: [win32][gdi32] Copying HDC to another?
 
Sorry. Here's the real link.

I believe you can do as you were doing after you call CreateCompatibleBitmap. Don't forget that you have to call it on screen_device and then call SelectObject.


All times are GMT -5. The time now is 4:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC