包含 Windows.h 和 wingdi.h 时出现"GradientFill was not declared in this scope"错误

"GradientFill was not declared in this scope" error when including windows.h and wingdi.h

本文关键字:declared not in this 错误 scope was GradientFill wingdi 包含 Windows      更新时间:2023-10-16

以下是代码:

#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;
        }
    }
}

我从title中得到消息,当我切换wingdi.h和windows.h时,我会从wingdi.h文件中得到大量错误。我使用代码块。

GradientFill的文档告诉您,哪个头声明了一个符号,哪个头要包括:

标题:WinGdi.h(包括Windows.h)

GradientFillWinGdi.h中声明时,您应该只声明#include <Windows.h>


注意:如果这不能解决您的问题,您可能需要考虑选择另一个IDE。Code::众所周知,块是脆弱的,有很多问题,并且是错误默认值的弱点(例如ANSI/Codepage字符编码与Unicode)。Visual Studio Community 2015是一个功能齐全的IDE,可以免费使用。