예제 #1
0
파일: gtk1.C 프로젝트: lhkiss2012/Ryoma
/*主函数*/
int main(int argc,char *argv[]){ 

 gint i; 

 int v,v0; 

 int timer; 

 GtkWidget *label2,*label; 

 GtkWidget *label0[5]; 

 GtkWidget *text; 

 gpointer date,data; 

 gdouble value1,value2; 

 gpointer gdata; 

 GtkWidget *label3; 

 GtkWidget *button1;  
 
 GtkWidget *vscrollbar,*hscrollbar;//定义滚动条 

 GtkWidget *MenuBar;//定义菜单栏 

 GtkWidget *MenuItemFile,*MenuItemShutDown,*MenuItemHelp; 
 
 gtk_set_locale (); 

 gtk_init(&argc,&argv);//在任何构件生成之前完成 

 memset (pfuser, 0 ,sizeof (pfuser)); 

 

 window=gtk_window_new(GTK_WINDOW_TOPLEVEL);//创建主窗口 

 gtk_window_set_title(GTK_WINDOW(window),"---------linux任务管理器-----------");//设置窗口标题 

 gtk_widget_set_usize(window, 600, 500);//设置窗口大小  

 gtk_window_set_resizable (GTK_WINDOW (window), TRUE);// 窗口大小可改变(TRUE) 

 gtk_container_set_border_width(GTK_CONTAINER(window),5);//设置窗口边框宽度 

 gtk_widget_show(window); 

 

 table=gtk_table_new(12,11,TRUE);//创建表格12行*10列 

 gtk_widget_show(table); 

 gtk_container_add(GTK_CONTAINER(window),table);//将table装进窗口  

 

 notebook=gtk_notebook_new();//创建notebook 

 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_TOP);//设置notebook的格式 

 gtk_table_attach_defaults (GTK_TABLE (table), notebook, 0, 11, 1, 11);//将notebook加入表格中 

 gtk_widget_show(notebook); 

 /*创建notebook的每一页*/ 

 for(i=0;i<5;i++){    

  label0[i]=gtk_label_new(title[i]);//notebook页面标题            

  frame[i]=gtk_frame_new(NULL);//页面框架 

  gtk_container_set_border_width (GTK_CONTAINER (frame[i]), 10);//框架与边缘的距离 

  gtk_frame_set_shadow_type (GTK_FRAME (frame[i]),GTK_SHADOW_ETCHED_OUT);//框架的阴影模式 

  gtk_widget_set_size_request(frame[i],450,450);//框架大小 

  gtk_widget_show(frame[i]); 

  gtk_widget_show (label0[i]); 

  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),frame[i],label0[i]);//创建notebook的第i页   

  table1[i]=gtk_table_new(12,11,TRUE);//创建表格12行*11列 

  gtk_widget_show(table1[i]); 

  gtk_container_add(GTK_CONTAINER(frame[i]),table1[i]);//将表格tbale1放入框架 
 } 
 
 MenuBar=gtk_menu_bar_new();//创建菜单栏 

 gtk_table_attach_defaults(GTK_TABLE(table),MenuBar,0,11,0,1);//将菜单栏加入表格 

 MenuItemFile=CreateMenuItem(MenuBar,"文件");//增加菜单项 

  MenuItemHelp=CreateMenuItem(MenuBar,"帮助");//增加菜单项 

  gtk_widget_show(MenuBar); 

 

    process_label=gtk_label_new("");//创建显示进程数的标签 

    gtk_widget_show(process_label); 
    
