CSDN博客

img csdnb3a

GTK+学习笔记1

发表于2004/7/8 17:38:00  1575人阅读

分类: 其它 VC++

1.将使用控制台建立的GTK+工程项目中的控制台窗口去掉

      a.)将工程设置中[C/C++]/[Preprocessor definitions]中的“_CONSOLE”改为

                  “_WINDOWS”

      b).将工程设置中[Link]/[Project Option]中的 "/subsystem:console" 改为

               “/subsystem:windows”

      c).将main函数改为

#if defined(G_OS_WIN32) && defined(_WINDOWS)
//Windows平台没有windows控制台窗口
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                     int       nCmdShow)
#else 
//windows平台控制台或Linux 平台
int main(int argc, char* argv[])
#endif
{

#if defined(G_OS_WIN32) && defined(_WINDOWS)

//去掉控制台输出
       gtk_init(&__argc, &__argv);
 
       /* We don't want a console window.. */
       /*
       *  Any calls to the glib logging functions, result in a call to AllocConsole().
       *  ME and 98 will in such cases produce a console window(2000 not), despite
       *  being built as a windows app rather than a console app.  So we should either
       *  ignore messages by setting dummy log handlers, or redirect messages.
       *  This requires setting handlers for all domains(any lib which uses g_logging).
       */

 
       g_log_set_handler(NULL,(GLogLevelFlags) (G_LOG_LEVEL_MASK  | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), DrCOM_dummy_log_handler, NULL); 
    g_log_set_handler("Gdk",(GLogLevelFlags)(G_LOG_LEVEL_MASK| G_LOG_FLAG_FATAL  | G_LOG_FLAG_RECURSION), DrCOM_dummy_log_handler, NULL);
 g_log_set_handler("Gtk",(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
  DrCOM_dummy_log_handler, NULL);
 g_log_set_handler("GLib",(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
  DrCOM_dummy_log_handler, NULL);
 g_log_set_handler("GModule",(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
  DrCOM_dummy_log_handler, NULL);
 g_log_set_handler("GLib-GObject",(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
  DrCOM_dummy_log_handler, NULL);
 g_log_set_handler("GThread",(GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION),
  DrCOM_dummy_log_handler, NULL);
 
  /* g_print also makes a call to AllocConsole(), therefore a handler needs to be
    set here aswell */

    g_set_print_handler( DrCOM_dummy_print );
 
#else
 gtk_init(&argc, &argv);
#endif

       gtk_main();
       return 0;

}

#ifdef G_OS_WIN32
static void DrCOM_dummy_print( const gchar* string )
{
 return;
}

static void DrCOM_dummy_log_handler (const gchar    *domain,
            GLogLevelFlags  flags,
            const gchar    *msg,
            gpointer        user_data)
{
 return;
}
#endif

0 0

相关博文

我的热门文章

img
取 消
img