原创 界面的宽度与高度

2024-6-21 19:51 135 1 1 分类: 软件与OS 文集: Linux
代码:

#include 
#include 
#include 

static void set_label(GtkWidget *window)
{
	char citem[100];
	sprintf(citem, "窗体尺寸为:%d * %d",
	               window->allocation.width,
	               window->allocation.height);
	//gtk_label_set_label(label, citem);
	gtk_window_set_title(GTK_WINDOW(window), citem);
}
int main(int argc, char *argv[]) {
	gtk_init(&argc, &argv);

	GtkWidget *label;
	label = gtk_label_new ("改变窗体大小后,显示窗体尺寸");
	GtkWidget *window;
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title(GTK_WINDOW(window), "构件尺寸演示");
	gtk_widget_set_size_request(window, 200, 200);
	gtk_container_add (GTK_CONTAINER (window), label);
	gtk_widget_show(label);
	gtk_widget_show(window);
	g_signal_connect((gpointer) window, "size-allocate",
							G_CALLBACK(set_label),
							NULL);
	g_signal_connect(G_OBJECT(window), "delete_event",
			G_CALLBACK(gtk_main_quit), NULL);
	gtk_main();

	return 0;
}

运行


PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
1
关闭 站长推荐上一条 /3 下一条