interchangeable functions

This is a discussion on interchangeable functions within the General Discussions forums, part of the Community Boards category; The GetStockObject function with an argument of DC_BRUSH or DC_PEN can be used interchangeably with the SetDCPenColor and SetDCBrushColor functions. ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    460

    interchangeable functions

    The GetStockObject function with an argument of DC_BRUSH or DC_PEN can be used interchangeably with the SetDCPenColor and SetDCBrushColor functions.

    That's from the reference at msdn.

    Does "interchangeably" mean they can be used in any order?

    I would guess that it doesn't mean you can use one in place of another.

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,667
    Quote Originally Posted by megafiddle View Post
    The GetStockObject function with an argument of DC_BRUSH or DC_PEN can be used interchangeably with the SetDCPenColor and SetDCBrushColor functions.

    That's from the reference at msdn.

    Does "interchangeably" mean they can be used in any order?

    I would guess that it doesn't mean you can use one in place of another.
    As in, GetStockObject(DC_BRUSH) and GetStockObject(DC_PEN) can be used for SetDCBrushColor() and SetDCPenColor(), respectively.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    460
    Are you saying that:

    SelectObject(hdc, GetStockObject(DC_PEN));

    is the same as:

    SelectObject(hdc, SetDCPenColor(colorval));

    ?

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,667
    Quote Originally Posted by megafiddle View Post
    Are you saying that:

    SelectObject(hdc, GetStockObject(DC_PEN));

    is the same as:

    SelectObject(hdc, SetDCPenColor(colorval));

    ?
    No.

    SetDCPenColor() is used to change the color of the pen on the specified DC.
    SelectObject() is used (you guessed it) to select objects to be used by the specified DC.
    More than one object can be selected at a time, but if you try to select an object of a conflicting type, the original will be removed.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    460
    Yes, I understand that.

    But, what is meant by interchangeable?

    And which of those four functions are interchangeable with which others?

    If it means that one object can be exchanged for another, that would make sense,
    but that's always true.

    And anyway, it said the functions were interchangeable, not the objects.
    Last edited by megafiddle; 08-22-2011 at 06:30 PM.

  6. #6
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,667
    Quote Originally Posted by megafiddle View Post
    Yes, I understand that.

    But, what is meant by interchangeable?

    And which of those four functions are interchangeable with which others?

    If it means that one object can be exchanged for another, that would make sense,
    but that's always true.

    And anyway, it said the functions were interchangeable, not the objects.
    It doesn't actually say the functions _or_ objects are interchangeable. The _use_ of DC_BRUSH and DC_PEN in GetStockObject is interchangeable with SetDCPenColor() and SetDCBrushColor() functions.
    For example, you can change the color of an object retrieved by GetStockObject(DC_BRUSH) with SetDCPenColor().

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    460
    That's true, it does say use of...

    However, you can select both a stock brush and a stock pen simultaneously.
    So which of those two would SetDCPenColor apply to, if it could apply to either?

  8. #8
    Registered User
    Join Date
    Mar 2011
    Posts
    460
    I appreciate the information and help. But I still can't make sense out of it.

    They do work as I would expect them to.

    SetDCPenColor and SetDCBrushColor each set the color of
    StockObject DC_PEN and StockObject DC_BRUSH respectively.

    I tried using SetDCPenColor to set the brush color and it had no effect.
    Same with using SetDCBrushColor to set the pen color, no effect.

  9. #9
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    MSDN isn't infallible and you've figured out what the functions do, accept that it's a particularly nonsense sentence and move on. It's not something to be spending 10 minutes figuring out, much less a day.

  10. #10
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,565
    The SetDCBrushColor and SetDCPenColor pages link to this example, showing how you can use them interchangeably. That is, calling
    Code:
    SelectObject(hdc, GetStockObject(BLACK_PEN));
    is equivalent to
    Code:
    SetDCPenColor(hdc, RGB(0,0,0));

  11. #11
    Registered User
    Join Date
    Mar 2011
    Posts
    460
    Quote Originally Posted by anduril462 View Post
    The SetDCBrushColor and SetDCPenColor pages link to this example, showing how you can use them interchangeably. That is, calling
    Code:
    SelectObject(hdc, GetStockObject(BLACK_PEN));
    is equivalent to
    Code:
    SetDCPenColor(hdc, RGB(0,0,0));
    Yes, I saw that.

    But
    Code:
    SelectObject(hdc, GetStockObject(BLACK_PEN));
    and
    Code:
    SetDCPenColor(hdc, RGB(0,0,0));
    are not equivalent.

    SetDCPenColor(hdc, RGB(0,0,0) only sets the color of the DC_PEN.

    The DC_PEN still had to be selected before it could be used.

    It's true that a DC_PEN with color set to black can be used instead of a BLACK_PEN with same
    results, but that's not what the description in question was saying. Everything was related to
    DC_PEN and DC_BRUSH.

  12. #12
    Registered User
    Join Date
    Mar 2011
    Posts
    460
    Quote Originally Posted by adeyblue View Post
    MSDN isn't infallible and you've figured out what the functions do, accept that it's a particularly nonsense sentence and move on. It's not something to be spending 10 minutes figuring out, much less a day.
    So it is nonsense, then.
    At least I know it wasn't just me.
    Thanks.

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by megafiddle View Post
    So it is nonsense, then.
    At least I know it wasn't just me.
    Thanks.
    As in ... "One sure way to waste a ton of time is to get lost in the minutia"... If it works, use it...

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    This is functionality left over from pre .NET version IDEs (ie MSVC v6), where GDI objects were not cleaned up by the garbage collection system (not all GDIs were marked as 'default' and there was no garbage collection).

    It is less important now as most .NET IDEs hold your hand and nag you about every little thing. Also basic GDI object functionality was changed to make GDI drawing easy.

    Stock GDI objects do not leak GDI memory if they are not removed from the DC before the DC is deleted and the stock GDI object does not explicitly require clean up with DeleteObject().

    The SetDCXXXColor() allows you to change the colour of a pen/brush without creating a new GDI object, selecting it into the DC (catching the return) and after use returning the default GDI object followed by deleting the created GDIs.

    So the functions are interchangeable because they allow modification of GDI objects without resorting to the 'normal' procedure (of allocating GDI memory, using it, removing it and freeing it).
    "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. Creating Functions & passing information to other functions
    By RyanLeonard in forum C Programming
    Replies: 4
    Last Post: 10-28-2010, 12:17 PM
  2. Functions calling other functions.
    By kbro3 in forum C++ Programming
    Replies: 2
    Last Post: 12-26-2009, 11:10 PM
  3. Replies: 7
    Last Post: 04-19-2006, 11:17 AM
  4. Replies: 6
    Last Post: 05-06-2003, 03:08 PM
  5. Replies: 1
    Last Post: 01-20-2002, 10:50 AM

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