c0cc9c55885c235c7d8597fa90786ca6d4e28fcd
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / samples / Tray / src / View.cpp
1 ///////////////////////////////\r
2 // View.cpp\r
3 \r
4 #include "stdafx.h"\r
5 #include "View.h"\r
6 #include "resource.h"\r
7 \r
8 \r
9 // Definitions for the CView class\r
10 void CView::Minimize()\r
11 {\r
12     NOTIFYICONDATA nid = { 0 };\r
13     nid.cbSize = sizeof(NOTIFYICONDATA);\r
14     nid.hWnd = m_hWnd;\r
15     nid.uID = IDW_MAIN;\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
20 \r
21         lstrcpy(nid.szTip, _T("Tray Demo tooltip"));\r
22 \r
23     Shell_NotifyIcon(NIM_ADD, &nid);\r
24     ShowWindow(SW_HIDE);\r
25     m_IsMinimized = true;\r
26 }\r
27 \r
28 void CView::OnAbout()\r
29 {\r
30         MessageBox(_T("Tray Example: Demonstrates minimizing a window to the tray."), _T("About Tray Example"), MB_OK | MB_ICONINFORMATION);\r
31 }\r
32 \r
33 void CView::OnCreate()\r
34 {\r
35         // OnCreate is called automatically during window creation when a\r
36         // WM_CREATE message received.\r
37 \r
38         // Tasks such as setting the icon, creating child windows, or anything\r
39         // associated with creating windows are normally performed here.\r
40 \r
41         // Set the window's icon\r
42         SetIconSmall(IDW_MAIN);\r
43         SetIconLarge(IDW_MAIN);\r
44 \r
45         SetWindowText(LoadString(IDW_MAIN).c_str());            // Window title\r
46 \r
47         TRACE(_T("OnCreate\n"));\r
48 }\r
49 \r
50 BOOL CView::OnCommand(WPARAM wParam, LPARAM lParam)\r
51 {\r
52         // OnCommand responds to menu and and toolbar input\r
53 \r
54         UNREFERENCED_PARAMETER(lParam);\r
55 \r
56         switch(LOWORD(wParam))\r
57         {\r
58         case IDM_MINTOTRAY:\r
59                 Minimize();\r
60                 return TRUE;\r
61         case IDM_FILE_EXIT:\r
62                 // End the application\r
63                 PostQuitMessage(0);\r
64                 return TRUE;\r
65         case IDM_HELP_ABOUT:\r
66                 OnAbout();\r
67                 return TRUE;\r
68         }\r
69 \r
70         return FALSE;\r
71 }\r
72 \r
73 void CView::OnDestroy()\r
74 {\r
75         // End the application when the window is destroyed\r
76         ::PostQuitMessage(0);\r
77 }\r
78 \r
79 void CView::OnPaint(CDC* pDC)\r
80 {\r
81         // OnPaint is called automatically whenever a part of the\r
82         // window needs to be repainted.\r
83 \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
88 }\r
89 \r
90 void CView::OnInitialUpdate()\r
91 {\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
94 \r
95         TRACE(_T("OnInitialUpdate\n"));\r
96 }\r
97 \r
98 void CView::OnSize()\r
99 {\r
100         // Force the window to be repainted during resizing\r
101         Invalidate();\r
102 }\r
103 \r
104 void CView::OnTrayIcon(WPARAM wParam, LPARAM lParam)\r
105 {\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
110                 return;\r
111 \r
112         if (lParam == WM_LBUTTONUP)\r
113     {\r
114         Restore();\r
115     }\r
116     else if (lParam == WM_RBUTTONUP)\r
117     {\r
118                 CMenu TopMenu(IDM_MINIMIZED);\r
119                 CMenu* pSubMenu = TopMenu.GetSubMenu(0);\r
120 \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
124 \r
125                 switch (uSelected)\r
126                 {\r
127                 case IDM_MIN_RESTORE:\r
128                         Restore();\r
129                         break;\r
130                 case IDM_MIN_ABOUT:\r
131                         OnAbout();\r
132                         break;\r
133                 case IDM_MIN_EXIT:\r
134                         Destroy();\r
135                         break;\r
136                 }\r
137     }\r
138 }\r
139 \r
140 void CView::PreCreate(CREATESTRUCT& cs)\r
141 {\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
146 \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
155 }\r
156 \r
157 void CView::Restore()\r
158 {\r
159     NOTIFYICONDATA nid = { 0 };\r
160     nid.cbSize = sizeof(NOTIFYICONDATA);\r
161     nid.hWnd = m_hWnd;\r
162     nid.uID = IDW_MAIN;\r
163     Shell_NotifyIcon(NIM_DELETE, &nid);\r
164     ShowWindow(SW_SHOW);\r
165     m_IsMinimized = false;\r
166 }\r
167 \r
168 LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
169 {\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
173 \r
174         switch(uMsg)\r
175         {\r
176         case WM_DESTROY:\r
177                 OnDestroy();\r
178                 return 0;\r
179         case WM_SIZE:\r
180                 OnSize();\r
181                 break;\r
182         case WM_SYSCOMMAND:\r
183                 if (wParam == SC_MINIMIZE)      // User pressed minimize button\r
184                 {\r
185                         Minimize();\r
186                         return 0;\r
187                 }\r
188                 break;\r
189         case MSG_TRAYICON:\r
190                 OnTrayIcon(wParam, lParam);\r
191                 break;\r
192         }\r
193 \r
194         // pass unhandled messages on for default processing\r
195         return WndProcDefault(uMsg, wParam, lParam);\r
196 }\r

UCC git Repository :: git.ucc.asn.au