« 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 | 11 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.
November 10th, 2024 at 18:53
… [Trackback]
[…] Here you can find 17560 more Information on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
November 12th, 2024 at 14:40
… [Trackback]
[…] Here you can find 36839 additional Information on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
November 16th, 2024 at 05:24
… [Trackback]
[…] Find More here to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
November 17th, 2024 at 14:11
… [Trackback]
[…] Find More on to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
December 1st, 2024 at 18:36
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]
December 11th, 2024 at 19:34
… [Trackback]
[…] Find More on that Topic: compdigitec.com/labs/2009/12/06/console-free-gtkmm-applications-in-visual-studio-2008/ […]