Scope
PresetNameDlg.cpp
1 #include "stdafx.h"
2 #include "PresetNameDlg.h"
3 #include "resource.h"
4 
5 namespace scope {
6  namespace gui {
7 
8 CPresetNameDlg::CPresetNameDlg(std::shared_ptr<std::wstring> _name)
9  : name(_name) {
10 }
11 
12 LRESULT CPresetNameDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) {
13  edit.Attach(GetDlgItem(IDC_NAME_EDIT));
14  CenterWindow(GetParent());
15  edit.SetWindowText(name->c_str());
16  edit.SetSel(0, name->length());
17  edit.SetFocus();
18  return FALSE; // return FALSE, otherwise focus is not given to the edit control!
19 }
20 
21 LRESULT CPresetNameDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
22  int ret = 0;
23  int32_t length = edit.GetWindowTextLength()+1; // +1 since terminating \0 is not counter
24  std::vector<wchar_t> buff(length, L' ');
25  edit.GetWindowText(buff.data(), length); // empty control gives only a \0
26  name->assign(buff.begin(), buff.end()-1);
27 
28  if ( wID == IDCANCEL ) {
29  *name = L"";
30  ret = -1;
31  }
32 
33  EndDialog(ret);
34  return 0;
35 }
36 
37 }}
CPresetNameDlg(std::shared_ptr< std::wstring > _name)
Get a reference to a CString to write the name into.
LRESULT OnCloseCmd(WORD, WORD wID, HWND, BOOL &)
This is the include file for standard system include files, or project specific include files that ar...
CEdit edit
the name edit control
Definition: PresetNameDlg.h:13
std::shared_ptr< std::wstring > const name
pointer to a string to write the name into
Definition: PresetNameDlg.h:16
LRESULT OnInitDialog(UINT, WPARAM, LPARAM, BOOL &)
Initializes the dialog.