CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2009
    Posts
    5

    Hide a console window in VC++

    I am using visual studio 6 to develop a VC++ application (Console based non MFC) to trigger an event. But when I run it, a black console window just flashes & goes off. However it successfully triggers the event. But, I want it to be hidden. I searched & found the following code to hide it but it returns errors. Here is the code

    // Test_console.cpp : Defines the entry point for the console application.


    #pragma comment(linker, "/SUBSYSTEM:WINDOWS")

    #define _WIN32_WINNT 0x0500


    #include <windows.h>
    #include <WinCon.h>
    #include "stdafx.h"
    #include <iostream>


    int main(int argc, char* argv[])
    {

    HWND hWnd = GetConsoleWindow();
    ShowWindow( hWnd, SW_HIDE );

    return 0;
    }


    The errors are as follows:

    error C2065: 'HWND' : undeclared identifier
    error C2146: syntax error : missing ';' before identifier 'hWnd'
    error C2065: 'hWnd' : undeclared identifier
    error C2065: 'GetConsoleWindow' : undeclared identifier
    error C2065: 'ShowWindow' : undeclared identifier
    error C2065: 'SW_HIDE' : undeclared identifier

    Can anybody please help me.

  2. #2
    Join Date
    May 2002
    Posts
    1,435

    Re: Hide a console window in VC++

    I don't know much about console programming, but wouldn't the code you show still flash since you are hiding it after it has been created?

    Why not a Windows program with no windows?:
    Code:
    #include <windows.h>
    
    int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	::MessageBox(0, "\"No-Window\" Windows Program", "NoWin", MB_OK);
    	return 0;
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured