// Remplacer les fonctions suivantes par les versions ci-présentes // Si une fonction est inexistante, la créer puis la compléter // Dans le xxxApp.cpp (xxx=projet), fichier principal: // Attention, il n'y a plus de CDoc ni CView BOOL xxxApp::InitInstance() { // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // You should modify this string to be something appropriate // such as the name of your company or organization. #ifdef _DEBUG SetRegistryKey("Micromega Debug"); // Set the database registry key for debug version #else SetRegistryKey(IDS_REGISTRY_KEY); // Set the database registry key for release version #endif LoadStdProfileSettings(0); // Load standard INI file options (including MRU) CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); return TRUE; } // Dans la classe CMainFrame, fenêtre principale: // Dans le .h, message map: les autres fonctions sont à créer par AppWizard afx_msg LONG OnMYWM_NOTIFYICON(WPARAM wParam, LPARAM lParam); // Dans le .cpp: // Dans le message map: ON_MESSAGE(MYWM_NOTIFYICON, OnMYWM_NOTIFYICON) // Dans le corp du fichier: BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs cs.style = WS_DISABLED; return CFrameWnd::PreCreateWindow(cs); } // Création fenêtre -> Lancer initialisations int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; NOTIFYICONDATA tnid; CString szDummy; // Mettre l'icône dans la barre de tâches szDummy.LoadString(IDS_SYSTRAY_TEXT); // Nom du toolTip tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = m_hWnd; tnid.uID = ID_ICON_SYSTRAY; // ID de l'icône dans le systray tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uCallbackMessage = MYWM_NOTIFYICON; // Message à envoyer pour un évènement tnid.hIcon = AfxGetApp()->LoadIcon(IDI_SYSTRAY); // Icône à afficher dans la barre de tâches lstrcpyn(tnid.szTip, (LPCTSTR)szDummy, sizeof(tnid.szTip)); if(!Shell_NotifyIcon(NIM_ADD, &tnid)) { // Message si pas OK AfxMessageBox(IDS_ERREUR_TASKBAR, MB_OK | MB_ICONEXCLAMATION); DestroyWindow(); } // Autres init nécessaires... return 0; } // Destruction fenêtre -> désinitialisations void CMainFrame::OnDestroy() { NOTIFYICONDATA tnid; // Vire l'icône de la barre de tâches tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = m_hWnd; tnid.uID = ID_ICON_SYSTRAY; // ID de l'icône dans le systray Shell_NotifyIcon(NIM_DELETE, &tnid); // Autres désinit nécessaires... CFrameWnd::OnDestroy(); } // Gestion des events souris sur l'icône dans la taskbar LONG CMainFrame::OnMYWM_NOTIFYICON(WPARAM wParam, LPARAM lParam) { if ((UINT) lParam == WM_LBUTTONDOWN) // 1 click bouton gauche { // Afficher menu popup CMenu menu; CPoint point; GetCursorPos(&point); if (menu.LoadMenu(IDR_MAINFRAME)) // Charge menu principal { CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); SetForegroundWindow(); pPopup->TrackPopupMenu( TPM_RIGHTALIGN | TPM_RIGHTBUTTON | TPM_LEFTBUTTON, point.x, point.y, (CWnd*)this); } } return 0; } // Ajouter en définitions générales du programme (StdAfx.h) #define MYWM_NOTIFYICON (WM_USER+1) #define ID_ICON_SYSTRAY 1 // Resources: IDS_REGISTRY_KEY // String pour clé Registry: 'Micromega Software System' IDS_SYSTRAY_TEXT // String pour texte Tooltip de l'icône dans le systray IDS_ERREUR_TASKBAR // Texte erreur icône systray: 'Erreur lors de l'initialisation de la barre de tâches.\nExécution de xxxxx impossible!!' IDR_MAINFRAME // Menu sur click icône systray IDI_SYSTRAY // Icône à afficher dans le systray // Modifications: rendre CMainFrame::CMainFrame 'public' ('protected' par défaut)