Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

C - Simple Example GTK

// gcc file.c -o file.o `pkg-config --libs --cflags gtk+-2.0`

#include <gtk/gtk.h>
#include <stdlib.h>

void displayUI()
{
	GtkWidget* mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	gtk_window_set_default_size(GTK_WINDOW(mainWindow), 400, 300);
	gtk_window_set_title(GTK_WINDOW(mainWindow), "GTK Simple Example");
	gtk_window_set_position(GTK_WINDOW(mainWindow), GTK_WIN_POS_CENTER_ALWAYS);

	gtk_signal_connect(GTK_OBJECT(mainWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	gtk_widget_show_all(mainWindow);
}

int main(int argc, char *argv[])
{
	gtk_init(&argc, &argv);

	displayUI();

	gtk_main();

	return EXIT_SUCCESS;
}

Xlib - mouseClick

// Simula il click del mouse

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>

void mouseClick(int button)
{
	Display *display = XOpenDisplay(NULL);

	XEvent event;
	
	if(display == NULL)
	{
		fprintf(stderr, "Errore nell'apertura del Display !!!\n");
		exit(EXIT_FAILURE);
	}
	
	memset(&event, 0x00, sizeof(event));
	
	event.type = ButtonPress;
	event.xbutton.button = button;
	event.xbutton.same_screen = True;
	
	XQueryPointer(display, RootWindow(display, DefaultScreen(display)), &event.xbutton.root, &event.xbutton.window, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
	
	event.xbutton.subwindow = event.xbutton.window;
	
	while(event.xbutton.subwindow)
	{
		event.xbutton.window = event.xbutton.subwindow;
		
		XQueryPointer(display, event.xbutton.window, &event.xbutton.root, &event.xbutton.subwindow, &event.xbutton.x_root, &event.xbutton.y_root, &event.xbutton.x, &event.xbutton.y, &event.xbutton.state);
	}
	
	if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");
	
	XFlush(display);
	
	usleep(100000);
	
	event.type = ButtonRelease;
	event.xbutton.state = 0x100;
	
	if(XSendEvent(display, PointerWindow, True, 0xfff, &event) == 0) fprintf(stderr, "Errore nell'invio dell'evento !!!\n");
	
	XFlush(display);
	
	XCloseDisplay(display);
}


// gcc source.c -L /usr/X11R6/lib -lX11

Java - UIManager all-windows

// Imposto il tema Metal non solo all'interno delle finestre di Java, ma anche al suo esterno...

    // Con queste definizioni dico che tutti i frame e i dialog prendono il tema Metal
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    //

    try
    {
        // Con questa imposto il tema
	UIManager.setLookAndFeel(new MetalLookAndFeel());
    }
    catch(UnsupportedLookAndFeelException e)
    {
	e.printStackTrace();
    }
    // In questo modo tutte le finestre avranno il tema Metal
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS