how CDC::FromHandle get the returns value

This is a discussion on how CDC::FromHandle get the returns value within the Windows Programming forums, part of the Platform Specific Boards category; CDC::FromHandle is static and it accepts HDC as an imput. It only means MFC has a global array that consists ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    how CDC::FromHandle get the returns value

    CDC::FromHandle is static and it accepts HDC as an imput. It only means MFC has a global array that consists some HDC, so it can returns the CDC*, and if it is not found, according to MS, it will create a temporary CDC and attach to it.
    does anyone know when the array been created ? Or does CDC::FromHandle search all CWnd object (enum from the parent of caller) and try to find the matching HDC?

    thx

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    There's a free trial of VS2008 Pro available, which comes with the MFC source code. Have a look and you can see how it does it.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,853
    Quote Originally Posted by binyo66 View Post
    CDC::FromHandle is static and it accepts HDC as an imput. It only means MFC has a global array that consists some HDC, so it can returns the CDC*, and if it is not found, according to MS, it will create a temporary CDC and attach to it.
    does anyone know when the array been created ? Or does CDC::FromHandle search all CWnd object (enum from the parent of caller) and try to find the matching HDC?

    thx
    IIRC

    MFC uses maps of CObject.

    FromHandle(HDC ) searches all current objects in the map for a matching HDC value.

    If none is found a CDC object is created, init using the HDC and added to the map.

    How your WIN32 wrapper replicates this functionality can only be answered after reading the design docs (and functional specs).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 02:27 AM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  3. Function returns null value instead of zero
    By drdepoy in forum C Programming
    Replies: 3
    Last Post: 10-23-2005, 03:51 PM
  4. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21