1 // NewProjectDlg.cpp : implementation file
2 //
3 
4 #include "studiox_includes.h"
5 #include "NewProjectDlg.h"
6 #include "express_dialog.h"
7 
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #endif
11 
12 #define NEW_PROJECT_WIDTH 600
13 #define NEW_PROJECT_HEIGHT 320
14 
15 // NewProjectDlg dialog
16 
17 //IMPLEMENT_DYNAMIC(NewProjectDlg, CDialog)
18 enum new_project_dlg_test_commands{
19     TEST_SET_NEW_PROJECT_PATH = 1,
20     TEST_SET_NEW_PROJECT_NAME,
21     TEST_SAVE_NEW_PROJECT_CREATE,
22     TEST_CANCEL_NEW_PROJECT_CREATE,
23 };
24 
BEGIN_MESSAGE_MAP(NewProjectDlg,express_dialog)25 BEGIN_MESSAGE_MAP(NewProjectDlg, express_dialog)
26     ON_BN_CLICKED(IDC_BROWSE_PATH, &NewProjectDlg::OnBnClickedBrowsePath)
27     ON_BN_CLICKED(IDCANCEL, &NewProjectDlg::OnCancel)
28     ON_WM_SHOWWINDOW()
29     ON_WM_PAINT()
30     ON_MESSAGE(STUDIO_TEST, OnTestMessage)
31 END_MESSAGE_MAP()
32 
33 NewProjectDlg::NewProjectDlg(CWnd* pParent /*=NULL*/)
34 	: express_dialog(NewProjectDlg::IDD, pParent)
35 {
36     IconId = IDB_NEW_PROJECT_ICON;
37     SetTitleText("Create New Project");
38 }
39 
~NewProjectDlg()40 NewProjectDlg::~NewProjectDlg()
41 {
42 }
43 
OnShowWindow(BOOL bShow,UINT nStatus)44 void NewProjectDlg::OnShowWindow(BOOL bShow, UINT nStatus)
45 {
46     CRect size;
47     GetWindowRect(&size);
48 
49     size.OffsetRect(0, -120);
50     MoveWindow(size);
51     express_dialog::OnShowWindow(bShow, nStatus);
52 }
53 
OnInitDialog()54 BOOL NewProjectDlg::OnInitDialog()
55 {
56     express_dialog::OnInitDialog();
57 
58     // TODO:  Add extra initialization here
59     AddCancelButton();
60     AddSaveButton();
61 
62     CString description(L"Required");
63     SetAccessibleFullDescription(GetDlgItem(IDC_EDIT_NAME)->GetSafeHwnd(), description);
64     SetAccessibleFullDescription(GetDlgItem(IDC_EDIT_PATH)->GetSafeHwnd(), description);
65     SetAccessibleDescription(GetDlgItem(IDC_EDIT_NAME)->GetSafeHwnd(), description);
66     SetAccessibleDescription(GetDlgItem(IDC_EDIT_PATH)->GetSafeHwnd(), description);
67 
68     return TRUE;  // return TRUE unless you set the focus to a control
69                   // EXCEPTION: OCX Property Pages should return FALSE
70 }
71 
DoDataExchange(CDataExchange * pDX)72 void NewProjectDlg::DoDataExchange(CDataExchange* pDX)
73 {
74     CDialog::DoDataExchange(pDX);
75 }
76 
DestroyWindow()77 BOOL NewProjectDlg::DestroyWindow()
78 {
79     GetDlgItemText(IDC_EDIT_NAME, mproject_name);
80     GetDlgItemText(IDC_EDIT_PATH, mproject_path);
81     return CDialog::DestroyWindow();
82 }
83 
Getproject_name()84 CString &NewProjectDlg::Getproject_name()
85 {
86     return mproject_name;
87 }
Getproject_path()88 CString &NewProjectDlg::Getproject_path()
89 {
90     return mproject_path;
91 }
OnOK()92 void NewProjectDlg::OnOK()
93 {
94     GetDlgItemText(IDC_EDIT_NAME, mproject_name);
95     GetDlgItemText(IDC_EDIT_PATH, mproject_path);
96 
97     if (mproject_name.IsEmpty())
98     {
99         ErrorMsg(L"The project name cannot be empty.", this);
100         return;
101     }
102 
103     if (mproject_path.IsEmpty())
104     {
105         ErrorMsg(L"The project path cannot be empty.", this);
106         return;
107     }
108 
109     CDialog::OnOK();
110 }
111 
OnCancel()112 void NewProjectDlg::OnCancel()
113 {
114     CDialog::OnCancel();
115 }
116 
117 ///////////////////////////////////////////////////////////////////////////////
OnPaint()118 void NewProjectDlg::OnPaint()
119 {
120     CDialog::OnPaint();
121 
122     PaintRequiredAsterisk(IDC_EDIT_NAME);
123     PaintRequiredAsterisk(IDC_EDIT_PATH);
124     PaintRequiredAsterisk(IDC_REQUIRED_FIELD_LEGEND);
125 }
126 
127 
128 
129 // NewProjectDlg message handlers
130 
OnBnClickedBrowsePath()131 void NewProjectDlg::OnBnClickedBrowsePath()
132 {
133     TCHAR path[MAX_PATH];
134     if (BrowseForFolder(m_hWnd, NULL, NULL, path))
135     {
136         SetDlgItemText(IDC_EDIT_PATH, path);
137     }
138 }
139 
OnTestMessage(WPARAM wParam,LPARAM lParam)140 afx_msg LRESULT NewProjectDlg::OnTestMessage(WPARAM wParam, LPARAM lParam)
141 {
142     switch (wParam)
143     {
144     case TEST_SET_NEW_PROJECT_PATH:
145         SetDlgItemText(IDC_EDIT_PATH, GetTestingParam(0));
146         break;
147 
148     case TEST_SET_NEW_PROJECT_NAME:
149         SetDlgItemText(IDC_EDIT_NAME, GetTestingParam(0));
150         break;
151 
152     case TEST_SAVE_NEW_PROJECT_CREATE:
153         OnOK();
154         break;
155 
156     case TEST_CANCEL_NEW_PROJECT_CREATE:
157         OnCancel();
158     }
159 
160     return 0;
161 }