'GetConsoleWindow'未在此范围内声明?

Kev*_*ong 5 c++ windows winapi windows-console

#include<windows.h>已经添加了,为什么GCC-mingw32编译器报告了'GetConsoleWindow' was not declared in this scope

这是我的代码:

#include<iostream>
#include<cmath>
#include<windows.h>

using namespace std;

#define PI 3.14

int main() 
{
    //Get a console handle
    HWND myconsole = GetConsoleWindow();
    //Get a handle to device context
    HDC mydc = GetDC(myconsole);

    int pixel =0;

    //Choose any color
    COLORREF COLOR= RGB(255,255,255); 

    //Draw pixels
    for(double i = 0; i < PI * 4; i += 0.05)
    {
        SetPixel(mydc,pixel,(int)(50+25*cos(i)),COLOR);
        pixel+=1;
    }

    ReleaseDC(myconsole, mydc);
    cin.ignore();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

谢谢.^^

Evg*_*nko 8

来自msdn:

要编译使用此函数的应用程序,请将_WIN32_WINNT定义为0x0500或更高版本.

所以你可以尝试更换

#include<windows.h>
Run Code Online (Sandbox Code Playgroud)

#define _WIN32_WINNT 0x0500
#include<windows.h>
Run Code Online (Sandbox Code Playgroud)

或者SDKDDKVer.h从Windows SDK中包含:

包括SDKDDKVer.h定义了最高可用的Windows平台.


Dav*_*nan 6

文件说:

要编译使用此函数的应用程序,请将_WIN32_WINNT定义为0x0500或更高版本.

我怀疑你没有这样做.

在包含windows.h之前,需要定义条件.请注意,版本0x0500对应于Windows 2000,因此,如果您想要支持Windows NT4或更早版本或Windows 9x,则需要切换到使用运行时链接.