summaryrefslogtreecommitdiff
path: root/NSCmpts/BackupDestProp.cpp
blob: 615394562f5f8523b2e5813be17b4d6d42526125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// BackupDestProp.cpp : Implementation of CBackupDestProp
#include "stdafx.h"
#include "NSCmpts.h"
#include "BackupDestProp.h"

#include <path.h>
#include <shlobj.h>

/////////////////////////////////////////////////////////////////////////////
// CBackupDestProp

LRESULT CBackupDestProp::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// Let it choose an object to get data from
	m_Data.Initialize(m_nObjects, m_ppUnk);

	// Set Control Text
	m_sPath = m_Data.GetString(NS_BACKUP_REG_DEST, _T(""));
	SetDlgItemText(IDC_DEST, m_sPath);
	
	return TRUE;  // Let the system set the focus
}

LRESULT CBackupDestProp::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	// Last resort. Save text in case of Destroy somewhere
	GetDlgItemText(IDC_DEST, m_sPath.get_buffer(MAX_PATH), MAX_PATH);
	m_sPath.release_buffer();

	return 0;
}

LRESULT CBackupDestProp::OnBrowse(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	// Show a Browse for Folder Dialog

	LPMALLOC pMalloc;
	if(FAILED(::SHGetMalloc(&pMalloc)))
		return 0;

	BROWSEINFO bi;
	bi.hwndOwner = m_hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = m_sPath.get_buffer(MAX_PATH);
	bi.lpszTitle = _T("Choose folder to backup to:");
	bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
	bi.lpfn = NULL;
    bi.lParam = 0;

	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

	if(pidl == NULL)
		return 0;

	m_sPath.release_buffer();

	if(::SHGetPathFromIDList(pidl, m_sPath.get_buffer(MAX_PATH)))
		::SetWindowText(GetDlgItem(IDC_DEST), m_sPath);

	m_sPath.release_buffer();

	pMalloc->Free(pidl);
	pMalloc->Release();

	bHandled = true;
	return 0;
}