Use Slim Reader/Writer lock to replace CRITICAL_SECTION (better performance).
[gdipp.git] / gdipp_pre / MainDlg.cpp
blobce2022e8d558db55ba0f1c74222e148b476e3e2e
1 // MainDlg.cpp : implementation of the CMainDlg class
2 //
3 /////////////////////////////////////////////////////////////////////////////
5 #include "stdafx.h"
6 #include "gdipp_pre/resource.h"
7 #include "MainDlg.h"
8 #include "gdipp_pre/gdipp_pre.h"
9 #include "gdipp_pre/aboutdlg.h"
11 BOOL CMainDlg::PreTranslateMessage(MSG* pMsg)
13 return CWindow::IsDialogMessage(pMsg);
16 BOOL CMainDlg::OnIdle()
18 return FALSE;
21 LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
23 // center the dialog on the screen
24 CenterWindow();
26 // set icons
27 HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
28 IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
29 SetIcon(hIcon, TRUE);
30 HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
31 IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
32 SetIcon(hIconSmall, FALSE);
33 HMENU hMenu = (HMENU)::LoadMenu(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME));
34 SetMenu(hMenu);
35 SetDlgItemTextW(IDC_STATIC, preview_text);
37 // register object for message filtering and idle updates
38 CMessageLoop* pLoop = _Module.GetMessageLoop();
39 ATLASSERT(pLoop != NULL);
40 pLoop->AddMessageFilter(this);
41 pLoop->AddIdleHandler(this);
43 UIAddChildWindowContainer(m_hWnd);
45 return TRUE;
48 LRESULT CMainDlg::OnClose(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
50 CloseDialog(static_cast<int>(wParam));
51 return 0;
54 LRESULT CMainDlg::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
56 // unregister message filtering and idle updates
57 CMessageLoop* pLoop = _Module.GetMessageLoop();
58 ATLASSERT(pLoop != NULL);
59 pLoop->RemoveMessageFilter(this);
60 pLoop->RemoveIdleHandler(this);
62 return 0;
65 LRESULT CMainDlg::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
67 gdipp::init_config();
68 return 0;
71 LRESULT CMainDlg::OnFileOpen(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
73 BOOL b_ret;
75 OPENFILENAMEW ofn = {};
76 ofn.lStructSize = sizeof(OPENFILENAME);
77 ofn.hwndOwner = m_hWnd;
78 ofn.lpstrFilter = L"XML Files\0*.xml\0\0";
79 ofn.lpstrFile = config_path;
80 ofn.nMaxFile = MAX_PATH;
82 b_ret = GetOpenFileNameW(&ofn);
83 if (b_ret)
85 gdipp::init_config();
86 b_ret = gdipp::load_config(config_path);
89 return 0;
92 LRESULT CMainDlg::OnFileSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
94 //BOOL b_ret = gdipp::save_config(config_path);
95 assert(false);
96 return 0;
99 LRESULT CMainDlg::OnFileSaveAs(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
101 /*BOOL b_ret;
103 OPENFILENAMEW ofn = {};
104 ofn.lStructSize = sizeof(OPENFILENAME);
105 ofn.hwndOwner = m_hWnd;
106 ofn.lpstrFilter = L"XML Files\0*.xml\0\0";
107 ofn.lpstrFile = config_path;
108 ofn.nMaxFile = MAX_PATH;
110 b_ret = GetSaveFileNameW(&ofn);
111 if (b_ret)
113 b_ret = gdipp::save_config(config_path);
115 assert(false);
116 return 0;
119 LRESULT CMainDlg::OnFileExit(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
121 // TODO: Add validation code
122 CloseDialog(wID);
123 return 0;
126 LRESULT CMainDlg::OnChangeFont(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
128 BOOL b_ret;
130 const HFONT old_font = reinterpret_cast<const HFONT>(SendMessage(GetDlgItem(IDC_STATIC), WM_GETFONT, 0, 0));
131 assert(old_font != NULL);
133 LOGFONTW lf;
134 const int i_ret = GetObject(old_font, sizeof(LOGFONTW), &lf);
135 assert(i_ret != 0);
137 CHOOSEFONTW cf = {};
138 cf.lStructSize = sizeof(CHOOSEFONTW);
139 cf.hwndOwner = m_hWnd;
140 cf.lpLogFont = &lf;
141 cf.Flags = CF_INITTOLOGFONTSTRUCT;
143 b_ret = ChooseFontW(&cf);
144 if (b_ret)
146 HFONT new_font = CreateFontIndirect(&lf);
147 assert(new_font != NULL);
149 SendMessage(GetDlgItem(IDC_STATIC), WM_SETFONT, reinterpret_cast<WPARAM>(new_font), MAKELPARAM(TRUE, 0));
151 DeleteObject(old_font);
154 return 0;
157 LRESULT CMainDlg::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
159 CAboutDlg dlg;
160 dlg.DoModal();
161 return 0;
164 void CMainDlg::CloseDialog(int nVal)
166 DestroyWindow();
167 ::PostQuitMessage(nVal);