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;
    }


  • 相关阅读:
    TopCoder12729 「SRM589Medium」GearsDiv1 二分图最小点覆盖
    Codechef RIN 「Codechef14DEC」Course Selection 最小割离散变量模型
    BZOJ3144/LG3227 「HNOI2013」切糕 最小割离散变量模型
    20191214 Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
    [Codeforces868F]Yet Another Minimization Problem
    2020年计算机算法基础理论与应用研讨会小记
    [Codeforces1421E]Swedish Heroes
    [Codechef CCC]Hit the coconuts
    CSP-S 2020
    牛客NOIP2020模拟
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/5325262.html
Copyright © 2011-2022 走看看