home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 June / PCWorld_2003-06_cd.bin / KOMUNIK / MIRRORIT / SRC / SESSIONPROPERTIESMAINPAGE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-04  |  3.0 KB  |  131 lines

  1. // SessionPropertiesMainPage.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MirrorIt.h"
  6. #include "SessionPropertiesMainPage.h"
  7. #include "shlobj.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSessionPropertiesMainPage property page
  17.  
  18. IMPLEMENT_DYNCREATE(CSessionPropertiesMainPage, CPropertyPage)
  19.  
  20. CSessionPropertiesMainPage::CSessionPropertiesMainPage() : CPropertyPage(CSessionPropertiesMainPage::IDD)
  21. {
  22.     //{{AFX_DATA_INIT(CSessionPropertiesMainPage)
  23.     m_BaseURL = _T("");
  24.     m_SessionName = _T("");
  25.     m_Comment = _T("");
  26.     m_Directory = _T("");
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30. CSessionPropertiesMainPage::~CSessionPropertiesMainPage()
  31. {
  32. }
  33.  
  34. void CSessionPropertiesMainPage::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CPropertyPage::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(CSessionPropertiesMainPage)
  38.     DDX_Text(pDX, IDC_BASEURL, m_BaseURL);
  39.     DDX_Text(pDX, IDC_SESSIONNAME, m_SessionName);
  40.     DDX_Text(pDX, IDC_COMMENT, m_Comment);
  41.     DDX_Text(pDX, IDC_DIRECTORY, m_Directory);
  42.     //}}AFX_DATA_MAP
  43. }
  44.  
  45.  
  46. BEGIN_MESSAGE_MAP(CSessionPropertiesMainPage, CPropertyPage)
  47.     //{{AFX_MSG_MAP(CSessionPropertiesMainPage)
  48.     ON_BN_CLICKED(IDC_DIRECTORYBUTTON, OnDirectorybutton)
  49.     //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CSessionPropertiesMainPage message handlers
  54.  
  55. BOOL CSessionPropertiesMainPage::OnKillActive() 
  56. {
  57.     BOOL bOk = CPropertyPage::OnKillActive();
  58.     if (bOk)
  59.     {
  60.         if (m_SessionName.IsEmpty())
  61.         {
  62.             AfxMessageBox(IDW_SESSIONNAME, MB_OK | MB_ICONSTOP);
  63.             bOk = FALSE;
  64.         }
  65.     }
  66.     return bOk;
  67. }
  68.  
  69. void CSessionPropertiesMainPage::OnDirectorybutton() 
  70. {
  71.     CString    directory;
  72.  
  73.     GetDlgItemText(IDC_DIRECTORY, directory);
  74.  
  75.     if (BrowseDirectory(m_hWnd, directory))
  76.         SetDlgItemText(IDC_DIRECTORY, directory);
  77. }
  78.  
  79. int CSessionPropertiesMainPage::BrowseDirectory(HWND hwnd, CString & directory)
  80. {
  81.     BROWSEINFO bi;       
  82.     LPSTR lpBuffer; 
  83.     LPITEMIDLIST pidlDesktop;
  84.     LPITEMIDLIST pidlBrowse;
  85.     LPMALLOC g_pMalloc;
  86.  
  87.     directory.Empty();
  88.     if (!SUCCEEDED(SHGetMalloc(&g_pMalloc)))
  89.         return FALSE; 
  90.  
  91.     if ((lpBuffer = (LPSTR) g_pMalloc->Alloc(MAX_PATH)) == NULL)
  92.     {
  93.         g_pMalloc->Release();
  94.         return FALSE;    
  95.     }
  96.  
  97.     if (!SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_DESKTOP, &pidlDesktop)))
  98.     { 
  99.         g_pMalloc->Free(lpBuffer);
  100.         g_pMalloc->Release();
  101.         return FALSE;
  102.     }
  103.  
  104.     bi.hwndOwner = hwnd; 
  105.     bi.pidlRoot = pidlDesktop;
  106.     bi.pszDisplayName = lpBuffer; 
  107.  
  108.     CString title;
  109.     title.LoadString(IDC_BROWSEDIR);
  110.     bi.lpszTitle = title;
  111.     bi.ulFlags = BIF_RETURNONLYFSDIRS; 
  112.     bi.lpfn = NULL;
  113.     bi.lParam = 0;    
  114.  
  115.     int res = FALSE;
  116.     pidlBrowse = SHBrowseForFolder(&bi);
  117.     if (pidlBrowse != NULL) 
  118.     {    
  119.         if (SHGetPathFromIDList(pidlBrowse, lpBuffer))
  120.         {
  121.             directory = lpBuffer;
  122.             res = TRUE;
  123.         }
  124.         g_pMalloc->Free(pidlBrowse);     
  125.     }
  126.     g_pMalloc->Free(pidlDesktop); 
  127.     g_pMalloc->Free(lpBuffer); 
  128.     g_pMalloc->Release();
  129.     return res;
  130. }
  131.