QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

楼主: changyp

怎样实现用GTK编程将窗口隐藏,并以图标形式显示在系统托盘?

[复制链接]
 楼主| 发表于 2005-11-4 12:51:40 | 显示全部楼层
[quote:89d3c5c96e="mozilla"]你用的肯定是从gnome-cn上下载的。
我上传那个是从星际译王里拷贝出来的。

另外这个程序在kde下也管用。[/quote]

我己经找到问题了
以eggtrayicon.c里面把#include   <config.h>注释掉
然后再添加#define GETTEXT_PACKAGE "****"
               #define PACKAGE "****"     //****是你的程序名
这样就可以编译通过了..
回复

使用道具 举报

发表于 2008-6-2 10:45:29 | 显示全部楼层

回复 #8 mozilla 的帖子

mozilla很厉害啊,谢谢了,转眼2008了,呵呵。
回复

使用道具 举报

发表于 2008-6-18 13:19:20 | 显示全部楼层
楼上更厉害…………这么早的僵死贴也能翻出来
回复

使用道具 举报

发表于 2008-9-6 09:30:27 | 显示全部楼层
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include <unistd.h>
#include <wait.h>
#include<gtk/gtk.h>
/*
** 编译使用以下命令:
** gcc -Wall `pkg-config --libs --cflags gtk+-2.0` icon.c -o icon
** 需要gtk2 >2.10.0
*/
void callback_icon(GtkStatusIcon *status_icon,gpointer data)
{
        gtk_main_quit();
        g_object_unref(status_icon);
}

char *get_proc_path(void)
{
        char *link = NULL;
        char *tmp = NULL;
        static char path[1024]={0};
       
        link = g_strdup_printf("/proc/%d/exe",getpid());
        tmp = g_file_read_link(link,NULL);
        strcpy(path,tmp);
       
        g_free(link);
        g_free(tmp);
       
        return path;
}
int main(int argc,char **argv)
{
        gtk_init(&argc,&argv);
       
        char * cmd ="/bin/echo";
        char *procpath = NULL;
        GtkStatusIcon* icon;
        pid_t pid ;
        int status;

        icon = gtk_status_icon_new_from_stock (GTK_STOCK_QUIT);
        gtk_status_icon_set_tooltip(icon,"A Status Icon HelloWorld");
        g_signal_connect((gpointer)icon, "activate", G_CALLBACK(callback_icon), NULL);
       
        gtk_main();
//        signal(SIGCHLD,SIG_IGN);
        pid = fork();
        if(pid==0){
                execlp(cmd,cmd,NULL);
                fprintf(stderr,"execlp():%s:%s\n",cmd,strerror(errno));
                exit(-1);
        }else if(pid == -1 ){ ///error .
                fprintf(stderr,"fork():%s \n",strerror(errno));
                return pid;
        }
        if(waitpid(pid,&status,0)==-1)
                g_print("waitpid(pid = %d):%s",pid,strerror(errno));
        if(fork()==0){
                procpath = get_proc_path();
                execlp(procpath,procpath,NULL);
        }
        g_print("return 0 .\n");
        return 0;
}
回复

使用道具 举报

发表于 2008-11-17 22:56:14 | 显示全部楼层
我再翻腾一下吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-26 22:59 , Processed in 0.088994 second(s), 13 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表