1 ///////////////////////////////
\r
6 #include "resource.h"
\r
9 // Definitions for the CView class
\r
10 void CView::Minimize()
\r
12 NOTIFYICONDATA nid = { 0 };
\r
13 nid.cbSize = sizeof(NOTIFYICONDATA);
\r
16 nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
\r
17 nid.uCallbackMessage = MSG_TRAYICON;
\r
18 nid.hIcon = (HICON) (::LoadImage (GetModuleHandle(NULL), MAKEINTRESOURCE (IDW_MAIN), IMAGE_ICON,
\r
19 ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0));
\r
21 lstrcpy(nid.szTip, _T("Tray Demo tooltip"));
\r
23 Shell_NotifyIcon(NIM_ADD, &nid);
\r
24 ShowWindow(SW_HIDE);
\r
25 m_IsMinimized = true;
\r
28 void CView::OnAbout()
\r
30 MessageBox(_T("Tray Example: Demonstrates minimizing a window to the tray."), _T("About Tray Example"), MB_OK | MB_ICONINFORMATION);
\r
33 void CView::OnCreate()
\r
35 // OnCreate is called automatically during window creation when a
\r
36 // WM_CREATE message received.
\r
38 // Tasks such as setting the icon, creating child windows, or anything
\r
39 // associated with creating windows are normally performed here.
\r
41 // Set the window's icon
\r
42 SetIconSmall(IDW_MAIN);
\r
43 SetIconLarge(IDW_MAIN);
\r
45 SetWindowText(LoadString(IDW_MAIN).c_str()); // Window title
\r
47 TRACE(_T("OnCreate\n"));
\r
50 BOOL CView::OnCommand(WPARAM wParam, LPARAM lParam)
\r
52 // OnCommand responds to menu and and toolbar input
\r
54 UNREFERENCED_PARAMETER(lParam);
\r
56 switch(LOWORD(wParam))
\r
62 // End the application
\r
65 case IDM_HELP_ABOUT:
\r
73 void CView::OnDestroy()
\r
75 // End the application when the window is destroyed
\r
76 ::PostQuitMessage(0);
\r
79 void CView::OnPaint(CDC* pDC)
\r
81 // OnPaint is called automatically whenever a part of the
\r
82 // window needs to be repainted.
\r
84 // Centre some text in our view window
\r
85 CRect rc = GetClientRect();
\r
86 CString cs = LoadString(IDW_MAIN);
\r
87 pDC->DrawText(cs, cs.GetLength(), rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
\r
90 void CView::OnInitialUpdate()
\r
92 // OnInitialUpdate is called after the window is created.
\r
93 // Tasks which are to be done after the window is created go here.
\r
95 TRACE(_T("OnInitialUpdate\n"));
\r
98 void CView::OnSize()
\r
100 // Force the window to be repainted during resizing
\r
104 void CView::OnTrayIcon(WPARAM wParam, LPARAM lParam)
\r
106 // For a NOTIFYICONDATA with uVersion= 0, wParam and lParam have the following values:
\r
107 // The wParam parameter contains the identifier of the taskbar icon in which the event occurred.
\r
108 // The lParam parameter holds the mouse or keyboard message associated with the event.
\r
109 if (wParam != IDW_MAIN)
\r
112 if (lParam == WM_LBUTTONUP)
\r
116 else if (lParam == WM_RBUTTONUP)
\r
118 CMenu TopMenu(IDM_MINIMIZED);
\r
119 CMenu* pSubMenu = TopMenu.GetSubMenu(0);
\r
121 SetForegroundWindow();
\r
122 CPoint pt = GetCursorPos();
\r
123 UINT uSelected = pSubMenu->TrackPopupMenu(TPM_RETURNCMD | TPM_NONOTIFY, pt.x, pt.y, this, NULL);
\r
127 case IDM_MIN_RESTORE:
\r
130 case IDM_MIN_ABOUT:
\r
140 void CView::PreCreate(CREATESTRUCT& cs)
\r
142 // This function will be called automatically by Create. It provides an
\r
143 // opportunity to set various window parameters prior to window creation.
\r
144 // You are not required to set these parameters, any paramters which
\r
145 // aren't specified are set to reasonable defaults.
\r
147 // Set some optional parameters for the window
\r
148 cs.dwExStyle = WS_EX_CLIENTEDGE; // Extended style
\r
149 cs.lpszClass = _T("View Window"); // Window Class
\r
150 cs.x = 50; // top x
\r
151 cs.y = 50; // top y
\r
152 cs.cx = 400; // width
\r
153 cs.cy = 300; // height
\r
154 cs.hMenu = LoadMenu(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_MAIN));
\r
157 void CView::Restore()
\r
159 NOTIFYICONDATA nid = { 0 };
\r
160 nid.cbSize = sizeof(NOTIFYICONDATA);
\r
162 nid.uID = IDW_MAIN;
\r
163 Shell_NotifyIcon(NIM_DELETE, &nid);
\r
164 ShowWindow(SW_SHOW);
\r
165 m_IsMinimized = false;
\r
168 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
170 // This function is our message procedure. We process the messages for
\r
171 // the view window here. Unprocessed messages are passed on for
\r
172 // default processing.
\r
182 case WM_SYSCOMMAND:
\r
183 if (wParam == SC_MINIMIZE) // User pressed minimize button
\r
190 OnTrayIcon(wParam, lParam);
\r
194 // pass unhandled messages on for default processing
\r
195 return WndProcDefault(uMsg, wParam, lParam);
\r