Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using Gtk;
- using System.Drawing;
- namespace MacGtkTest
- {
- static class Program
- {
- [STAThread]
- static void Main(string[] args)
- {
- if (args.Length != 1 || (args[0] != "W" && args[0] != "G"))
- {
- Console.WriteLine("Usage: MacGtkTest W|G");
- return;
- }
- if (args[0] == "W")
- {
- System.Threading.Thread t = new System.Threading.Thread(RunGtkLoop);
- t.Start();
- System.Threading.Thread.Sleep(5 * 1000);
- RunWinLoop();
- }
- else
- {
- System.Threading.Thread t = new System.Threading.Thread(RunWinLoop);
- t.Start();
- System.Threading.Thread.Sleep(5 * 1000);
- RunGtkLoop();
- }
- }
- static void RunWinLoop()
- {
- Console.WriteLine("Initializing WinForms");
- System.Windows.Forms.Application.EnableVisualStyles();
- System.Windows.Forms.Application.DoEvents();
- Console.WriteLine("Running WinForms");
- System.Windows.Forms.Application.Run();
- Console.WriteLine("Exiting WinForms");
- }
- static void RunGtkLoop()
- {
- Gtk.Application.Init();
- StatusIcon icon = new StatusIcon();
- icon.Visible = false;
- Console.WriteLine("Initializing GTK icon");
- using (Bitmap bmp = new Bitmap(16, 16))
- {
- using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
- {
- g.Clear(Color.Purple);
- }
- using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
- {
- bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
- ms.Position = 0;
- icon.Pixbuf = new Gdk.Pixbuf(ms);
- }
- }
- Console.WriteLine("Setting GTK event handlers");
- icon.PopupMenu += new PopupMenuHandler(icon_PopupMenu);
- icon.Activate += new EventHandler(icon_Activate);
- Console.WriteLine("Setting GTK icon visible");
- icon.Visible = true;
- Console.WriteLine("Starting GTK");
- Gtk.Application.Run();
- Console.WriteLine("Exiting GTK");
- }
- static void icon_Activate(object sender, EventArgs e)
- {
- Console.WriteLine("Activate");
- }
- static void icon_PopupMenu(object o, PopupMenuArgs args)
- {
- Console.WriteLine("Popup menu");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement