"GradientFill was not declared in this scope" 包含 windows.h 和 wingdi.h 时出错
"GradientFill was not declared in this scope" error when including windows.h and wingdi.h
代码如下:
#include <windows.h>
#include <wingdi.h>
#include <tchar.h>
#include <string>
#include <iostream>
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) //handling the message; all cases should be in logical order
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
GRADIENT_RECT rc;
TRIVERTEX vertex[2] ;
//vertex settings...
hdc = BeginPaint(hwnd, &ps);
GradientFill(hdc, vertex, 2, &rc, 1, GRADIENT_FILL_RECT_V);
EndPaint(hwnd, &ps);
break;
}
}
}
我从标题中得到消息,当我切换 wingdi.h 和 windows.h 时,我从 wingdi.h 文件中得到大量错误。
我使用代码块。
GradientFill 的文档告诉您,哪个 header 声明了一个符号,哪个 header 包含:
Header: WinGdi.h (include Windows.h)
虽然 GradientFill
在 WinGdi.h 中声明,但您应该只 #include <Windows.h>
。
注意:如果这不能解决您的问题,您可能需要考虑选择另一个 IDE。 Code::Blocks 众所周知是脆弱的,有很多问题,并且对错误的默认值情有独钟(例如 ANSI/Codepage 字符编码与 Unicode)。 Visual Studio Community 2015 是功能齐全的 IDE,可以免费使用。
代码如下:
#include <windows.h>
#include <wingdi.h>
#include <tchar.h>
#include <string>
#include <iostream>
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) //handling the message; all cases should be in logical order
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
GRADIENT_RECT rc;
TRIVERTEX vertex[2] ;
//vertex settings...
hdc = BeginPaint(hwnd, &ps);
GradientFill(hdc, vertex, 2, &rc, 1, GRADIENT_FILL_RECT_V);
EndPaint(hwnd, &ps);
break;
}
}
}
我从标题中得到消息,当我切换 wingdi.h 和 windows.h 时,我从 wingdi.h 文件中得到大量错误。 我使用代码块。
GradientFill 的文档告诉您,哪个 header 声明了一个符号,哪个 header 包含:
Header: WinGdi.h (include Windows.h)
虽然 GradientFill
在 WinGdi.h 中声明,但您应该只 #include <Windows.h>
。
注意:如果这不能解决您的问题,您可能需要考虑选择另一个 IDE。 Code::Blocks 众所周知是脆弱的,有很多问题,并且对错误的默认值情有独钟(例如 ANSI/Codepage 字符编码与 Unicode)。 Visual Studio Community 2015 是功能齐全的 IDE,可以免费使用。