Search code examples
c++windowswinapiwindows-console

'GetConsoleWindow' was not declared in this scope?


#include<windows.h> have already added, so why the GCC-mingw32 Compiler reported that 'GetConsoleWindow' was not declared in this scope ?

Here's my code:

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

Thanks. ^^


Solution

  • From msdn:

    To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later.

    So you can try to replace

    #include<windows.h>
    

    with

    #define _WIN32_WINNT 0x0500
    #include<windows.h>
    

    Or include SDKDDKVer.h from Windows SDK:

    Including SDKDDKVer.h defines the highest available Windows platform.