//    timer=gtk_timeout_add(1000,(GtkFunction)process_num,data);//加一个定时器(timer),每隔1秒调用一次(GtkFunction)process_num函数 

    gtk_table_attach_defaults(GTK_TABLE(table),process_label,0,2,11,12);//在状态栏中显示进程总数 

     cpu_rate_label=gtk_label_new(" ");//创建显示cpu占用率的标签 

    gtk_widget_show(cpu_rate_label); 

 gtk_table_attach_defaults(GTK_TABLE(table),cpu_rate_label,2,5,11,12);//在状态栏中显示cpu占用率 
    
 cpu_bar=gtk_progress_bar_new();//创建CPU进度条 

 gtk_widget_show(cpu_bar); 
 notebook_cpu_init(); 
 
 gtk_signal_connect(GTK_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(delete_event),NULL); 

  gtk_main(); 
} 
예제 #2
0
//---------------------主函数--------------------
int main(int argc, char *argv[])
{
	int i;
	int timer;
	gpointer data, date;

	gtk_set_locale ();//初始化运行环境
	gtk_init(&argc,&argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);//创建主窗口
	gtk_window_set_title(GTK_WINDOW(window),"查看进程使用内存地址的利器");//设置窗口标题
	gtk_widget_set_usize(window, 600, 500);//设置窗口大小 
	gtk_window_set_resizable (GTK_WINDOW (window), TRUE);// 窗口大小可改变(TRUE)
	gtk_container_set_border_width(GTK_CONTAINER(window),5);//设置窗口边框宽度
	gtk_widget_show(window);

	table = gtk_table_new(12,11,TRUE);//创建表格12行*11列
	gtk_widget_show(table);
	gtk_container_add(GTK_CONTAINER(window),table);//将table装进窗口 

	notebook = gtk_notebook_new();
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_TOP);//设置notebook的格式
	gtk_table_attach_defaults (GTK_TABLE (table), notebook, 0, 11, 1, 11);//将notebook加入表格中
	gtk_widget_show(notebook);
	for(i = 0; i < 5; i++)
	{
		label0[i] = gtk_label_new(title[i]);
		frame[i] = gtk_frame_new(NULL);
		gtk_container_set_border_width(GTK_CONTAINER(frame[i]), 10);
		gtk_frame_set_shadow_type(GTK_FRAME(frame[i]), GTK_SHADOW_ETCHED_OUT);
		gtk_widget_set_size_request(frame[i], 450, 450);
		gtk_widget_show(frame[i]);
		gtk_widget_show(label0[i]);
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame[i], label0[i]);
		table1[i] = gtk_table_new(12, 11, TRUE);
		gtk_widget_show(table1[i]);
		gtk_container_add(GTK_CONTAINER(frame[i]), table1[i]);
	}

	label = gtk_label_new("Select Memory Address By PID:");
	gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 5, 0, 1);
	gtk_widget_show(label);

	entry = gtk_entry_new();
	gtk_table_attach_defaults(GTK_TABLE(table), entry, 6, 8, 0, 1);
	gtk_widget_show(entry);

	button = gtk_button_new_with_label(" SELECT ");
	gtk_widget_set_size_request(button, 10, 10);
	gtk_table_attach_defaults(GTK_TABLE(table), button, 9, 11, 0, 1);
	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_clicked), NULL);
	gtk_widget_show(button);

	time_label = gtk_label_new("");
	timer = gtk_timeout_add(1000, (GtkFunction)sys_time, data);
	gtk_table_attach_defaults(GTK_TABLE(table), time_label, 7, 11, 1, 2);
	gtk_widget_show(time_label);				
	
	uptime_label = gtk_label_new("");
	timer = gtk_timeout_add(1000, (GtkFunction)uptime, data);
//	gtk_table_attach_defaults(GTK_TABLE(table), uptime_label, 7, 11, 0, 2);	
	gtk_widget_show(uptime_label);
	
	MenuBar = gtk_menu_bar_new();
	gtk_table_attach_defaults(GTK_TABLE(table), MenuBar, 0, 11, 0, 1);
	MenuItemFile = CreateMenuItem(MenuBar, "文件");
	CreateMenuFile(MenuItemFile);		
	MenuItemShutDown = CreateMenuItem(MenuBar, "关机选项");
	CreateMenuShutDown(MenuItemShutDown);
	MenuItemHelp = CreateMenuItem(MenuBar, "帮助");
	CreateMenuHelp(MenuItemHelp);
	gtk_widget_show(MenuBar);

	process_label = gtk_label_new("");
	timer = gtk_timeout_add(1000, (GtkFunction)process_num, data);
	gtk_table_attach_defaults(GTK_TABLE(table), process_label, 0, 2, 11, 12);
	gtk_widget_show(process_label);

	cpu_rate_label = gtk_label_new("");
	timer = gtk_timeout_add(1000, (GtkFunction)cpu_rate_ava, data);
	gtk_table_attach_defaults(GTK_TABLE(table), cpu_rate_label, 2, 5, 11, 12);
	gtk_widget_show(cpu_rate_label);

	mem_rate_label = gtk_label_new("");
	timer = gtk_timeout_add(1000, (GtkFunction)mem_rate_ava, data);
	gtk_table_attach_defaults(GTK_TABLE(table), mem_rate_label, 5, 8, 11, 12);
	gtk_widget_show(mem_rate_label);

	swap_rate_label = gtk_label_new("");
	timer = gtk_timeout_add(1000, (GtkFunction)swap_rate_ava, data);
	gtk_table_attach_defaults(GTK_TABLE(table), swap_rate_label, 8, 10, 11, 12);
	gtk_widget_show(swap_rate_label);

	cpu_bar = gtk_progress_bar_new();
	mem_bar = gtk_progress_bar_new();
	swap_bar = gtk_progress_bar_new();
	gtk_widget_show(cpu_bar);
	gtk_widget_show(mem_bar);
	gtk_widget_show(swap_bar);

	notebook_cpu_init();
	notebook_mem_init();
	notebook_pro_init();
//	notebook_vmem_init();

	v_label = gtk_label_new("");
	r_label = gtk_label_new("");

	gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL);
 
	gtk_main();
	return 0;
}