« Windows Live and Bad Behaviour plugin incompatiblity | Home | How to take out the system built-in beeper in Linux »
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 | 25 Comments »
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?
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.
March 21st, 2010 at 08:28
Ok thanks. With the windows subsytem all works well. Cheers
March 21st, 2010 at 08:46
Do you have any experiance using a glade comstructed GUI with visual studio?
July 9th, 2012 at 01:03
Kudos!
This is exactly what I was looking for and works perfectly for me, thank you very much.
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
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/ […]
January 14th, 2023 at 13:43
… [Trackback]
[…] Read More on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
January 24th, 2023 at 05:24
… [Trackback]
[…] Read More Info here on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
February 27th, 2023 at 04:18
… [Trackback]
[…] Read More on on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
March 16th, 2023 at 10:58
… [Trackback]
[…] Info to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
March 16th, 2023 at 21:08
… [Trackback]
[…] Read More Info here to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
March 21st, 2023 at 03:50
… [Trackback]
[…] Read More to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]