Create an irregular window in GTK +-2.0 (on)

Source: Internet
Author: User

Http://blog.163.com/xy_god/blog/static/9148351200781734123827/

Create an irregular window in GTK +-2.0 (on)

Author: xy_god

Email: xy_god@163.com

Blog: http://hi.baidu.com/xy_god

Google, Baidu, Chinese, and English web pages have been searched for a long time, but it is difficult to find the irregular production of GTK +-2.0

Window article! Of course, there are still some. On freenode's IRC, we met a Chinese, bsch, who provided a usage diagram.

Although he is very enthusiastic about how to create a circular button, it does not fully meet my needs, because his button's response to the event is still in

In the rectangle area, and it is written by gtkmm. I have little knowledge about gtkmm. I will not mention it here! But his enthusiastic help is still

Thank you very much. Especially, he told me that IRC can be used in Emacs, which is very practical and convenient!

In addition, I started searching for the gtk_widget_shape_combine_mask function, as prompted by my colleagues in the company.

This is rarely used! Hard work, finally found the glock-0.2.0 this software, it is specifically used to illustrate how to use

The gtk_widget_shape_combine_mask function is used to create programs with irregular windows! Of course, it is still very long! All of them are explained,

It must be far from creating an irregular window! Therefore, I have provided some examples based on this example, which is very short and must be

Harm, hey (if you want to read the Glock code, its home page is: http://www.brouhaha.com /~ Eric/software/Glock /)!

The example program I wrote is as follows:

01 /************************************/

02/* Main. C */

03 /************************************/

04 # include <GTK/GTK. h>

05

06 int main (INT argc, char * argv [])

07 {

08 gtkwidget * window;

09 gtkwidget * button;

10 gtkwidget * hbox;

11

12

13

14 gdkgc * GC;

15 gdkcolormap * colormap;

16 gdkbitmap * window_shape_bitmap;

17

18 gdkcolor black;

19 gdkcolor white;

20

21 gtk_init (& argc, & argv );

22

23 /////////////////////////////////////// //////////////////////////////////

24 window = gtk_window_new (gtk_window_toplevel );

25 gtk_window_set_title (gtk_window (window), "circular window test program! ");

26 gtk_window_set_default_size (gtk_window (window), 400,300 );

27 gtk_signal_connect (g_object (window), "Destroy ",

28 g_callback (gtk_main_quit), null );

29

30 hbox = gtk_hbox_new (false, 10 );

31 gtk_container_add (gtk_container (window), hbox );

32 gtk_widget_show (hbox );

33

34 button = gtk_button_new_with_label ("Hello, world! Hello, world! ");

35 gtk_box_pack_start_defaults (gtk_box (hbox), button );

36 gtk_widget_show (button );

37

38 gtk_widget_show_all (window );

39 /////////////////////////////////////// //////////////////////////////////

40

41 //************************************* **************************************

42 colormap = gdk_colormap_get_system ();

43

44 gdk_color_black (colormap, & black );

45 gdk_color_white (colormap, & white );

46

47 window_shape_bitmap = (gdkbitmap *) gdk_pixmap_new (null, 400,300, 1 );

48

49 GC = gdk_gc_new (window_shape_bitmap );

50 gdk_gc_set_foreground (GC, & black );

51 gdk_gc_set_background (GC, & white );

52 gdk_draw_rectangle (window_shape_bitmap, GC, true,

53 0, 0,400,300 );

54

55 gdk_gc_set_foreground (GC, & white );

56 gdk_gc_set_background (GC, & black );

57

58 // draw a filled circle in window_shape_bitmap

59 gdk_draw_arc (window_shape_bitmap, GC, true,

60 0, 0,400,300, 0,360*64 );

61 gtk_widget_shape_combine_mask (window, window_shape_bitmap, 0, 0 );

62 //************************************* **************************************

63

64 gtk_main ();

65 return 0;

66}

Makefile:

Cc = gcc

Test: Main. c

$ (CC) Main. C-o Test 'pkg-config -- cflags -- libs GTK +-2.0'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.