1 // MainDlg.cpp : implementation of the CMainDlg class
3 /////////////////////////////////////////////////////////////////////////////
6 #include "gdipp_pre/resource.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()
21 LRESULT
CMainDlg::OnInitDialog(UINT
/*uMsg*/, WPARAM
/*wParam*/, LPARAM
/*lParam*/, BOOL
& /*bHandled*/)
23 // center the dialog on the screen
27 HICON hIcon
= (HICON
)::LoadImage(_Module
.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME
),
28 IMAGE_ICON
, ::GetSystemMetrics(SM_CXICON
), ::GetSystemMetrics(SM_CYICON
), LR_DEFAULTCOLOR
);
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
));
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
);
48 LRESULT
CMainDlg::OnClose(UINT
/*uMsg*/, WPARAM wParam
, LPARAM
/*lParam*/, BOOL
& /*bHandled*/)
50 CloseDialog(static_cast<int>(wParam
));
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);
65 LRESULT
CMainDlg::OnFileNew(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
71 LRESULT
CMainDlg::OnFileOpen(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
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
);
86 b_ret
= gdipp::load_config(config_path
);
92 LRESULT
CMainDlg::OnFileSave(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
94 //BOOL b_ret = gdipp::save_config(config_path);
99 LRESULT
CMainDlg::OnFileSaveAs(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
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);
113 b_ret = gdipp::save_config(config_path);
119 LRESULT
CMainDlg::OnFileExit(WORD
/*wNotifyCode*/, WORD wID
, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
121 // TODO: Add validation code
126 LRESULT
CMainDlg::OnChangeFont(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
130 const HFONT old_font
= reinterpret_cast<const HFONT
>(SendMessage(GetDlgItem(IDC_STATIC
), WM_GETFONT
, 0, 0));
131 assert(old_font
!= NULL
);
134 const int i_ret
= GetObject(old_font
, sizeof(LOGFONTW
), &lf
);
138 cf
.lStructSize
= sizeof(CHOOSEFONTW
);
139 cf
.hwndOwner
= m_hWnd
;
141 cf
.Flags
= CF_INITTOLOGFONTSTRUCT
;
143 b_ret
= ChooseFontW(&cf
);
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
);
157 LRESULT
CMainDlg::OnAppAbout(WORD
/*wNotifyCode*/, WORD
/*wID*/, HWND
/*hWndCtl*/, BOOL
& /*bHandled*/)
164 void CMainDlg::CloseDialog(int nVal
)
167 ::PostQuitMessage(nVal
);