--- /dev/null
+////////////////////////////////////////////////////\r
+// Mainfrm.cpp\r
+\r
+#include "stdafx.h"\r
+#include "mainfrm.h"\r
+#include "resource.h"\r
+\r
+\r
+// Definitions for the CMainFrame class\r
+CMainFrame::CMainFrame()\r
+{\r
+ // Constructor for CMainFrame. Its called after CFrame's constructor\r
+\r
+ //Set m_MyView as the view window of the frame\r
+ SetView(m_MyView);\r
+\r
+ // Set the registry key name, and load the initial window position\r
+ // Use a registry key name like "CompanyName\\Application"\r
+ LoadRegistrySettings(_T("Win32++\\Fast GDI Demo"));\r
+\r
+ // Load the settings from the registry with 4 MRU entries\r
+ LoadRegistryMRUSettings(4);\r
+}\r
+\r
+CMainFrame::~CMainFrame()\r
+{\r
+ // Destructor for CMainFrame.\r
+}\r
+\r
+void CMainFrame::OnAdjustImage()\r
+{\r
+ if (GetMyView().GetImage())\r
+ {\r
+ // Initiate the Colour Adjust Dialog\r
+ CColourDialog Dialog(IDD_DIALOG1);\r
+ Dialog.DoModal();\r
+ }\r
+ else\r
+ MessageBox(_T("Open a Bitmap file first!"), _T("Error"), MB_OK);\r
+}\r
+\r
+void CMainFrame::ModifyBitmap(int cRed, int cGreen, int cBlue, BOOL bGray)\r
+{\r
+ TintBitmap(FromHandle(GetMyView().GetImage()), cRed, cGreen, cBlue);\r
+ if (bGray) GrayScaleBitmap(FromHandle(GetMyView().GetImage()));\r
+\r
+ GetMyView().RedrawWindow(0, 0, RDW_NOERASE|RDW_INVALIDATE|RDW_UPDATENOW);\r
+}\r
+\r
+BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)\r
+{\r
+ // OnCommand responds to menu and and toolbar input\r
+\r
+ switch(LOWORD(wParam))\r
+ {\r
+ case IDM_FILE_NEW:\r
+ OnFileNew();\r
+ return TRUE;\r
+ case IDM_FILE_OPEN:\r
+ OnFileOpen();\r
+ return TRUE;\r
+ case IDM_FILE_SAVE:\r
+ OnFileSave();\r
+ return TRUE;\r
+ case IDM_FILE_SAVEAS:\r
+ OnFileSaveAs();\r
+ return TRUE;\r
+ case IDM_FILE_EXIT:\r
+ // End the application\r
+ ::PostMessage(m_hWnd, WM_CLOSE, 0, 0);\r
+ return TRUE;\r
+ case IDM_IMAGE_ADJUST:\r
+ OnAdjustImage();\r
+ return TRUE;\r
+ case IDW_VIEW_STATUSBAR:\r
+ OnViewStatusBar();\r
+ return TRUE;\r
+ case IDW_VIEW_TOOLBAR:\r
+ OnViewToolBar();\r
+ return TRUE;\r
+ case IDM_HELP_ABOUT:\r
+ // Display the help dialog\r
+ OnHelp();\r
+ return TRUE;\r
+ case IDW_FILE_MRU_FILE1:\r
+ case IDW_FILE_MRU_FILE2:\r
+ case IDW_FILE_MRU_FILE3:\r
+ case IDW_FILE_MRU_FILE4:\r
+ OnFileOpenMRU(wParam, lParam);\r
+ return TRUE;\r
+ }\r
+\r
+ return FALSE;\r
+}\r
+\r
+void CMainFrame::OnCreate()\r
+{\r
+ // OnCreate controls the way the frame is created.\r
+ // Overriding CFrame::Oncreate is optional.\r
+ // The default for the following variables is TRUE\r
+\r
+ // m_bShowIndicatorStatus = FALSE; // Don't show statusbar indicators\r
+ // m_bShowMenuStatus = FALSE; // Don't show toolbar or menu status\r
+ // m_bUseReBar = FALSE; // Don't use rebars\r
+ // m_bUseThemes = FALSE; // Don't use themes\r
+ // m_bUseToolBar = FALSE; // Don't use a toolbar\r
+ // m_bUseCustomDraw = FALSE; // Don't use custom draw for menu items\r
+\r
+ // call the base class function\r
+ CFrame::OnCreate();\r
+}\r
+\r
+void CMainFrame::OnFileNew()\r
+{\r
+ CToolBar& TB = GetToolBar();\r
+ TB.DisableButton(IDM_FILE_SAVEAS);\r
+ TB.DisableButton(IDM_IMAGE_ADJUST);\r
+ m_MyView.FileOpen(NULL);\r
+ m_MyView.Invalidate();\r
+\r
+ // Set the caption\r
+ SetWindowText(_T("FastGDI"));\r
+}\r
+\r
+void CMainFrame::OnFileOpen()\r
+{\r
+ CFile File;\r
+ CString str = File.OpenFileDialog(0, OFN_FILEMUSTEXIST, _T("Scribble Files (*.bmp)\0*.bmp\0\0"), this);\r
+ if (!str.IsEmpty())\r
+ {\r
+ // Load the bitmap\r
+ m_MyView.FileOpen(str);\r
+\r
+ // Save the filename\r
+ m_PathName = str;\r
+ AddMRUEntry(str);\r
+\r
+ // Turn on the ToolBar adjust button\r
+ CToolBar& TB = GetToolBar();\r
+ TB.EnableButton(IDM_FILE_SAVEAS);\r
+ TB.EnableButton(IDM_IMAGE_ADJUST);\r
+ EnableMenuItem(GetFrameMenu(), IDM_IMAGE_ADJUST, MF_BYCOMMAND | MF_ENABLED);\r
+\r
+ // Resize the frame to match the bitmap\r
+ if (GetMyView().GetImage())\r
+ {\r
+ GetMyView().ShowScrollBar(SB_HORZ, FALSE);\r
+ GetMyView().ShowScrollBar(SB_VERT, FALSE);\r
+ CRect rcImage = GetMyView().GetImageRect();\r
+ AdjustFrameRect(rcImage);\r
+ }\r
+\r
+ GetMyView().RedrawWindow(0, 0, RDW_NOERASE|RDW_INVALIDATE|RDW_UPDATENOW);\r
+\r
+ // Set the caption\r
+ CString str = _T("FastGDI - ") + m_PathName;\r
+ SetWindowText(str);\r
+ }\r
+}\r
+\r
+BOOL CMainFrame::OnFileOpenMRU(WPARAM wParam, LPARAM lParam)\r
+{\r
+ UNREFERENCED_PARAMETER(lParam);\r
+\r
+ UINT nMRUIndex = LOWORD(wParam) - IDW_FILE_MRU_FILE1;\r
+ CString strMRUText = GetMRUEntry(nMRUIndex);\r
+ CToolBar& TB = GetToolBar();\r
+\r
+ if (m_MyView.FileOpen(strMRUText))\r
+ {\r
+ m_PathName = strMRUText;\r
+ TB.EnableButton(IDM_FILE_SAVEAS);\r
+ TB.EnableButton(IDM_IMAGE_ADJUST);\r
+\r
+ // Adjust the window size\r
+ CRect rcImage = GetMyView().GetImageRect();\r
+ AdjustFrameRect(rcImage);\r
+ }\r
+ else\r
+ {\r
+ RemoveMRUEntry(strMRUText);\r
+ TB.DisableButton(IDM_FILE_SAVEAS);\r
+ TB.DisableButton(IDM_IMAGE_ADJUST);\r
+ }\r
+\r
+ // Resize the frame to match the bitmap\r
+ if (GetMyView().GetImage())\r
+ {\r
+ GetMyView().ShowScrollBar(SB_HORZ, FALSE);\r
+ GetMyView().ShowScrollBar(SB_VERT, FALSE);\r
+ CRect rcImage = GetMyView().GetImageRect();\r
+ AdjustFrameRect(rcImage);\r
+ }\r
+\r
+ GetMyView().RedrawWindow(0, 0, RDW_NOERASE|RDW_INVALIDATE|RDW_UPDATENOW);\r
+\r
+ // Set the caption\r
+ CString str = _T("FastGDI - ") + m_PathName;\r
+ SetWindowText(str);\r
+ return TRUE;\r
+}\r
+\r
+void CMainFrame::OnFileSave()\r
+{\r
+ if (!m_PathName.IsEmpty())\r
+ {\r
+ CString str = m_PathName + _T(" already exists.\nDo you want to replace it?");\r
+\r
+ if (IDYES == MessageBox(str, _T("FileSaveAs"), MB_YESNO | MB_ICONWARNING))\r
+ m_MyView.FileSave(m_PathName);\r
+ }\r
+}\r
+\r
+void CMainFrame::OnFileSaveAs()\r
+{\r
+ CFile File;\r
+ CString str = File.SaveFileDialog(0, OFN_OVERWRITEPROMPT, _T("Bitmap Files (*.bmp)\0*.bmp\0\0"), _T("bmp"), 0);\r
+ if (!str.IsEmpty())\r
+ {\r
+ // Set the caption\r
+ m_PathName = str;\r
+ CString Title = _T("FastGDI - ") + m_PathName;\r
+ SetWindowText(Title);\r
+\r
+ // Save the file name\r
+ m_MyView.FileSave(str);\r
+ }\r
+}\r
+\r
+void CMainFrame::OnInitialUpdate()\r
+{\r
+ // The frame is now created.\r
+ // Place any additional startup code here.\r
+\r
+ TRACE(_T("Frame created\n"));\r
+}\r
+\r
+inline void CMainFrame::OnMenuUpdate(UINT nID)\r
+// Called when menu items are about to be displayed\r
+{\r
+ BOOL IsImageLoaded = (BOOL)GetMyView().GetImage();\r
+\r
+ switch(nID)\r
+ {\r
+ case IDM_FILE_SAVE:\r
+ EnableMenuItem(GetFrameMenu(), IDM_FILE_SAVE, IsImageLoaded? MF_ENABLED : MF_GRAYED);\r
+ break;\r
+ case IDM_FILE_SAVEAS:\r
+ EnableMenuItem(GetFrameMenu(), IDM_FILE_SAVEAS, IsImageLoaded? MF_ENABLED : MF_GRAYED);\r
+ break;\r
+ case IDM_IMAGE_ADJUST:\r
+ EnableMenuItem(GetFrameMenu(), IDM_IMAGE_ADJUST, IsImageLoaded? MF_ENABLED : MF_GRAYED);\r
+ break;\r
+ }\r
+}\r
+\r
+void CMainFrame::SetupToolBar()\r
+{\r
+ // Set the Resource IDs for the toolbar buttons\r
+ AddToolBarButton( IDM_FILE_NEW );\r
+ AddToolBarButton( IDM_FILE_OPEN );\r
+ AddToolBarButton( IDM_FILE_SAVEAS, FALSE );\r
+\r
+ AddToolBarButton( 0 ); // Separator\r
+ AddToolBarButton( IDM_IMAGE_ADJUST, FALSE );\r
+\r
+ AddToolBarButton( 0 ); // Separator\r
+ AddToolBarButton( IDM_HELP_ABOUT );\r
+\r
+ // Use large toolbar buttons\r
+ SetToolBarImages(RGB(192, 192, 192), IDB_TOOLBAR_BIG, 0, 0);\r
+}\r
+\r
+LRESULT CMainFrame::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)\r
+{\r
+// switch (uMsg)\r
+// {\r
+ //Additional messages to be handled go here\r
+// }\r
+\r
+ // pass unhandled messages on for default processing\r
+ return WndProcDefault(uMsg, wParam, lParam);\r
+}\r
+\r