I'm writing a Win32 application for Windows XP with Visual Studio 2005. It is a console program, and I'm trying to find the HWND attribute of my console. I need this because I need to use it as a parameter for a function.


So, thanks to the MSDN library I found this:

HWND WINAPI GetConsoleWindow(void);

It sounds really simple, but when I try to compile it says GetConsoleWindow is not identified. I looked through wincon.h, where it IS defined, but it is outlined like so:

#if(_WIN32_WINNT >= 0x0500)

WINBASEAPI
HWND
APIENTRY
GetConsoleWindow(
    VOID
    );

#endif

And, like it told me to, I put this in my code:

#define _WIN32_WINNT 0x0501  // Windows XP = 0501H

I thought that would fix the problem, but it still says identifier not found for GetConsoleWindow(). Does anyone have any ideas?

Try to compile this snippet and tell me if you have any problems. If that works, you could modify it to suit you. The #define switch should be used as it is.

And, like it told me to, I put this in my code:

#define _WIN32_WINNT 0x0501  // Windows XP = 0501H

I thought that would fix the problem, but it still says identifier not found for GetConsoleWindow(). Does anyone have any ideas?

Did you put that macro definition before the header which uses the conditional compilation?

Mr. Sinkula:

Actually, I put the #define after the include statements. I moved it to before the includes, and it worked! I guess I thought that it would be better after the includes, that way it would overwrite any #defines that are done in the header.

It does make sense though that if I don't define it before the include, then the header can't check the IF statement.

Wolfpack:

I did compile that code, and it did work.

Thank you both for your time.

I'm writing a Win32 application for Windows XP with Visual Studio 2005. It is a console program, and I'm trying to find the HWND attribute of my console. I need this because I need to use it as a parameter for a function.


So, thanks to the MSDN library I found this:

HWND WINAPI GetConsoleWindow(void);

It sounds really simple, but when I try to compile it says GetConsoleWindow is not identified. I looked through wincon.h, where it IS defined, but it is outlined like so:

#if(_WIN32_WINNT >= 0x0500)

WINBASEAPI
HWND
APIENTRY
GetConsoleWindow(
    VOID
    );

#endif

And, like it told me to, I put this in my code:

#define _WIN32_WINNT 0x0501  // Windows XP = 0501H

I thought that would fix the problem, but it still says identifier not found for GetConsoleWindow(). Does anyone have any ideas?

Hope this compiled code will help u a bit.

To use the features specifically marked for Windows 2000 in the header files, you need to explicitly define _WIN32_WINNT as 0x0500 or greater. You can define the symbols using the #define statement in each source file, or by specifying the /D_WIN32_WINNT=0x0500 compiler option supported by Visual C++.

Visual C++ 6.0: To specify compiler options, go to the Projects menu and click Settings, then select the C/C++ tab.
Visual C++ 7.0: To specify compiler options, go to the Projects menu and click Properties.

This is taken from MSDN

to wolfpack : ur code ran well in Microsoft Visual 2005 but I got 2 errors when I try it in Microsoft Visual 6.0 >...<"
-error C2065: 'GetConsoleWindow' : undeclared identifier
-error C2440: 'initializing' : cannot convert from 'int' to 'struct HWND__ *'
Plz help me...I use Win XP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.