ARGH
[matches/honours.git] / research / transmission_spectroscopy / TOF / Win32++ / samples / TabDemo / src / Mainfrm.cpp
1 ////////////////////////////////////////////////////\r
2 // Mainfrm.cpp\r
3 \r
4 #include "stdafx.h"\r
5 #include "TabDemoApp.h"\r
6 #include "mainfrm.h"\r
7 #include "resource.h"\r
8 \r
9 \r
10 // Definitions for the CMainFrame class\r
11 CMainFrame::CMainFrame()\r
12 {\r
13         //Set the tab control as the fram's view window\r
14         SetView(m_View);\r
15 \r
16         // Set the registry key name, and load the initial window position\r
17         // Use a registry key name like "CompanyName\\Application"\r
18         LoadRegistrySettings(_T("Win32++\\Container Demo"));\r
19 }\r
20 \r
21 CMainFrame::~CMainFrame()\r
22 {\r
23         // Destructor for CMainFrame.\r
24 }\r
25 \r
26 BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)\r
27 {\r
28         // OnCommand responds to menu and and toolbar input\r
29 \r
30         UNREFERENCED_PARAMETER(lParam);\r
31 \r
32         switch(LOWORD(wParam))\r
33         {\r
34         case IDM_FILE_NEW:\r
35                 OnFileNew();\r
36                 return TRUE;\r
37         case IDM_FILE_CLOSE:\r
38                 OnFileClose();\r
39                 return TRUE;\r
40         case IDM_FILE_EXIT:\r
41                 // End the application\r
42                 ::PostMessage(m_hWnd, WM_CLOSE, 0, 0);\r
43                 return TRUE;\r
44         case IDM_NEW_FILES:\r
45                 m_View.AddTabPage(new CViewFiles, _T("Files"), IDI_FILEVIEW);\r
46                 return TRUE;\r
47         case IDM_NEW_CLASSES:\r
48                 m_View.AddTabPage(new CViewClasses, _T("Classes"), IDI_CLASSVIEW);\r
49                 return TRUE;\r
50         case IDM_TAB_TOP:\r
51                 OnTabsAtTop();\r
52                 return TRUE;\r
53         case IDM_TAB_BUTTONS:\r
54                 OnShowButtons();\r
55                 return TRUE;\r
56         case IDW_VIEW_STATUSBAR:\r
57                 OnViewStatusBar();\r
58                 return TRUE;\r
59         case IDW_VIEW_TOOLBAR:\r
60                 OnViewToolBar();\r
61                 return TRUE;\r
62         case IDM_HELP_ABOUT:\r
63                 // Display the help dialog\r
64                 OnHelp();\r
65                 return TRUE;\r
66         }\r
67 \r
68         return FALSE;\r
69 }\r
70 \r
71 void CMainFrame::OnFileClose()\r
72 {\r
73         int iTab = m_View.GetCurSel();\r
74 \r
75         if (iTab >= 0)\r
76                 m_View.RemoveTabPage(iTab);\r
77 }\r
78 \r
79 void CMainFrame::OnFileNew()\r
80 {\r
81         // Creates the popup menu when the "New" toolbar button is pressed\r
82 \r
83         // Position the popup menu\r
84         CToolBar& TB = GetToolBar();\r
85         RECT rc = TB.GetItemRect(TB.CommandToIndex(IDM_FILE_NEW));\r
86         ::MapWindowPoints(GetToolBar(), NULL, (LPPOINT)&rc, 2);\r
87 \r
88         TPMPARAMS tpm;\r
89         tpm.cbSize = sizeof(TPMPARAMS);\r
90         tpm.rcExclude = rc;\r
91 \r
92         // Load the popup menu\r
93         CMenu TopMenu(IDM_NEWMENU);\r
94         CMenu* pPopupMenu = TopMenu.GetSubMenu(0);\r
95 \r
96         // Start the popup menu\r
97         pPopupMenu->TrackPopupMenuEx(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, rc.left, rc.bottom, this, &tpm);\r
98 }\r
99 \r
100 void CMainFrame::OnCreate()\r
101 {\r
102         // OnCreate controls the way the frame is created.\r
103         // Overriding CFrame::Oncreate is optional.\r
104         // The default for the following variables is TRUE\r
105 \r
106         // m_bShowIndicatorStatus = FALSE;      // Don't show statusbar indicators\r
107         // m_bShowMenuStatus = FALSE;           // Don't show toolbar or menu status\r
108         // m_bUseReBar = FALSE;                         // Don't use rebars\r
109         // m_bUseThemes = FALSE;            // Don't use themes\r
110         // m_bUseToolBar = FALSE;                       // Don't use a toolbar\r
111         // m_bUseCustomDraw = FALSE;            // Don't use custom draw for menu items\r
112 \r
113         // call the base class function\r
114         CFrame::OnCreate();\r
115         m_View.SetFixedWidth(TRUE);\r
116         m_View.SetOwnerDraw(TRUE);\r
117 }\r
118 \r
119 void CMainFrame::OnInitialUpdate()\r
120 {       \r
121         // Add some tabs to the tab control\r
122         m_View.AddTabPage(new CViewClasses, _T("Classes"), IDI_CLASSVIEW);\r
123         m_View.AddTabPage(new CViewFiles, _T("Files"), IDI_FILEVIEW);\r
124         m_View.AddTabPage(new CViewClasses, _T("Classes"), IDI_CLASSVIEW);\r
125         m_View.AddTabPage(new CViewFiles, _T("Files"), IDI_FILEVIEW);\r
126         m_View.SelectPage(0);\r
127 \r
128         // PreCreate initially set the window as invisible, so show it now.\r
129         ShowWindow();\r
130 }\r
131 \r
132 void CMainFrame::OnShowButtons()\r
133 {\r
134         BOOL bShow = m_View.GetShowButtons();\r
135         m_View.SetShowButtons(!bShow);\r
136         UINT uCheck = bShow? MF_UNCHECKED : MF_CHECKED;\r
137         ::CheckMenuItem(GetFrameMenu(), IDM_TAB_BUTTONS, uCheck);\r
138         m_View.RedrawWindow();\r
139 }\r
140 \r
141 void CMainFrame::OnTabsAtTop()\r
142 {\r
143         BOOL bTop = m_View.GetTabsAtTop();\r
144         m_View.SetTabsAtTop(!bTop);\r
145         \r
146         UINT uCheck = (bTop)? MF_UNCHECKED : MF_CHECKED;\r
147         ::CheckMenuItem(GetFrameMenu(), IDM_TAB_TOP, uCheck);\r
148 }\r
149 \r
150 void CMainFrame::PreCreate(CREATESTRUCT &cs)\r
151 {\r
152         // Call the base class function first\r
153         CFrame::PreCreate(cs);\r
154         \r
155         // Hide the window initially by removing the WS_VISIBLE style\r
156         cs.style &= ~WS_VISIBLE;\r
157 }\r
158 \r
159 void CMainFrame::SetupToolBar()\r
160 {\r
161         // Set the Resource IDs for the toolbar buttons\r
162         AddToolBarButton( IDM_FILE_NEW          );\r
163         AddToolBarButton( IDM_FILE_OPEN,  FALSE );\r
164         AddToolBarButton( IDM_FILE_SAVE,  FALSE );\r
165         \r
166         AddToolBarButton( 0 );  // Separator\r
167         AddToolBarButton( IDM_EDIT_CUT,   FALSE );\r
168         AddToolBarButton( IDM_EDIT_COPY,  FALSE );\r
169         AddToolBarButton( IDM_EDIT_PASTE, FALSE );\r
170         \r
171         AddToolBarButton( 0 );  // Separator\r
172         AddToolBarButton( IDM_FILE_PRINT, FALSE );\r
173         \r
174         AddToolBarButton( 0 );  // Separator\r
175         AddToolBarButton( IDM_HELP_ABOUT        );\r
176 \r
177         // Set the Checkmarks in the menu\r
178         ::CheckMenuItem(GetFrameMenu(), IDM_TAB_BUTTONS, MF_UNCHECKED);\r
179 \r
180         // Add some extra icons for menu items\r
181         AddMenuIcon(IDM_NEW_FILES, ::LoadIcon(GetApp()->GetInstanceHandle(), MAKEINTRESOURCE(IDI_FILEVIEW)));\r
182         AddMenuIcon(IDM_NEW_CLASSES, ::LoadIcon(GetApp()->GetInstanceHandle(), MAKEINTRESOURCE(IDI_CLASSVIEW)));\r
183 }\r
184 \r
185 LRESULT CMainFrame::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
186 {\r
187 //      switch (uMsg)\r
188 //      {\r
189 //              Add case statements for each messages to be handled here\r
190 //      }\r
191 \r
192         // pass unhandled messages on for default processing\r
193         return WndProcDefault(uMsg, wParam, lParam);\r
194 }\r
195 \r

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