Compdigitec Labs

« | Home | »

Console-free gtkmm applications in Visual Studio 2008

By admin | December 6, 2009

When compiling Gtkmm programs on Microsoft Windows using Visual C++, a black console box pops up when you run the program. However, setting the application subsystem to Windows will cause the program to complain about WinMain and other problems. Here is a versatile solution from the Gtkmm mailing list to get Gtkmm to work on Windows transparently without breaking interoperability with other platforms, such as Linux, though some modifications were required to make it work.

Insert the following code before your main() and after your header #includes:

#ifdef WIN32
	#include <windows.h>
#endif

using namespace std;
using namespace Gtk;

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

#ifdef WIN32

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	// check windows version
         DWORD dwVersion = GetVersion();

         if (!(dwVersion < 0x80000000))
         {
                 MessageBox(0, _T("This application requires Windows 2000/XP or above!"), _T("Fatal Error"), MB_OK);
                 return -1;
         }

         return main(__argc, __argv);
}

#endif

Here is a sample Gtkmm application without console boxes on Windows:

#include <gtkmm.h>
#include <iostream>
#ifdef WIN32
	#include <windows.h>
#endif

using namespace std;
using namespace Gtk;

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

#ifdef WIN32

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	// check windows version
         DWORD dwVersion = GetVersion();

         if (!(dwVersion < 0x80000000))
         {
                 MessageBox(0, _T("This application requires Windows 2000/XP or above!"), _T("Fatal Error"), MB_OK);
                 return -1;
         }

         return main(__argc, __argv);
}

#endif

int main(int argc, char* argv[])
{
	Gtk::Main kit(argc, argv);
	Gtk::Window window;
	Gtk::Main::run(window);

	return 0;
}

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Windows | 19 Comments »

19 Responses to “Console-free gtkmm applications in Visual Studio 2008”

  1. Rory Says:
    March 20th, 2010 at 11:39

    I am still getting a console window displayed even in the example.

    Visual studio is forcing me to use #include “stdafx.h”. Could this be the differance?

  2. admin Says:
    March 20th, 2010 at 18:18

    @Rory:

    It doesn’t hurt to try commenting out the #include statement. Also, be sure you have selected the Windows subsystem, and not the Console subsystem.

  3. Rory Says:
    March 21st, 2010 at 08:28

    Ok thanks. With the windows subsytem all works well. Cheers

  4. Rory Says:
    March 21st, 2010 at 08:46

    Do you have any experiance using a glade comstructed GUI with visual studio?

  5. PK Says:
    July 9th, 2012 at 01:03

    Kudos!

    This is exactly what I was looking for and works perfectly for me, thank you very much.

  6. Esport Says:
    February 18th, 2022 at 22:28

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  7. trực tiếp bóng đá Says:
    March 21st, 2022 at 08:20

    … [Trackback]

    […] Read More here to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  8. slot999 Says:
    April 13th, 2022 at 05:32

    … [Trackback]

    […] Find More Information here on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  9. สล็อตวอเลท Says:
    April 19th, 2022 at 12:33

    … [Trackback]

    […] Find More here on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  10. good dumps clubs Says:
    April 22nd, 2022 at 08:57

    … [Trackback]

    […] Read More Information here on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  11. betflix68 Says:
    April 25th, 2022 at 19:17

    … [Trackback]

    […] Read More here on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  12. buy mastercard gift card with Bitcoin btc anonymous 11 Says:
    May 31st, 2022 at 17:41

    … [Trackback]

    […] Find More here to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  13. pagina oficial do happymod para computador Says:
    July 15th, 2022 at 17:26

    … [Trackback]

    […] Read More here to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  14. www.spellcasting.biz/category/daily-blessings/ Says:
    August 21st, 2022 at 10:39

    … [Trackback]

    […] Read More on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  15. daily microdosing psilocybin mushrooms​ Says:
    August 29th, 2022 at 02:06

    … [Trackback]

    […] Info on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  16. buy fn american Says:
    September 9th, 2022 at 15:45

    … [Trackback]

    […] There you will find 64108 additional Info on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  17. anchor Says:
    October 7th, 2022 at 20:47

    … [Trackback]

    […] Here you can find 25924 more Info on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  18. sbobet Says:
    October 15th, 2022 at 01:47

    … [Trackback]

    […] Read More here to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

  19. เงินด่วนออนไลน์โอนเข้าบัญชี Says:
    October 27th, 2022 at 16:29

    … [Trackback]

    […] Read More on on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]

Comments