zoukankan      html  css  js  c++  java
  • 任务栏托盘不消失的问题-有启示

    通过找出该图标所相应的进程ID,假设该ID为NULL则删除该图标.

    #include <AFX.H>
    #include <COMMCTRL.H>
    #include <iostream.h>
    int main()
    {
    HWND  hStatus=::FindWindow("Shell_TrayWnd",NULL);  //得到任务栏句柄
    if  (hStatus==NULL)  
    {  
    cout<<"Get Shell_TrayWnd error!
    ";  
    return -1;  
    }  
    HWND  hNotify=FindWindowEx(hStatus,NULL,"TrayNotifyWnd",NULL); //右下角区域 
    if  (hNotify==NULL)  
    {  
    cout<<"Get TrayNotifyWnd error!
    ";  
    return -1;  
    }  
    HWND  hNotify1=FindWindowEx(hNotify,NULL,"SysPager",NULL);
    if  (hNotify==NULL)  
    {  
    cout<<"Get SysPager error!
    ";  
    return -1;  
    } 
    HWND  hNotify1_0=FindWindowEx(hNotify1,NULL,"ToolBarWindow32",NULL);//右下角区域(不包含时间)
    if  (hNotify1_0==NULL)   
    {  
    cout<<"Get ToolBarWindow32 error!
    ";  
    return -1;  
    }  
    //-------------------以上是得到任务栏右下脚一块地方的句柄
    DWORD  pid = 0;  
    GetWindowThreadProcessId(hNotify1_0,&pid);  
    if  (pid==NULL)  
    {  
    cout<<"Get pid error!
    ";  
    return -1;  
    }   
    
    HANDLE  hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_ALL_ACCESS,true,pid);  
    if  (hProcess==NULL)  
    {  
    cout<<"Get hd error!
    ";  
    return -1;  
    }  
    ::SendMessage(hNotify1_0,WM_PAINT ,NULL,NULL); 
    CRect rect;
    ::GetWindowRect(hNotify1_0,&rect);
    ::InvalidateRect(hNotify1_0,&rect,false);
    int  iNum=::SendMessage(hNotify1_0,TB_BUTTONCOUNT ,NULL,NULL);  //获取任务栏上图标个数
    
    unsigned long n = 0;  
    TBBUTTON  *pButton = new TBBUTTON;  
    CString  strInfo = _T("");  
    wchar_t  name[256] = {0};  	
    TBBUTTON  BButton; 
    unsigned   long    whd,proid;
    CString x;
    
    for(int i=0; i<iNum; i++)  
    {  
    ::SendMessage(hNotify1_0,TB_GETBUTTON,i,(LPARAM)(&BButton));  
    ReadProcessMemory(hProcess,&BButton,pButton,sizeof(TBBUTTON),&n);   
    if  (pButton->iString != 0xffffffff)  
    {  
    try  
    {  
    ReadProcessMemory(hProcess,(void *)pButton->iString,name,255,&n);	
    }  
    catch(...)  
    {  
    }      
    strInfo.Format("%d : %s
    ",i+1,CString(name)); 
    TRACE(strInfo);
    cout<<strInfo<<endl;
    }
    
    try   
    {   
    whd=0;   
    ReadProcessMemory(hProcess,(void   *)pButton->dwData,&whd,4,&n);   
    }   
    catch(...)   
    {   
    }   
    proid=NULL;   
    GetWindowThreadProcessId((HWND)whd,&proid);   
    if(proid==NULL)
    ::SendMessage(hNotify1_0,TB_DELETEBUTTON,i,0);
    } 
    delete pButton;
    return 0;
    }


  • 相关阅读:
    <html>
    Java设计模式----策略模式
    Android之通过网络播放一首简单的音乐
    关于六度关系理论,我最终算出了自己与奥巴马的关系度数
    本地创建Duplicate数据库
    资源向导之 &quot;APUE&quot;
    WinCE 下编程须要IP地址控件咋办?
    LeetCode Anagrams My solution
    一起talk C栗子吧(第一百三十三回:C语言实例--创建进程时的内存细节)
    自己定义View Layout过程
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5325262.html
Copyright © 2011-2022 走看看