Buchempfehlung
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
"Der" Petzold, das über 1000 Seiten starke Standardwerk zum Win32-API - besonders nützlich u. a. bei der GUI-Programmierung in FreeBASIC! [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

GTK - Menü Beispiel - menue_3

Uploader:Mitgliedrieselkalk
Datum/Zeit:22.04.2010 02:37:44

'- rieselkalk 2010
'- menue_3.bas


#include  once  "gtk/gtk.bi"

#define NULL 0
#define GDK_a &H061
#define GDK_b &H062
#define GDK_c &H063
#define GDK_d &H064
#Define GDK_e &H065
#define GDK_f &H066
#define GDK_g &H067
#define GDK_h &H068
#define GDK_i &H069
#define GDK_j &H06a
#define GDK_k &H06b
#define GDK_l &H06c
#define GDK_m &H06d
#define GDK_n &H06e
#define GDK_o &H06f
#define GDK_p &H070
#define GDK_q &H071
#define GDK_r &H072
#define GDK_s &H073
#define GDK_t &H074
#define GDK_u &H075
#define GDK_v &H076
#define GDK_w &H077
#define GDK_x &H078
#define GDK_y &H079
#define GDK_z &H07a

Declare Sub TextToLabel(Text As String)

sub callback_1 Cdecl (ByVal widget as GtkWidget ptr, byval user_data as gpointer)
  TextToLabel("Neu wurde geklickt!")
End sub
sub callback_2 Cdecl (ByVal widget as GtkWidget ptr, byval user_data as gpointer)
  '- UTF8 Zeichensatz Ä 195 132, Ö 195 150, Ü 195 156, ß 195 159, ä 195 164, ö 195 182, ü 195 188
  TextToLabel(Chr(195)+Chr(150)+"ffnen wurde geklickt!")
End Sub
sub callback_3 Cdecl (byval widget as GtkWidget ptr, byval user_data as gpointer)
  gtk_main_quit()
end Sub

gtk_init (0, 0)

' Menu Tasturkürzel mit AccelGroup bearbeiten
Dim Shared As GtkAccelGroup Ptr accel_group
  accel_group = gtk_accel_group_new ()

Dim Shared As GtkWidget ptr win_1        '- Als Variable nur in Sub verfügbar
  win_1 = gtk_window_new (GTK_WINDOW_TOPLEVEL)
  gtk_window_set_title (GTK_WINDOW (win_1), "Test Menue 3")
  gtk_window_move (GTK_WINDOW (win_1), 300, 200)
  gtk_window_resize (GTK_WINDOW (win_1), 300, 60)
  gtk_window_add_accel_group (GTK_WINDOW (win_1), accel_group)

Dim Shared As GtkWidget Ptr menue_bar
   menue_bar = gtk_menu_bar_new ()

'- Haupt Menu Eintrag Datei
Dim Shared As GtkWidget Ptr hmenue_Datei
  hmenue_Datei = gtk_menu_item_new_with_mnemonic ("_Datei")
  gtk_menu_bar_append (GTK_MENU_BAR(menue_bar), GTK_WIDGET(hmenue_Datei))

'- Sub Menu Eintrag Popup Datei
Dim Shared As GtkWidget Ptr hmenue_down_Datei
  hmenue_down_Datei = gtk_menu_new
  gtk_menu_item_set_submenu (GTK_MENU_ITEM(hmenue_Datei), GTK_WIDGET(hmenue_down_Datei))

'- Menu Eintrag Neu
Dim Shared As GtkWidget Ptr vmenue_Neu
  vmenue_Neu = gtk_image_menu_item_new_with_mnemonic ("Neu")
  gtk_menu_append (GTK_MENU (hmenue_down_Datei), GTK_WIDGET (vmenue_Neu))
  gtk_signal_connect_object (GTK_OBJECT(vmenue_Neu),"activate",G_CALLBACK(@callback_1),0)

  gtk_widget_add_accelerator (GTK_WIDGET(vmenue_Neu), "activate", accel_group, _
                              GDK_n, GDK_CONTROL_MASK, _
                              GTK_ACCEL_VISIBLE)

Dim Shared As GtkWidget Ptr image103
  image103 = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_MENU)
  gtk_widget_set_name (GTK_WIDGET(image103), "image103")
  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (vmenue_Neu), image103)

'- Menu Eintrag Öffnen
Dim Shared As GtkWidget Ptr vmenue_Oeffnen
  vmenue_Oeffnen = gtk_image_menu_item_new_with_mnemonic (Chr(195)+Chr(150)+"ffnen...")
  gtk_menu_append (GTK_MENU (hmenue_down_Datei), GTK_WIDGET (vmenue_Oeffnen))
  gtk_signal_connect_object (GTK_OBJECT(vmenue_Oeffnen),"activate",G_CALLBACK(@callback_2),0)

  gtk_widget_add_accelerator (GTK_WIDGET(vmenue_Oeffnen), "activate", accel_group, _
                              GDK_o, GDK_CONTROL_MASK, _
                              GTK_ACCEL_VISIBLE)

Dim Shared As GtkWidget Ptr image104
  image104 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU)
  gtk_widget_set_name (GTK_WIDGET(image104), "image104")
  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (vmenue_Oeffnen), image104)

'- Menu Eintrag Beenden
Dim Shared As GtkWidget Ptr vmenue_Beenden
  vmenue_Beenden = gtk_image_menu_item_new_with_mnemonic ("Beenden")
  gtk_menu_append (GTK_MENU (hmenue_down_Datei), GTK_WIDGET (vmenue_Beenden))
  gtk_signal_connect_object (GTK_OBJECT(vmenue_Beenden),"activate",G_CALLBACK(@callback_3),0)

  gtk_widget_add_accelerator (GTK_WIDGET(vmenue_Beenden), "activate", accel_group, _
                              GDK_q, GDK_CONTROL_MASK, _
                              GTK_ACCEL_VISIBLE)

Dim Shared As GtkWidget Ptr image108
  image108 = gtk_image_new_from_stock ("gtk-quit", GTK_ICON_SIZE_MENU)
  gtk_widget_set_name (GTK_WIDGET(image108), "image108")
  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (vmenue_Beenden), image108)


Dim Shared As GtkWidget Ptr label_1      '- Als Variable nur in Sub verfügbar
  label_1 = gtk_label_new("_______")
  TextToLabel("Keine Auswahl!")

dim Shared As GtkWidget ptr  vbox_1      '- Als Variable nur in Sub verfügbar
  vbox_1 = gtk_vbox_new(FALSE,0)
  gtk_container_add (GTK_CONTAINER(vbox_1), menue_bar)
  gtk_container_add (GTK_CONTAINER(vbox_1), label_1)

  gtk_container_add (GTK_CONTAINER (win_1), vbox_1)

  gtk_widget_show_all (win_1)

gtk_main()

Sub TextToLabel(Text As String)
 gtk_label_set_text (GTK_LABEL(label_1), Text)
End Sub