{"id":144,"date":"2009-12-06T16:39:32","date_gmt":"2009-12-06T20:39:32","guid":{"rendered":"http:\/\/www.compdigitec.com\/labs\/?p=144"},"modified":"2012-07-11T13:49:35","modified_gmt":"2012-07-11T18:49:35","slug":"console-free-gtkmm-applications-in-visual-studio-2008","status":"publish","type":"post","link":"http:\/\/www.compdigitec.com\/labs\/2009\/12\/06\/console-free-gtkmm-applications-in-visual-studio-2008\/","title":{"rendered":"Console-free gtkmm applications in Visual Studio 2008"},"content":{"rendered":"<p>When compiling <a href=\"http:\/\/www.gtkmm.org\/\">Gtkmm<\/a> 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 <a href=\"http:\/\/old.nabble.com\/how-to-prevent-the-console-window-poping-out-when-running-gtkmm-app--in-windows-vista--td23334287.html\">versatile solution from the Gtkmm mailing list<\/a> 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.<\/p>\n<p>Insert the following code before your <em>main()<\/em> and after your header <em>#include<\/em>s:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#ifdef WIN32\r\n\t#include &lt;windows.h&gt;\r\n#endif\r\n\r\nusing namespace std;\r\nusing namespace Gtk;\r\n\r\nint main(int argc, char* argv[]);\r\n\r\n#ifdef WIN32\r\n\r\nint APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)\r\n{\r\n\t\/\/ check windows version\r\n         DWORD dwVersion = GetVersion();\r\n\r\n         if (!(dwVersion &lt; 0x80000000))\r\n         {\r\n                 MessageBox(0, _T(&quot;This application requires Windows 2000\/XP or above!&quot;), _T(&quot;Fatal Error&quot;), MB_OK);\r\n                 return -1;\r\n         }\r\n\r\n         return main(__argc, __argv);\r\n}\r\n\r\n#endif\r\n<\/pre>\n<p>Here is a sample Gtkmm application without console boxes on Windows:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;gtkmm.h&gt;\r\n#include &lt;iostream&gt;\r\n#ifdef WIN32\r\n\t#include &lt;windows.h&gt;\r\n#endif\r\n\r\nusing namespace std;\r\nusing namespace Gtk;\r\n\r\nint main(int argc, char* argv[]);\r\n\r\n#ifdef WIN32\r\n\r\nint APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)\r\n{\r\n\t\/\/ check windows version\r\n         DWORD dwVersion = GetVersion();\r\n\r\n         if (!(dwVersion &lt; 0x80000000))\r\n         {\r\n                 MessageBox(0, _T(&quot;This application requires Windows 2000\/XP or above!&quot;), _T(&quot;Fatal Error&quot;), MB_OK);\r\n                 return -1;\r\n         }\r\n\r\n         return main(__argc, __argv);\r\n}\r\n\r\n#endif\r\n\r\nint main(int argc, char* argv[])\r\n{\r\n\tGtk::Main kit(argc, argv);\r\n\tGtk::Window window;\r\n\tGtk::Main::run(window);\r\n\r\n\treturn 0;\r\n}\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[603,605,604,602,601,85,600,606,608,607,609,60],"_links":{"self":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/144"}],"collection":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":0,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.compdigitec.com\/labs\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}