I don't understand your question at all but a run of your code I'll assume you're talking about the values sent to g_print not being what you want as that seems to be the only error. I'm actually very surprised this compiles. I guess gcc is a lot cleverer than I thought. There are a lot of errors. Here is some that I've corrected:
* in refresh_txtview you have win as a local scope variable but have declared it differently as a global variable above.
* You use sprintf but don't include string.h. actually you are better not including this and use the glib functions (g_sprintf etc.)
* in clicked_cb there is no need to redo gtk_widget_show on the notebook or queue a draw, this will happen automatically when control is passed back to gtk_main. Similarly with all the other refreshing you are doing.
* Also here you have listed the second arguement as GtkNotebook* when it should be gpointer and then cast as needed.
* Your refreshwin function is declared incorrectly
The textview displays exactly how it should so I don't know why you mention it in your question. Did you want the g_print to go to the textview? I'm not sure whether you really want to use g_print, it send info to stdout which on most machines is the terminal, i.e. it won't be seen unless you run the program from the terminal. You would likely be much better setting up a statusbar and pushing the text there each time instead.
The /n you are putting on the end of the strings. You would be better off setting up a macro with conditional compilation to capture both the unix and Windows versions of line endings.
Here is a correction of the code (still using g_print: run from the terminal to see its output)
Code:
#include <gtk/gtk.h>
void clicked_cb(GtkWidget *widget, gpointer data)
{
gchar str[16];
gint n;
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkTextMark *mark;
GtkWidget *lbl, *txtview;
n=gtk_notebook_get_n_pages(GTK_NOTEBOOK(data));
g_snprintf(str, 15, "Page %d", ++n);
lbl = gtk_label_new(str);
gtk_widget_show(lbl);
txtview = gtk_text_view_new();
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txtview));
mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(txtview),mark);
gtk_text_buffer_insert(buffer, &iter, "Buffer", -1);
gtk_widget_show(txtview);
gtk_notebook_append_page(GTK_NOTEBOOK(data), txtview, lbl); //加入页面
}
void refreshwin(GtkWidget* widget, gpointer data)
{
gint num;
gint pagenum;
pagenum=gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget));
num = gtk_notebook_current_page(GTK_NOTEBOOK(widget));
g_print("Current Page Number: %d, Total Number of Pages = %d\n", ++num, pagenum);
}
int main(int argc, char **argv)
{
GtkWidget *win;
GtkWidget *vbox;
GtkWidget *nb;
GtkWidget *button;
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(win),400,300);
g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(win), vbox);
gtk_widget_show(vbox);
nb = gtk_notebook_new();
g_signal_connect_after(G_OBJECT(nb),"switch_page",G_CALLBACK(refreshwin),NULL);
gtk_box_pack_start(GTK_BOX(vbox), nb, TRUE, TRUE, 0);
gtk_widget_show(nb);
button = gtk_button_new_with_label("Add Page");
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(clicked_cb), (gpointer)nb);
gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
gtk_widget_show(win);
gtk_main();
return 0;
}