1 ////////////////////////////////////////////////////
\r
6 #include "resource.h"
\r
9 // Definitions for the CMainFrame class
\r
10 CMainFrame::CMainFrame()
\r
12 // Constructor for CMainFrame. Its called after CFrame's constructor
\r
14 //Set m_MyView as the view window of the frame
\r
17 // Set the registry key name, and load the initial window position
\r
18 // Use a registry key name like "CompanyName\\Application"
\r
19 LoadRegistrySettings(_T("Win32++\\Fast GDI Demo"));
\r
21 // Load the settings from the registry with 4 MRU entries
\r
22 LoadRegistryMRUSettings(4);
\r
25 CMainFrame::~CMainFrame()
\r
27 // Destructor for CMainFrame.
\r
30 void CMainFrame::OnAdjustImage()
\r
32 if (GetMyView().GetImage())
\r
34 // Initiate the Colour Adjust Dialog
\r
35 CColourDialog Dialog(IDD_DIALOG1);
\r
39 MessageBox(_T("Open a Bitmap file first!"), _T("Error"), MB_OK);
\r
42 void CMainFrame::ModifyBitmap(int cRed, int cGreen, int cBlue, BOOL bGray)
\r
44 TintBitmap(FromHandle(GetMyView().GetImage()), cRed, cGreen, cBlue);
\r
45 if (bGray) GrayScaleBitmap(FromHandle(GetMyView().GetImage()));
\r
47 GetMyView().RedrawWindow(0, 0, RDW_NOERASE|RDW_INVALIDATE|RDW_UPDATENOW);
\r
50 BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
\r
52 // OnCommand responds to menu and and toolbar input
\r
54 switch(LOWORD(wParam))
\r
65 case IDM_FILE_SAVEAS:
\r
69 // End the application
\r
70 ::PostMessage(m_hWnd, WM_CLOSE, 0, 0);
\r
72 case IDM_IMAGE_ADJUST:
\r
75 case IDW_VIEW_STATUSBAR:
\r
78 case IDW_VIEW_TOOLBAR:
\r
81 case IDM_HELP_ABOUT:
\r
82 // Display the help dialog
\r
85 case IDW_FILE_MRU_FILE1:
\r
86 case IDW_FILE_MRU_FILE2:
\r
87 case IDW_FILE_MRU_FILE3:
\r
88 case IDW_FILE_MRU_FILE4:
\r
89 OnFileOpenMRU(wParam, lParam);
\r
96 void CMainFrame::OnCreate()
\r
98 // OnCreate controls the way the frame is created.
\r
99 // Overriding CFrame::Oncreate is optional.
\r
100 // The default for the following variables is TRUE
\r
102 // m_bShowIndicatorStatus = FALSE; // Don't show statusbar indicators
\r
103 // m_bShowMenuStatus = FALSE; // Don't show toolbar or menu status
\r
104 // m_bUseReBar = FALSE; // Don't use rebars
\r
105 // m_bUseThemes = FALSE; // Don't use themes
\r
106 // m_bUseToolBar = FALSE; // Don't use a toolbar
\r
107 // m_bUseCustomDraw = FALSE; // Don't use custom draw for menu items
\r
109 // call the base class function
\r
110 CFrame::OnCreate();
\r
113 void CMainFrame::OnFileNew()
\r
115 CToolBar& TB = GetToolBar();
\r
116 TB.DisableButton(IDM_FILE_SAVEAS);
\r
117 TB.DisableButton(IDM_IMAGE_ADJUST);
\r
118 m_MyView.FileOpen(NULL);
\r
119 m_MyView.Invalidate();
\r
122 SetWindowText(_T("FastGDI"));
\r
125 void CMainFrame::OnFileOpen()
\r
128 CString str = File.OpenFileDialog(0, OFN_FILEMUSTEXIST, _T("Scribble Files (*.bmp)\0*.bmp\0\0"), this);
\r
129 if (!str.IsEmpty())
\r
132 m_MyView.FileOpen(str);
\r
134 // Save the filename
\r
138 // Turn on the ToolBar adjust button
\r
139 CToolBar& TB = GetToolBar();
\r
140 TB.EnableButton(IDM_FILE_SAVEAS);
\r
141 TB.EnableButton(IDM_IMAGE_ADJUST);
\r
142 EnableMenuItem(GetFrameMenu(), IDM_IMAGE_ADJUST, MF_BYCOMMAND | MF_ENABLED);
\r
144 // Resize the frame to match the bitmap
\r
145 if (GetMyView().GetImage())
\r
147 GetMyView().ShowScrollBar(SB_HORZ, FALSE);
\r
148 GetMyView().ShowScrollBar(SB_VERT, FALSE);
\r
149 CRect rcImage = GetMyView().GetImageRect();
\r
150 AdjustFrameRect(rcImage);
\r
153 GetMyView().RedrawWindow(0, 0, RDW_NOERASE|RDW_INVALIDATE|RDW_UPDATENOW);
\r
156 CString str = _T("FastGDI - ") + m_PathName;
\r
157 SetWindowText(str);
\r
161 BOOL CMainFrame::OnFileOpenMRU(WPARAM wParam, LPARAM lParam)
\r
163 UNREFERENCED_PARAMETER(lParam);
\r
165 UINT nMRUIndex = LOWORD(wParam) - IDW_FILE_MRU_FILE1;
\r
166 CString strMRUText = GetMRUEntry(nMRUIndex);
\r
167 CToolBar& TB = GetToolBar();
\r
169 if (m_MyView.FileOpen(strMRUText))
\r
171 m_PathName = strMRUText;
\r
172 TB.EnableButton(IDM_FILE_SAVEAS);
\r
173 TB.EnableButton(IDM_IMAGE_ADJUST);
\r
175 // Adjust the window size
\r
176 CRect rcImage = GetMyView().GetImageRect();
\r
177 AdjustFrameRect(rcImage);
\r
181 RemoveMRUEntry(strMRUText);
\r
182 TB.DisableButton(IDM_FILE_SAVEAS);
\r
183 TB.DisableButton(IDM_IMAGE_ADJUST);
\r
186 // Resize the frame to match the bitmap
\r
187 if (GetMyView().GetImage())
\r
189 GetMyView().ShowScrollBar(SB_HORZ, FALSE);
\r
190 GetMyView().ShowScrollBar(SB_VERT, FALSE);
\r
191 CRect rcImage = GetMyView().GetImageRect();
\r
192 AdjustFrameRect(rcImage);
\r
195 GetMyView().RedrawWindow(0, 0, RDW_NOERASE|RDW_INVALIDATE|RDW_UPDATENOW);
\r
198 CString str = _T("FastGDI - ") + m_PathName;
\r
199 SetWindowText(str);
\r
203 void CMainFrame::OnFileSave()
\r
205 if (!m_PathName.IsEmpty())
\r
207 CString str = m_PathName + _T(" already exists.\nDo you want to replace it?");
\r
209 if (IDYES == MessageBox(str, _T("FileSaveAs"), MB_YESNO | MB_ICONWARNING))
\r
210 m_MyView.FileSave(m_PathName);
\r
214 void CMainFrame::OnFileSaveAs()
\r
217 CString str = File.SaveFileDialog(0, OFN_OVERWRITEPROMPT, _T("Bitmap Files (*.bmp)\0*.bmp\0\0"), _T("bmp"), 0);
\r
218 if (!str.IsEmpty())
\r
222 CString Title = _T("FastGDI - ") + m_PathName;
\r
223 SetWindowText(Title);
\r
225 // Save the file name
\r
226 m_MyView.FileSave(str);
\r
230 void CMainFrame::OnInitialUpdate()
\r
232 // The frame is now created.
\r
233 // Place any additional startup code here.
\r
235 TRACE(_T("Frame created\n"));
\r
238 inline void CMainFrame::OnMenuUpdate(UINT nID)
\r
239 // Called when menu items are about to be displayed
\r
241 BOOL IsImageLoaded = (BOOL)GetMyView().GetImage();
\r
245 case IDM_FILE_SAVE:
\r
246 EnableMenuItem(GetFrameMenu(), IDM_FILE_SAVE, IsImageLoaded? MF_ENABLED : MF_GRAYED);
\r
248 case IDM_FILE_SAVEAS:
\r
249 EnableMenuItem(GetFrameMenu(), IDM_FILE_SAVEAS, IsImageLoaded? MF_ENABLED : MF_GRAYED);
\r
251 case IDM_IMAGE_ADJUST:
\r
252 EnableMenuItem(GetFrameMenu(), IDM_IMAGE_ADJUST, IsImageLoaded? MF_ENABLED : MF_GRAYED);
\r
257 void CMainFrame::SetupToolBar()
\r
259 // Set the Resource IDs for the toolbar buttons
\r
260 AddToolBarButton( IDM_FILE_NEW );
\r
261 AddToolBarButton( IDM_FILE_OPEN );
\r
262 AddToolBarButton( IDM_FILE_SAVEAS, FALSE );
\r
264 AddToolBarButton( 0 ); // Separator
\r
265 AddToolBarButton( IDM_IMAGE_ADJUST, FALSE );
\r
267 AddToolBarButton( 0 ); // Separator
\r
268 AddToolBarButton( IDM_HELP_ABOUT );
\r
270 // Use large toolbar buttons
\r
271 SetToolBarImages(RGB(192, 192, 192), IDB_TOOLBAR_BIG, 0, 0);
\r
274 LRESULT CMainFrame::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
\r
278 //Additional messages to be handled go here
\r
281 // pass unhandled messages on for default processing
\r
282 return WndProcDefault(uMsg, wParam, lParam);
\r