HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_ALL_ACCESS,true,pid);
SendMessage(hNotify1_0,WM_PAINT ,NULL,NULL);
RECT 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=L"";
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(...)
{
}
}
try
{
whd=0;
ReadProcessMemory(hProcess,(void *)pButton->dwData,&whd,4,&n);
}
catch(...)
{
}
proid=NULL;
GetWindowThreadProcessId((HWND)whd,&proid);
if(proid==NULL)
{
PostMessage(hNotify1_0,TB_DELETEBUTTON,i,0);
SendMessage(HWND_BROADCAST,WM_SETTINGCHANGE,NULL,NULL);
}
}
delete pButton;
}
/
ON_MESSAGE(TAB_MYMESSAGE_FROMTRAY,&My_onShowTary)
//
//窗口转托盘
void My_toTray();
void CTril_ProjectDlg::My_toTray()
{
NOTIFYICONDATA nid;
nid.cbSize = (DWORD)sizeof(NOTIFYICONDATA);
nid.hWnd = this->m_hWnd;
nid.uID = IDR_MAINFRAME;
nid.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP ;
nid.uCallbackMessage = TAB_MYMESSAGE_FROMTRAY;//自定义的消息名称
nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
wcscpy(nid.szTip, L"Tril_Solutions");
Shell_NotifyIcon(NIM_ADD,&nid);//在托盘区添加图标
ShowWindow(SW_HIDE);//隐藏主窗口
}
// 托盘转窗口
afx_msg LRESULT My_onShowTary(WPARAM wParam,LPARAM lParam);
LRESULT CTril_ProjectDlg::My_onShowTary(WPARAM wParam,LPARAM lParam)
{
//wParam接收的是图标的ID,而lParam接收的是鼠标的行为
if( wParam != IDR_MAINFRAME)
return 1;
switch(lParam)
{
case WM_RBUTTONUP:
{//右键起来时弹出快捷菜单,这里只有一个“关闭”
LPPOINT lpoint = new tagPOINT;
::GetCursorPos(lpoint);//得到鼠标位置
CMenu menu;
menu.CreatePopupMenu();//声明一个弹出式菜单
增加菜单项“关闭”,点击则发送消息WM_DESTROY给主窗口(已
隐藏),将程序结束。
//menu.AppendMenu(MF_STRING,WM_DESTROY,L"关闭");
//增加菜单项“关闭”,点击则发送自定义消息IDC_BUTTON1给主窗口(已隐藏)
//退出按纽将响应该消息
menu.AppendMenu(MF_STRING,IDC_BUTTON_CLOSE,L"Exit");
//确定弹出式菜单的位置
menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this);
//资源回收
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
delete lpoint;
ClearIcon();
}
break;
case WM_LBUTTONDBLCLK://双击左键的处理
{
this->ShowWindow(SW_SHOW);//简单的显示主窗口完事儿
}
break;
}
return 0;
}