Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'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. ^^

like image 915
Kevin Dong Avatar asked Nov 16 '13 10:11

Kevin Dong


3 Answers

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.

like image 161
Evgeny Timoshenko Avatar answered Sep 24 '22 15:09

Evgeny Timoshenko


The documentation says:

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

I suspect that you did not do that.

You need to define the conditional before you include windows.h. Note that version 0x0500 corresponds to Windows 2000 so in the unlikely event that you want to support Windows NT4 or earlier, or Windows 9x, you'll need to switch to using run-time linking instead.

like image 39
David Heffernan Avatar answered Sep 22 '22 15:09

David Heffernan


Or, if you get errors saying that it is redefined, you can use this :

#if       _WIN32_WINNT < 0x0500
  #undef  _WIN32_WINNT
  #define _WIN32_WINNT   0x0500
#endif
#include <windows.h> 
like image 37
Samuel Avatar answered Sep 25 '22 15:09

Samuel