GetStockObject

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.
 
yc_ycAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AlexFMConnect With a Mentor Commented:
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
 
yc_ycAuthor Commented:
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
 
AlexFMCommented:
/D _WIN32_WINNT=0x500    (if you add this manually to cl commang line).

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

WIN32_WINNT=0x500
0
 
AlexFMCommented:
Correction:

_WIN32_WINNT=0x500
0
 
yc_ycAuthor Commented:
Many thanks.
0
All Courses

From novice to tech pro — start learning today.