SetDCPenColor() undifined

This is a discussion on SetDCPenColor() undifined within the Windows Programming forums, part of the Platform Specific Boards category; Is this one of the latest from API, even Charles Petzold book doesn't have on index.. Trying to change the ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    SetDCPenColor() undefined

    Is this one of the latest from API, even Charles Petzold book doesn't have on index.. Trying to change the color of the pen... Also this..
    Code:
    hPen = (HPEN)GetStockObject(DC_PEN);
    states that DC_PEN is undefined

    /Yes, i do have windows.h included and have been using pens and brushes for sometime with no prob, first time trying to change pen color!
    Last edited by csonx_p; 06-13-2008 at 07:29 AM.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    check your stdafx.h for the value of _WIN32_WINNT.
    if its set to 0x0400, and you are using w2k or higher,
    change it to 0x0500 and see waht happens.

    Some Functions in GDI32 such as
    SetDCPenColor and SetDCBrushColor are only defined for
    _WIN32_WINNT >= 0x0500
    I program i C, so do not use stdafx.h... I've disabled pre-compiled headers...

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    any1 subscribed to the following website, apparently you have to pay to be a member.. Not in good financial terms now but maybe my answer is on this link!

    http://www.experts-exchange.com/Prog..._21188603.html

    If so, please quote the answers to here. I know i'm asking for too much but am kindly doing so... Need help where possible.. Oh! the free trial still needs me to pay.

    Thanx

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Put this before you #include <Windows.h>:

    Code:
    #define _WIN32_WINNT 0x0500

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by MacGyver View Post
    Put this before you #include <Windows.h>:

    Code:
    #define _WIN32_WINNT 0x0500
    works, THANX... Didn't know you still exist, will use you on other things

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by csonx_p View Post
    works, THANX... Didn't know you still exist, will use you on other things
    I get no link errors or warnings anymore, but then the color is not changed, always defaults to black... Is there any other form one can change line color when drawing? Here's my code

    Code:
    	// Select the new pen and its color.
    	// Draw the arc using API arc function
    	hPen = (HPEN)GetStockObject(BLACK_PEN);
    	hOldPen=(HPEN)SelectObject(hdc, hPen);
    	SetDCPenColor(hdc,RGB(R,G,B));
    	Arc( hdc, left, top, right, bottom, xstart, ystart, xend, yend 	);
    	SelectObject(hdc, hOldPen);

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    I am not sure you can modify a Stock GDI object. YOu would change the default Pen, not select in a Stock Pen and then change the colour.

    I use CreatePen() as it give me more control.


    Code:
    hPen=(HPEN)CreatePen(PS_SOLID,1,RGB(R,G,B));//solid pen one px wide
    
    hOrigPen=SelectObject(hDC,hPen);
    
    //draw
    
    SelectObject(hDC,hOrigPen);
    DeleteObject(hPen);
    Last edited by novacain; 06-18-2008 at 11:49 PM. Reason: clarity
    "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

  9. #9
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by novacain View Post
    I am not sure you can modify a Stock GDI object. YOu would change the default Pen, not select in a Stock Pen and then change the colour.

    I use CreatePen() as it give me more control.


    Code:
    hPen=(HPEN)CreatePen(PS_SOLID,1,RGB(R,G,B));//solid pen one px wide
    
    hOrigPen=SelectObject(hDC,hPen);
    
    //draw
    
    SelectObject(hDC,hOrigPen);
    DeleteObject(hPen);
    Yes this is what i've opted for...works

Popular pages Recent additions subscribe to a feed

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