解决方案 »

  1.   

    问题如下:
    1、上面的代码使用到跨进程的内存读取,调用了ReadProcessMemory,但是由于程序是32位的,目标窗口在EXplorer进程中,在64位的机器上(比如64的Win7),读取是有问题的。应该是32位进程直接读取64位进程是有问题的。
    2、上面的代码看上去有点牵强,是非文档化的东西,写到程序应该不是很靠谱。
    3、关于是否有托盘图标,托盘是否在掩藏的溢出区域,没有对应API可供使用,也没有对应的注册表项可以读取,上述的检测很难实现。
      

  2.   

    另外的问题:
    1、实现了类似QQ来消息头像闪动的功能,动态的闪动是通过将托盘图标设置成头像和空白之间来来回切换实现的。但是消息查看过后,要将托盘图标恢复成正常时的图标。但是Shell_NotifyIcon API调用失败,导致托盘图标恢复失败,显示空白,但是位置还在的。尝试过多设置几次,发现也没效果,都会失败。也查看了lasterror值。
    2、在个别机器上出现托盘图标因不明原因消失,而此时程序依然在运行(任务管理器中能找到对应的进程)。于是开启一个守护托盘图标的定时器,定时检测托盘图标是否存在,通过调用Shell_NotifyIcon修改图标信息(其实NOTIFYICONDATA结构体信息没变,只是用同样的NOTIFYICONDATA信息执行了修改动作)。但这样也不能百分之百的解决问题,还是会出现托盘图标消失问题,只是降低了概率。相关代码:
        void CXXDlg::OnTimer( UINT_PTR nIDEvent )  
        {  
            if ( nIDEvent == 100 )  
            {  
                if ( !Shell_NotifyIcon( NIM_MODIFY, &m_nid ) )  
                    Shell_NotifyIcon( NIM_ADD, &m_nid );  
            }  
          
            CDialog::OnTimer(nIDEvent);  
        }  
      

  3.   

    关于托盘图标不明原因消失的问题,XP和Win7中均出现过!
      

  4.   

    是不是重启explorer.exe后消失?
    中文系统要自己注册TaskbarCreated消息后处理
      

  5.   

    是不是重启explorer.exe后消失?
    中文系统要自己注册TaskbarCreated消息后处理这种情况最简单,肯定处理了!
      

  6.   

    是不是重启explorer.exe后消失?
    中文系统要自己注册TaskbarCreated消息后处理
    其实这个消息通知解决2方面问题:
    1、程序运行过程中,explorer资源管理器异常退出,重启后手动添加托盘图标到通知区域;
    2、在Win7中将程序设置为开机自启动,有时会出现托盘图标创建失败的问题,应该是程序自启动时,资源管理器还没创建完成,所以隶属于资源管理器进程的托盘图标通知窗口还没创建,导致向其中添加托盘图标失败。那么注册了这个消息,在收到资源管理器创建完成的消息时,再创建托盘图标,具体说明见msdn上的描述:
    Shell_NotifyIcon will often fail when called during Windows startup (for instance, if your application is listed in HKLM\Software\Microsoft\Windows\CurrentVersion\Run. This appears to be because the system is busy starting applications. The failure is more common on low-spec computers or computers with some brands of antivirus software installed, which seem to be very intensive at startup.Unfortunately, you cannot rely on the error code returned by GetLastError. When Shell_NotifyIcon returns false, some of the common errors returned by GetLastError are:    ERROR_FILE_NOT_FOUND (2)
        ERROR_TIMEOUT (1460)
        ERROR_SUCCESS (0)The most appropriate response to any error returned by Shell_NotifyIcon is to sleep for a period of time and retry.An explanation of why the error code may differ has been made by Paul Baker, paraphrased fromhttp://groups.google.com/group/microsoft.public.platformsdk.shell/msg/59235b293cbf5dfa andhttp://groups.google.com/group/microsoft.public.platformsdk.shell/msg/73973287f15c03fc:Shell_NotifyIcon actually calls SetLastError(0) initially. After that, basically it uses FindWindow to find the tray notification window. If this fails, it will typically return ERROR_FILE_NOT_FOUND. Otherwise it sends a WM_COPYDATA message to the tray notification window, using SendMessageTimeout with a timeout of only 4 seconds. If that message returns zero, then Shell_NotifyIcon will fail with GetLastError returning zero.reply to the above...
    Applications that want to use the notification APIs that are running before or during explorer startup should listen for the notification message that indicates the taskbar is ready to receive API calls. This is the “TaskbarCreated “ message. This also enables your application to re-register if the explorer is re-started.
    This is described in the section titled “Taskbar Creation Notification” on this page:
    http://msdn.microsoft.com/en-us/library/cc144179(VS.85).aspx
      

  7.   

    还有这样一个问题:360如何做到在win7下默认显示到右下角的可见的托盘区域的?
    ----------------------------------------------------------------------------------------------------------------
    1、Win7下为了不让程序托盘侵占太多的右下角空间,默认把托盘图标隐藏在小箭头下托盘溢出区域的。 有时候用户不知道某程序已经启动,且隐藏在小箭头下面,所以就需要提示用户,比如QQ,酷狗都会弹出一个框框告诉用户把QQ的托盘设置出来。 但是有些程序做到了默认显示,比如360,dropbox.
    2、 小箭头打开后的用来保存隐藏的托盘图标的窗口是NotifyIconOverflowWindow窗口,正常显示的是TrayNotifyWnd窗口下可见托盘区域,两个之间都支持直接拖拽,感觉可以模拟拖拽,但是不知怎么实现。
      

  8.   

    第一,图标消失,单就QQ我无论在XP还是WIN7都没有出现过,请先检查程序逻辑,是否自己无意中删了notify icon第二,你的检测方法不靠谱,需要想办法先刷新图标栏()
      

  9.   

    国外的论坛中,有提出到注册表项
    HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Explorer\TrayNotify中,分析 IconStreams和 PastIconsStream文件的内容,但是这是微软不公开的,也是严格禁止的,也没有相关的代码可供参考
      

  10.   

    再就是,为什么在64位机器上检测失败,是由于TBBUTTON结构体:
    typedef struct _TBBUTTON {
        int iBitmap;
        int idCommand;
        BYTE fsState;
        BYTE fsStyle;
    #ifdef _WIN64
        BYTE bReserved[6];          // padding for alignment
    #elif defined(_WIN32)
        BYTE bReserved[2];          // padding for alignment
    #endif
        DWORD_PTR dwData;
        INT_PTR iString;
    } TBBUTTON, NEAR* PTBBUTTON, *LPTBBUTTON;
    在32位和64位程序中的内存分布是不一样的,所以对于32位的程序在64位的操作系统上运行,是要重新计算偏移的
      

  11.   

    想找win7下刷新托盘图标的代码