?? hscroll.c
字號:
/* * * Sample Code for Gtk+ Programming in C, 1st Edition, Prentice Hall * * Copyright 2000 - 2002 Syd Logan, All Rights Reserved * * This code is distributed without warranty. You are free to use this * code for any purpose, however, if this code is republished or * redistributed in its original form, as hardcopy or electronically, * then you must include this copyright notice along with the code. * * Questions or comments regarding this code or any bugs it contains can * be directed to the author via e-mail at slogan@cts.com **/#include <gtk/gtk.h>#include <stdio.h>// a data type that makes it possible to pass both adjustment objects as// client data to the HandleOkButton() signal functiontypedef struct _adjustments { GtkAdjustment *adj1; GtkAdjustment *adj2;} Adjustments;// called when the user presses the Ok buttonstatic voidHandleOkButton(GtkWidget *w, gpointer data){ Adjustments *adjs = (Adjustments *) data; fprintf( stderr, "Hscale value is %d vscale value is %.1f\n", (int) adjs->adj1->value, adjs->adj2->value );}// called when the user changes the value of the first scale widgetstatic voidAdjustment1Changed(GtkAdjustment *w, gpointer data){ fprintf( stderr, "Adjustment 1 is %d\n", (int) w->value );}// called when the user changes the value of the second scale widgetstatic voidAdjustment2Changed(GtkAdjustment *w, gpointer data){ fprintf( stderr, "Adjustment 2 is %.1f\n", w->value );}main( argc, argv )int argc;char *argv[];{ GtkWidget *hscale, *vscale, *vbox, *hbox, *window, *button; GtkObject *adj1, *adj2; Adjustments adjustments; gtk_init( &argc, &argv ); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE); gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &window); gtk_window_set_title(GTK_WINDOW (window), "GtkScale Demo"); vbox = gtk_vbox_new( FALSE, 0 ); gtk_container_add( GTK_CONTAINER( window ), vbox ); hbox = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX( vbox ), hbox, TRUE, TRUE, 0 ); // create an adjustment object for the first scale widget adj1 = gtk_adjustment_new(0.0, 0.0, 100.0, 1.0, 5.0, 1.0); gtk_signal_connect(GTK_OBJECT(adj1), "value_changed", GTK_SIGNAL_FUNC(Adjustment1Changed), NULL); // create a horizontal scale widget. Display the value to the // left of the scale, and display scale value as an integer hscale = gtk_hscrollbar_new( GTK_ADJUSTMENT(adj1) ); gtk_box_pack_start( GTK_BOX( hbox ), hscale, TRUE, TRUE, 0 ); // create an adjustment object for the second scale widget adj2 = gtk_adjustment_new(0.0, 0.0, 100.0, 1.0, 5.0, 50.0); gtk_signal_connect(GTK_OBJECT(adj2), "value_changed", GTK_SIGNAL_FUNC(Adjustment2Changed), NULL); // create a vertical scale widget using widget-supplied defaults vscale = gtk_vscrollbar_new( GTK_ADJUSTMENT(adj2) ); gtk_box_pack_start( GTK_BOX( hbox ), vscale, TRUE, TRUE, 0 ); adjustments.adj1 = GTK_ADJUSTMENT(adj1); adjustments.adj2 = GTK_ADJUSTMENT(adj2); button = gtk_button_new_with_label( "Ok" ); gtk_signal_connect(GTK_OBJECT(button), "clicked", (GtkSignalFunc) HandleOkButton, &adjustments); gtk_box_pack_end( GTK_BOX( vbox ), button, FALSE, FALSE, 0 ); gtk_widget_show_all( GTK_WIDGET( window ) ); adj2 = (GtkObject *) gtk_range_get_adjustment( GTK_RANGE( vscale ) ); printf( "adjustment 2 is %x\n", adj2 ); gtk_main();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -