#include//中文字符串顯示時的編碼轉換:GBK-to-UTF-8
char* gbk2utf8(char* c){return (g_locale_to_utf8(c,-1,0,0,0));
}
gint count=0;
void on_button_clicked(GtkWidget *bt,gpointer data){g_print(gbk2utf8("Button點擊了"));
g_print(" %d ",count);
g_print(gbk2utf8("次!\n"));
count += 1;
}
int main(int argc, char *argv[]) {GtkWidget *window;
GtkWidget *button;
gtk_init(&argc, &argv);
g_print("<----About GTK+-3.0---->\n");
g_print(" GTK+ version: %d.%d.%d\n", gtk_major_version,
gtk_minor_version, gtk_micro_version);
g_print(" Glib version: %d.%d.%d\n", glib_major_version,
glib_minor_version, glib_micro_version);
g_print("<---------------------->\n");
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), gbk2utf8("按鈕示例"));
gtk_window_set_default_size(GTK_WINDOW(window), 260, 50);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window),10);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
button = gtk_button_new_with_label(gbk2utf8("點我試試!"));
g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(on_button_clicked),NULL);
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main();
return 0;
}
3. 運行結果目前累計服務客戶超過千家,積累了豐富的產品開發(fā)及服務經驗。以網站設計水平和技術實力,樹立企業(yè)形象,為客戶提供網站設計、成都做網站、網站策劃、網頁設計、網絡營銷、VI設計、網站改版、漏洞修補等服務。創(chuàng)新互聯(lián)公司始終以務實、誠信為根本,不斷創(chuàng)新和提高建站品質,通過對領先技術的掌握、對創(chuàng)意設計的研究、對客戶形象的視覺傳遞、對應用系統(tǒng)的結合,為客戶提供更好的一站式互聯(lián)網解決方案,攜手廣大客戶,共同發(fā)展進步。4. C++版函數gbk2utf8的類型和參數類型與C版有所不同,主要由char *
改為了char const *
,原因是 ISO C++ 標準禁止a string constant
到char*
的轉換 !運行結果如上圖。
#include#includeusing namespace std;
//中文字符串顯示時的編碼轉換:GBK-to-UTF-8
char const * gbk2utf8(char const * c){return (g_locale_to_utf8(c,-1,0,0,0));
}
gint count=0;
void on_button_clicked( ){g_print(gbk2utf8("Button點擊了"));
g_print(" %d ",count);
g_print(gbk2utf8("次!\n"));
count += 1;
}
int main(int argc, char *argv[]) {GtkWidget *window;
GtkWidget *button;
gtk_init(&argc, &argv);
cout<< "<----About GTK+-3.0---->\n";
cout<< " GTK+ version: "<< gtk_major_version<< "."<< gtk_minor_version<< "."<< gtk_micro_version<\n";
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), gbk2utf8("按鈕示例"));
gtk_window_set_default_size(GTK_WINDOW(window), 260, 50);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window),10);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
button = gtk_button_new_with_label(gbk2utf8("點我試試!"));
g_signal_connect(G_OBJECT(button),"clicked", G_CALLBACK(on_button_clicked),NULL);
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main();
return 0;
}
你是否還在尋找穩(wěn)定的海外服務器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調度確保服務器高可用性,企業(yè)級服務器適合批量采購,新人活動首月15元起,快前往官網查看詳情吧