18

I've been looking around but I couldn't find the solution to my problem, even with some supposedly solved problems that resemble mine.

I want to hide the console window when my C program runs.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define _WIN32_WINNT 0x0500

int main(){   
    HWND hWnd = GetConsoleWindow();
    ShowWindow( hWnd, SW_MINIMIZE );  //won't hide the window without SW_MINIMIZE
    ShowWindow( hWnd, SW_HIDE );
}

This is what I tried but the compiler gives me

initialization makes pointer from integer without a cast

and the fatal one which actually stops the compiling:

undefined reference to 'GetConsoleWindow'

PS: I've checked wincon.h and the GetConsoleWindow() function is defined.

3
  • This could help you: How to hide Console Window with WinAPI? Commented Aug 4, 2012 at 21:43
  • Ken, I am using C not C++ and that thread solves a different problem, not this one. I already tried it out. Commented Aug 4, 2012 at 21:53
  • @Steve314, you're right. Going back and reading in more depth, it isn't. Removing my comment - can't undo the close vote, but don't want to direct others the wrong way. Thanks for the correction. :-) y Orionis, my apologies. Commented Aug 4, 2012 at 22:00

2 Answers 2

17

Your

#define _WIN32_WINNT 0x0500

(which is needed to use GetConsoleWindow - see the documentation) must be before

#include <windows.h>

That #define is used by windows.h to know which version of Windows you are targeting (and thus which declarations it has to provide/which additional fields it has to add to structures/other magic that may be related to that linker error); if you define it after you include windows.h it will be useless.

Sign up to request clarification or add additional context in comments.

Comments

0

if you want to remove it, even without windows.h, you can SIMPLY just add -mwindows to your compiler flags (gcc), so
gcc examplefile.c -mwindows -o example.exe

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.