f



Problem getting console window handle

Need to get the window handle for a Win32 console app. According to a few 
websites, the following should work:

#include <windows.h>

HWND  hConsole    ;

int main()
{
 hConsole = GetConsoleWindow()    ;
........
}

But the compile reports an error:
error C2065: 'GetConsoleWindow' : undeclared identifier

The project link settings do include kernel32.lib, as instructed.

Any assistance much appreciated. 


0
Bruce
4/21/2013 7:21:02 AM
comp.os.programmer.win32 14522 articles. 0 followers. Post Follow

2 Replies
667 Views

Similar Articles

[PageSpeed] 16

>But the compile reports an error:
>error C2065: 'GetConsoleWindow' : undeclared identifier

Check the remarks section of the documentation:
http://msdn.microsoft.com/en-gb/library/windows/desktop/ms683175(v=vs.85).aspx

You will of course need to be using tools that post-date Windows 2000
to have the header definition & lib.

Dave
0
David
4/21/2013 8:39:52 AM
On Sun, 21 Apr 2013 15:21:02 +0800, "Bruce Varley" <bv@NoSpam.com>
wrote:

>Need to get the window handle for a Win32 console app. According to a few 
>websites, the following should work:
>
>#include <windows.h>
>
>HWND  hConsole    ;
>
>int main()
>{
> hConsole = GetConsoleWindow()    ;
>.......
>}
>
>But the compile reports an error:
>error C2065: 'GetConsoleWindow' : undeclared identifier
>
>The project link settings do include kernel32.lib, as instructed.
>
>Any assistance much appreciated. 
>

This is a compiler error, not a linker error, so don't fret about the
libs just yet, you haven't gotten that far.

You can use the Visual Studio IDE to jump to the definition of these
constants or you can add this to your source to verify David's
suggestion:

#ifndef  _WIN32_WINNT
#error  _WIN32_WINNT not defined
#endif

#ifndef  _WIN32
#error  _WIN32 not defined
#endif

#ifndef  _CONSOLE
#error  _CONSOLE not defined
#endif

These will stop compiliation if your project is incorrectly targeted.
0
Geoff
4/21/2013 4:40:32 PM
Reply: