Results 1 to 15 of 15

Thread: Dc Q!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636

    Question Dc Q!

    Hi, Guys.

    I have a question about DCs (Longs).
    When I want to copy a DC into another DC and I do it like this:
    VB Code:
    1. FirstDC = SecondDC
    So when I change the FirstDC the SecondDC changes too, and that's not what I wanted. I want to copy it.
    Is there an API for this? or just a simple code?

    Help please,
    Arie.

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Try FirstDC = VarPtr(SecondDC). I dunno, sounds scary having Pointers in action in VB!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You cannot duplicate a dc. But you can use the SaveDC API to save the state of a device context, then restore it.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Sastraxi's code will most likely lead to an access violation.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Use CreateDC to create a new DC, then BitBlt to copy the first onto the second. Do it all the time. Put the code into a function called CopyDC, put it into a module, and away you go.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But that's something different. What he wants is a copy of a screen dc so he can use two sets of settings (at least that's how I understand it), which you cannot. You can save a set of settings and later load it using SaveDC and RestoreDC.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Originally posted by CornedBee
    But that's something different. What he wants is a copy of a screen dc so he can use two sets of settings (at least that's how I understand it), which you cannot. You can save a set of settings and later load it using SaveDC and RestoreDC.


    OK THIS is what he asked for:

    So when I change the FirstDC the SecondDC changes too, and that's not what I wanted. I want to copy it.

    He didn't ask for anything about copying DC settings; just contents...
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    This is all too freaky for me... I'm outta here!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    So when I change the FirstDC the SecondDC changes too, and that's not what I wanted. I want to copy it.
    Does he mean the settings of SecondDC change too, or the content (what is displayed) change too?
    Because you still cannot copy a DC. The return of CreateCompatibleDC will not draw to the screen, but to a memory location.

    He didn't ask for anything about copying DC settings; just contents...
    He asked for copying the DC, which is not possible. And maybe he doesn't know it, but to windows a DC is only a bunch of settings and a reference to a device, which stores the actual data (the device might be the screen or a printer or memory location or a DirectDraw surface, but the DC stores no data).

    Arie, we need clarification.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    *sigh*

    A Device Context stores a pointer to what roughly translates as image data. By using CreateCompatibleDC you can create a NEW DC that points to blank memory that is compatible with the screen DC. Then you copy the screen DC's image (i.e. contents) using BitBlt to the memory DC, and when you are done you copy them back and use DeleteObject on the memory DC.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, I know, but if you're a tech freak like I am the question means what I said.

    Where's Arie anyway?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Wouldn't it be ironic if he solved his problem on his own and just left
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Originally posted by CornedBee
    Yeah, I know, but if you're a tech freak like I am the question means what I said.

    Where's Arie anyway?

    I've talked to dozens of other coders about DCs using the term "copy" to mean Blt'ing the contents. I've never heard anyone use the term like you do
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    Hey guys, relax.
    I wasn't here a few days.

    In the meanwhile I figured that what I need is to BitBlt from FirstDC into SecondDC. I needed only the image in it, nothing else.

    I'll adapt the way that mlewis suggested.

    Thank you all for helping,
    Arie.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok, ok, I'm shutting up. I surely wouldn't use it that way, but it's now clear.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width