简体   繁体   中英

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

Here is the code:

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

I get the message from title, and when I switch wingdi.h and windows.h I get load of errors from wingdi.h file. I use codeblocks.

The documentation for GradientFill tells you, which header declares a symbol and which header to include:

Header: WinGdi.h (include Windows.h)

While GradientFill is declared in WinGdi.h you should #include <Windows.h> only.


Note: In case this doesn't solve your issues, you might want to consider picking another IDE. Code::Blocks is known to be brittle, with lots of issues, and a soft spot for wrong defaults (eg ANSI/Codepage character encoding vs. Unicode). Visual Studio Community 2015 is a full featured IDE that can be used free of charge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM