Posted on 2004-10-30
Last Modified: 2013-12-03
I am learning programming windows.
See below piece of code:

  hdc = GetDC(hwnd);
  ReleaseDC(hwnd, hdc);

Compiling error:
error C2065: 'DC_PEN' : undeclared identifier
error C2065: 'SetDCPenColor' : undeclared identifier

The type of stock object can be the value DC_PEN in the GetStockObject function .
what is wrong here? How should I change a pen color? Thanks.
Question by:yc_yc
    LVL 48

    Accepted Solution

    Both DC_PEN and SetDCPenColor are available in Windows 2000 or later. To compile this code you need to define constant:

    #define _WIN32_WINNT 0x0500

    before including windows.h, as described in this article:

    Put this constant to the beginning of stdafx.h.

    Author Comment

    In the article, it mentions another way is:

    Visual C++ 6.0:  To specify compiler options, go to the Projects menu and click Settings, then select the C/C++ tab. By specifying the /D compiler option supported by Visual C++.

    I tried it too. In Project settings, Select the C/C++ tab , in Project Options text box typing /D "_WIN32_WINNT 0x0500".  But it didn't work, the compiling error still exists.

    Did I use the correct /D compiler option (put /D "_WIN32_WINNT 0x0500" in Project Options)? Thanks.

    LVL 48

    Expert Comment

    /D _WIN32_WINNT=0x500    (if you add this manually to cl commang line).

    Project - Settings - C/C++ - Preprocessor definitions. Add:

    LVL 48

    Expert Comment



    Author Comment

    Many thanks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
    This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (, we saw how to put the Delete button back there where it belongs.  "Delete" is …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now