http://www.csdn.net/develop/read_article.asp?id=14490 做一个自己的任务栏 //用该程序可以做一个自己的任务栏,包括列举出任务栏上程序的Handle、 //WindowName、程序路径、图标。可选定窗口并提前,或者在程序间切换。 //如果你的程序满屏,并且屏蔽了系统键的话,或许可以用到下面的技巧。但是系统托盘的,我只能取到金山糍粑和FreeRam等,取不到喇叭和输入法等 这里改改或许可以 if (IsWindowVisible(Wnd) or IsIconic(wnd)) and ((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or (GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and (GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
//用该程序可以做一个自己的任务栏,包括列举出任务栏上程序的Handle、
//WindowName、程序路径、图标。可选定窗口并提前,或者在程序间切换。
//如果你的程序满屏,并且屏蔽了系统键的话,或许可以用到下面的技巧。但是系统托盘的,我只能取到金山糍粑和FreeRam等,取不到喇叭和输入法等
这里改改或许可以
if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
(GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
{
if(m_handle = ::FindWindow("Shell_TrayWnd",NULL)) if(m_handle = FindWindowEx(m_handle,NULL,"TrayNotifyWnd",NULL))
if(m_handle = FindWindowEx(m_handle,NULL,"ToolbarWindow32",NULL))
if(m_handle)
this->Attach(m_handle);
else
m_handle = NULL;}CTrayToolBar::~CTrayToolBar()
{
this->Detach();
}
BEGIN_MESSAGE_MAP(CTrayToolBar, CToolBarCtrl)
//{{AFX_MSG_MAP(CTrayToolBar)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CTrayToolBar message handlersvoid CTrayToolBar::ShowAll()
{
if(!m_handle) {AfxMessageBox("获取system tray失败!"); return;} int i = 0;
while(i < ICON_MAX )
{
this->ShowIcon(i,TRUE);
i++;
} Refresh();}void CTrayToolBar::ShowIcon(int index ,BOOL bShow)
{
if(!m_handle) {AfxMessageBox("获取system tray失败!"); return;}
//本来这里可以通过index来获得 nID,但是虽然函数成功,但idCommand却是错误的
/*
TBBUTTON * ptbbtn= new TBBUTTON;
this->SendMessage(TB_GETBUTTON,(WPARAM) index,(LPARAM) ptbbtn);
*/
if(bShow)
this->PostMessage(TB_HIDEBUTTON, index ,(LPARAM) MAKELONG(FALSE, 0));
else
this->PostMessage(TB_HIDEBUTTON, index ,(LPARAM) MAKELONG(TRUE, 0));
// delete ptbbtn;
}void CTrayToolBar::HideAll()
{ if(!m_handle) {AfxMessageBox("获取system tray失败!"); return;} int i = 0;
while(i < ICON_MAX )
{
this->ShowIcon(i,FALSE);
i++;
} Refresh();}void CTrayToolBar::Refresh()
{ NOTIFYICONDATAW Icon;
Icon.cbSize = sizeof( NOTIFYICONDATAW );
Icon.hWnd = this->m_hWnd ;
Icon.uID = 0;
Icon.uFlags = NIF_MESSAGE | NIF_TIP;
Icon.uCallbackMessage = WM_USER + 777;
Icon.hIcon = NULL;
Shell_NotifyIconW( NIM_ADD , &Icon );
Shell_NotifyIconW( NIM_DELETE , &Icon );}void CTrayToolBar::DeleteIcon(int index)
{
if(!m_handle) {AfxMessageBox("获取system tray失败!"); return;} this->DeleteButton(index);
Refresh();
}
int CTrayToolBar::GetCount()
{
if(!m_handle) {AfxMessageBox("获取system tray失败!"); return 0;}
return this->GetButtonCount();
}