GTK 窗体小记

      今天终于解决了这个难题, 围绕它已经折磨我好久了 . 现在把心得写下, 以便同仁和自己以后参考.
根据GTK+的外观设置API : gtk_window_set_decorated (window,FALSE); 这个API可以创建无标题栏的窗体. 二话不说, 直接查找API的源代码:

 

ExpandedBlockStart.gif 代码
1  void  gtk_window_set_decorated (GtkWindow  * window,gboolean   setting)
2  {
3    ... gdk_window_set_decorations (GTK_WIDGET (window) -> window,GDK_DECOR_ALL);
4         else
5        gdk_window_set_decorations (GTK_WIDGET (window) -> window,  0 );
6   ...}
7 

 

再往下找(在gdk的X11里面找):

 

ExpandedBlockStart.gif 代码
 1  void  gdk_window_set_decorations (GdkWindow  * window,GdkWMDecoration decorations)
 2  {
 3    MotifWmHints hints;
 4 
 5    g_return_if_fail (GDK_IS_WINDOW (window)); 
 6    hints.flags  =  MWM_HINTS_DECORATIONS;
 7    hints.decorations  =  decorations; 
 8    gdk_window_set_mwm_hints (window,  & hints);
 9  }
10 
11 

 

again:

 

ExpandedBlockStart.gif 代码
 1  static   void  gdk_window_set_mwm_hints (GdkWindow  * window,MotifWmHints  * new_hints)
 2  {
 3    GdkDisplay  * display;
 4    Atom hints_atom  =  None;
 5    guchar  * data;
 6    MotifWmHints  * hints;
 7    Atom type;
 8    gint format;
 9    gulong nitems;
10    gulong bytes_after;
11   
12     if  (GDK_WINDOW_DESTROYED (window))
13       return ;
14   
15    display  =  gdk_drawable_get_display (window); 
16    hints_atom  =  gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
17 
18    XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
19          hints_atom,  0 sizeof  (MotifWmHints) / sizeof  ( long ),
20          False, AnyPropertyType,  & type,  & format,  & nitems,
21           & bytes_after,  & data);
22   
23     if  (type  ==  None)
24      hints  =  new_hints;
25     else
26    {
27        hints  =  (MotifWmHints  * )data;
28   
29         if  (new_hints -> flags  &  MWM_HINTS_FUNCTIONS)
30   {
31     hints -> flags  |=  MWM_HINTS_FUNCTIONS;
32     hints -> functions  =  new_hints -> functions;
33   }
34    if  (new_hints -> flags  &  MWM_HINTS_DECORATIONS)
35   {
36     hints -> flags  |=  MWM_HINTS_DECORATIONS;
37     hints -> decorations  =  new_hints -> decorations;
38   }
39  }
40   
41    XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
42       hints_atom, hints_atom,  32 , PropModeReplace,
43       (guchar  * )hints,  sizeof  (MotifWmHints) / sizeof  ( long ));
44   
45     if  (hints  !=  new_hints)
46      XFree (hints);
47  }
48 
49 

 

 

就是它了 创建无装饰窗体的核心代码就是它了. 再从中进行分析, 我封装出了这样的函数代码:

x

ExpandedBlockStart.gif 代码
 1  static   void  gdk_window_set_mwm_hints (GdkWindow  * window,MotifWmHints  * new_hints)
 2  {
 3    GdkDisplay  * display;
 4    Atom hints_atom  =  None;
 5    guchar  * data;
 6    MotifWmHints  * hints;
 7    Atom type;
 8    gint format;
 9    gulong nitems;
10    gulong bytes_after;
11   
12     if  (GDK_WINDOW_DESTROYED (window))
13       return ;
14   
15    display  =  gdk_drawable_get_display (window); 
16    hints_atom  =  gdk_x11_get_xatom_by_name_for_display (display, _XA_MOTIF_WM_HINTS);
17 
18    XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
19          hints_atom,  0 sizeof  (MotifWmHints) / sizeof  ( long ),
20          False, AnyPropertyType,  & type,  & format,  & nitems,
21           & bytes_after,  & data);
22   
23     if  (type  ==  None)
24      hints  =  new_hints;
25     else
26    {
27        hints  =  (MotifWmHints  * )data;
28   
29         if  (new_hints -> flags  &  MWM_HINTS_FUNCTIONS)
30   {
31     hints -> flags  |=  MWM_HINTS_FUNCTIONS;
32     hints -> functions  =  new_hints -> functions;
33   }
34    if  (new_hints -> flags  &  MWM_HINTS_DECORATIONS)
35   {
36     hints -> flags  |=  MWM_HINTS_DECORATIONS;
37     hints -> decorations  =  new_hints -> decorations;
38   }
39  }
40   
41    XChangeProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
42       hints_atom, hints_atom,  32 , PropModeReplace,
43       (guchar  * )hints,  sizeof  (MotifWmHints) / sizeof  ( long ));
44   
45     if  (hints  !=  new_hints)
46      XFree (hints);
47  }
48 
49 

 

make  运行 .

PS: 典型的窗口管理程序的应用问题 不过要找到这个点还真费了不少事 .希望对大家有所帮助。

 

 

 

转载于:https://www.cnblogs.com/winnxm/archive/2010/02/26/1674100.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值