Solved

GetStockObject

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

  hdc = GetDC(hwnd);
  SelectObject(hdc,GetStockObject(DC_PEN));
  SetDCPenColor(hdc,RGB(00,0xff,00));
  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.
 
0
Question by:yc_yc
    5 Comments
     
    LVL 48

    Accepted Solution

    by:
    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:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp

    Put this constant to the beginning of stdafx.h.
    0
     

    Author Comment

    by:yc_yc
    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.


    0
     
    LVL 48

    Expert Comment

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

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

    WIN32_WINNT=0x500
    0
     
    LVL 48

    Expert Comment

    by:AlexFM
    Correction:

    _WIN32_WINNT=0x500
    0
     

    Author Comment

    by:yc_yc
    Many thanks.
    0

    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 (http://www.experts-exchange.com/A_2172.html), 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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
    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