TA的每日心情 | 奋斗 2016-10-11 09:20 |
---|
签到天数: 271 天 连续签到: 1 天 [LV.8]以坛为家I
|
1.实现按下鼠标左键拖动窗口
1>加入事件:
- gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
复制代码
2>关联信号与button按下的事件:
- g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(window_drag), NULL);
复制代码
3>窗口拖动事件的实现:
- gboolean window_drag(GtkWidget *widget, GdkEventButton *event, GdkWindowEdge edge)
- {
- if (event->button == 1)
- {
- gtk_window_begin_move_drag(GTK_WINDOW(gtk_widget_get_toplevel(widget)), event->button, event->
- x_root, event->y_root, event->time);
- }
-
- return FALSE;
- }
复制代码 注意这里:GTK+3中,第二个参数是GdkEvent,而不是GdkEventButton,所以,如果是GTK+3,那么请把所有的event->后面加上button.
例如:event->button改成event->button.button
2.使窗口不能移出桌面最左边,在标题栏显示当前窗口的位置坐标
1>关联信号与事件:
- g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(window_move), NULL);
复制代码
2>窗口移动事件的实现:
- gboolean window_move(GtkWidget *widget, GdkEvent *event, gpointer data)
- {
- gint x, y;
- gchar buf[10] = {0};
- x = event->configure.x;
- y = event->configure.y;
- if (x <= 0)//如果窗口超出桌面最左边框
- {
- x = 0;
- gtk_window_move(GTK_WINDOW(widget), x, y);
- }
- sprintf(buf, "%d,%d", x, y);
- gtk_window_set_title(GTK_WINDOW(widget), buf);
- return TRUE;
- }
复制代码 |
|