Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 22nd, 2008, 6:13 PM   #1
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 94
Rep Power: 1 null_ptr0 is on a distinguished road
[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.
null_ptr0 is offline   Reply With Quote
Old Feb 22nd, 2008, 6:43 PM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
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.
The Dark is offline   Reply With Quote
Old Feb 23rd, 2008, 6:48 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 23rd, 2008, 1:06 PM   #4
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 94
Rep Power: 1 null_ptr0 is on a distinguished road
Re: [win32][gdi32] Copying HDC to another?

Quote:
Originally Posted by Ooble View Post
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.
null_ptr0 is offline   Reply With Quote
Old Feb 23rd, 2008, 1:25 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 23rd, 2008, 1:45 PM   #6
null_ptr0
12 years old
 
Join Date: Nov 2007
Posts: 94
Rep Power: 1 null_ptr0 is on a distinguished road
Re: [win32][gdi32] Copying HDC to another?

your link points to GetDC

edit:
how would i set the newly created HBITMAP's pixels?
null_ptr0 is offline   Reply With Quote
Old Feb 23rd, 2008, 2:08 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
more problems with copying from classes cwl157 Java 0 Sep 19th, 2007 4:17 PM
copying files rwm C++ 8 Apr 26th, 2007 2:39 AM
String to Morse Code - Copying from string to string Xenon C 29 Nov 10th, 2005 2:30 PM
Copying memory address values rsnd C++ 4 Jun 19th, 2005 7:41 AM
copying files first before deleting them harjit Visual Basic 1 May 15th, 2005 7:05 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:28 AM.

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