GTK + Learn Notes 1

zhaozj2021-02-12  165

1. Remove the console window in the GTK engineering project established by the console

a.) Change the "_CONSOLE" in [C / C ] / [Preprocessor definitions] in the project settings to

"_Windows"

b) Change the "/ subs" in the project settings [link] / [project option] to "/ subs"

"/ Subsystem: Windows"

c) change the main function to

#if defined (G_OS_WIN32) && defined (_WINDOWS) // Windows platform no windows console window int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) #else // windows platform console or Linux platforms int main ( INT Argc, Char * Argv []) # endif {

#if Defined (g_os_win32) && defined (_windows)

// Remove the console output 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);

#ndifgtk_main (); return 0;

}

#ifdef g_OS_WIN32STATIC 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

转载请注明原文地址:https://www.9cbs.com/read-6274.html

New Post(0)