001
14.02.2003, 22:51 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo Lutz, siehe Bsp:
C++: |
void CTrayDlg::OnBnClickedTray() { ShowWindow(SW_HIDE); NOTIFYICONDATA icondata; ZeroMemory(&icondata, sizeof (NOTIFYICONDATA)); icondata.cbSize = sizeof (NOTIFYICONDATA); icondata.hWnd = this->m_hWnd; icondata.uID = 1; icondata.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP; icondata.uCallbackMessage = MYWM_NOTIFYICON; /* #define MYWM_NOTIFYICON WM_USER+1 */ icondata.hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance, MAKEINTRESOURCE (IDI_ICON1), IMAGE_ICON,16,16,LR_SHARED|LR_DEFAULTCOLOR); lstrcpyn(icondata.szTip, _T("Tray Demo"), sizeof(icondata.szTip)); Shell_NotifyIcon(NIM_ADD, &icondata); }
LRESULT CTrayDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { CMenu menue, *pMenu; CWnd* pTarget = AfxGetMainWnd(); switch (message){ case MYWM_NOTIFYICON: switch (LOWORD(lParam)){ case WM_RBUTTONUP: if (LOWORD(lParam) == WM_RBUTTONUP){ if (!menue.LoadMenu(IDR_MENU1)) return 0; if (!(pMenu = menue.GetSubMenu(0))) return 0; //::SetMenuDefaultItem(pMenu->m_hMenu, m_MenueItemID, m_MenueItemByPos); //Anzeigen CPoint pos; GetCursorPos(&pos); pTarget->SetForegroundWindow(); ::TrackPopupMenu(pMenu->m_hMenu, 0, pos.x, pos.y, 0, pTarget->GetSafeHwnd(), NULL); pTarget->PostMessage(WM_NULL, 0, 0); menue.DestroyMenu(); } break; case WM_LBUTTONUP: NOTIFYICONDATA iconData; iconData.cbSize = sizeof(NOTIFYICONDATA); iconData.hWnd = this->GetSafeHwnd(); iconData.uID = 1; Shell_NotifyIcon(NIM_DELETE, &iconData); ShowWindow(SW_SHOW); SetForegroundWindow(); break; } break; } return CDialog::WindowProc(message, wParam, lParam); }
|
Hab jetzt nicht geprüft warum bei Dir zwei Icon erscheinen(evtl. 32x32?). -- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 14.02.2003 um 22:53 Uhr von Uwe editiert. |