Commit before breaking everything
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / samples / Tray / src / View.cpp
diff --git a/research/transmission_spectroscopy/TOF/Win32++/samples/Tray/src/View.cpp b/research/transmission_spectroscopy/TOF/Win32++/samples/Tray/src/View.cpp
new file mode 100644 (file)
index 0000000..c0cc9c5
--- /dev/null
@@ -0,0 +1,196 @@
+///////////////////////////////\r
+// View.cpp\r
+\r
+#include "stdafx.h"\r
+#include "View.h"\r
+#include "resource.h"\r
+\r
+\r
+// Definitions for the CView class\r
+void CView::Minimize()\r
+{\r
+    NOTIFYICONDATA nid = { 0 };\r
+    nid.cbSize = sizeof(NOTIFYICONDATA);\r
+    nid.hWnd = m_hWnd;\r
+    nid.uID = IDW_MAIN;\r
+    nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;\r
+    nid.uCallbackMessage = MSG_TRAYICON;\r
+       nid.hIcon = (HICON) (::LoadImage (GetModuleHandle(NULL), MAKEINTRESOURCE (IDW_MAIN), IMAGE_ICON,\r
+               ::GetSystemMetrics (SM_CXSMICON), ::GetSystemMetrics (SM_CYSMICON), 0));\r
+\r
+       lstrcpy(nid.szTip, _T("Tray Demo tooltip"));\r
+\r
+    Shell_NotifyIcon(NIM_ADD, &nid);\r
+    ShowWindow(SW_HIDE);\r
+    m_IsMinimized = true;\r
+}\r
+\r
+void CView::OnAbout()\r
+{\r
+       MessageBox(_T("Tray Example: Demonstrates minimizing a window to the tray."), _T("About Tray Example"), MB_OK | MB_ICONINFORMATION);\r
+}\r
+\r
+void CView::OnCreate()\r
+{\r
+       // OnCreate is called automatically during window creation when a\r
+       // WM_CREATE message received.\r
+\r
+       // Tasks such as setting the icon, creating child windows, or anything\r
+       // associated with creating windows are normally performed here.\r
+\r
+       // Set the window's icon\r
+       SetIconSmall(IDW_MAIN);\r
+       SetIconLarge(IDW_MAIN);\r
+\r
+       SetWindowText(LoadString(IDW_MAIN).c_str());            // Window title\r
+\r
+       TRACE(_T("OnCreate\n"));\r
+}\r
+\r
+BOOL CView::OnCommand(WPARAM wParam, LPARAM lParam)\r
+{\r
+       // OnCommand responds to menu and and toolbar input\r
+\r
+       UNREFERENCED_PARAMETER(lParam);\r
+\r
+       switch(LOWORD(wParam))\r
+       {\r
+       case IDM_MINTOTRAY:\r
+               Minimize();\r
+               return TRUE;\r
+       case IDM_FILE_EXIT:\r
+               // End the application\r
+               PostQuitMessage(0);\r
+               return TRUE;\r
+       case IDM_HELP_ABOUT:\r
+               OnAbout();\r
+               return TRUE;\r
+       }\r
+\r
+       return FALSE;\r
+}\r
+\r
+void CView::OnDestroy()\r
+{\r
+       // End the application when the window is destroyed\r
+       ::PostQuitMessage(0);\r
+}\r
+\r
+void CView::OnPaint(CDC* pDC)\r
+{\r
+       // OnPaint is called automatically whenever a part of the\r
+       // window needs to be repainted.\r
+\r
+       // Centre some text in our view window\r
+       CRect rc = GetClientRect();\r
+       CString cs = LoadString(IDW_MAIN);\r
+       pDC->DrawText(cs, cs.GetLength(), rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);\r
+}\r
+\r
+void CView::OnInitialUpdate()\r
+{\r
+       // OnInitialUpdate is called after the window is created.\r
+       // Tasks which are to be done after the window is created go here.\r
+\r
+       TRACE(_T("OnInitialUpdate\n"));\r
+}\r
+\r
+void CView::OnSize()\r
+{\r
+       // Force the window to be repainted during resizing\r
+       Invalidate();\r
+}\r
+\r
+void CView::OnTrayIcon(WPARAM wParam, LPARAM lParam)\r
+{\r
+       // For a NOTIFYICONDATA with uVersion= 0, wParam and lParam have the following values:\r
+       // The wParam parameter contains the identifier of the taskbar icon in which the event occurred.\r
+       // The lParam parameter holds the mouse or keyboard message associated with the event.\r
+    if (wParam != IDW_MAIN)\r
+               return;\r
+\r
+       if (lParam == WM_LBUTTONUP)\r
+    {\r
+        Restore();\r
+    }\r
+    else if (lParam == WM_RBUTTONUP)\r
+    {\r
+               CMenu TopMenu(IDM_MINIMIZED);\r
+               CMenu* pSubMenu = TopMenu.GetSubMenu(0);\r
+\r
+        SetForegroundWindow();\r
+               CPoint pt = GetCursorPos();\r
+               UINT uSelected = pSubMenu->TrackPopupMenu(TPM_RETURNCMD | TPM_NONOTIFY, pt.x, pt.y, this, NULL);\r
+\r
+               switch (uSelected)\r
+               {\r
+               case IDM_MIN_RESTORE:\r
+                       Restore();\r
+                       break;\r
+               case IDM_MIN_ABOUT:\r
+                       OnAbout();\r
+                       break;\r
+               case IDM_MIN_EXIT:\r
+                       Destroy();\r
+                       break;\r
+               }\r
+    }\r
+}\r
+\r
+void CView::PreCreate(CREATESTRUCT& cs)\r
+{\r
+       // This function will be called automatically by Create. It provides an\r
+       // opportunity to set various window parameters prior to window creation.\r
+       // You are not required to set these parameters, any paramters which\r
+       // aren't specified are set to reasonable defaults.\r
+\r
+       // Set some optional parameters for the window\r
+       cs.dwExStyle = WS_EX_CLIENTEDGE;                // Extended style\r
+       cs.lpszClass = _T("View Window");               // Window Class\r
+       cs.x = 50;                                                              // top x\r
+       cs.y = 50;                                                              // top y\r
+       cs.cx = 400;                                                    // width\r
+       cs.cy = 300;                                                    // height\r
+       cs.hMenu =  LoadMenu(GetApp()->GetResourceHandle(), MAKEINTRESOURCE(IDW_MAIN));\r
+}\r
+\r
+void CView::Restore()\r
+{\r
+    NOTIFYICONDATA nid = { 0 };\r
+    nid.cbSize = sizeof(NOTIFYICONDATA);\r
+    nid.hWnd = m_hWnd;\r
+    nid.uID = IDW_MAIN;\r
+    Shell_NotifyIcon(NIM_DELETE, &nid);\r
+    ShowWindow(SW_SHOW);\r
+    m_IsMinimized = false;\r
+}\r
+\r
+LRESULT CView::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+{\r
+       // This function is our message procedure. We process the messages for\r
+       // the view window here.  Unprocessed messages are passed on for\r
+       //  default processing.\r
+\r
+       switch(uMsg)\r
+       {\r
+       case WM_DESTROY:\r
+               OnDestroy();\r
+               return 0;\r
+       case WM_SIZE:\r
+               OnSize();\r
+               break;\r
+       case WM_SYSCOMMAND:\r
+               if (wParam == SC_MINIMIZE)      // User pressed minimize button\r
+               {\r
+                       Minimize();\r
+                       return 0;\r
+               }\r
+               break;\r
+       case MSG_TRAYICON:\r
+               OnTrayIcon(wParam, lParam);\r
+               break;\r
+       }\r
+\r
+       // pass unhandled messages on for default processing\r
+       return WndProcDefault(uMsg, wParam, lParam);\r
+}\r

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