home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / recent / recent.exe / FilesDlg.cpp < prev    next >
C/C++ Source or Header  |  1998-04-13  |  1KB  |  67 lines

  1. #include "stdafx.h"
  2. #include "FilesDlg.h"
  3.  
  4. FilesDlg::FilesDlg(const TCHAR* initTitle) :
  5.     title(initTitle)
  6. {
  7. }
  8.  
  9. FilesDlg::~FilesDlg()
  10. {
  11. }
  12.  
  13. LRESULT FilesDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
  14. {
  15.     CWindow listBox(GetDlgItem(IDC_LIST));
  16.     for(list<tstring>::iterator it = files.begin(); it != files.end(); ++it)
  17.         listBox.SendMessage(LB_ADDSTRING, 0, reinterpret_cast<LPARAM>((*it).data()));
  18.     listBox.SendMessage(LB_SETCURSEL, 0);
  19.  
  20.     SetWindowText(title.data());
  21.     CenterWindow();
  22.     return 1;
  23. }
  24.  
  25. LRESULT FilesDlg::OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  26. {
  27.     DoOK();
  28.     return 0;
  29. }
  30.  
  31. LRESULT FilesDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
  32. {
  33.     EndDialog(wID);
  34.     return 0;
  35. }
  36.  
  37. LRESULT FilesDlg::OnList(WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
  38. {
  39.     switch(wNotifyCode)
  40.     {
  41.     case LBN_DBLCLK:
  42.         DoOK();
  43.         break;
  44.  
  45.     default:
  46.         bHandled = FALSE;
  47.     }
  48.  
  49.     return 0;
  50. }
  51.  
  52. void FilesDlg::DoOK()
  53. {
  54.     CWindow listBox(GetDlgItem(IDC_LIST));
  55.     int selIndex = listBox.SendMessage(LB_GETCURSEL);
  56.     if(selIndex != LB_ERR)
  57.     {
  58.         int len = listBox.SendMessage(LB_GETTEXTLEN, selIndex);
  59.         _ASSERT(len != LB_ERR);
  60.         TCHAR* selBuff = new TCHAR[len + 1];
  61.         listBox.SendMessage(LB_GETTEXT, selIndex, reinterpret_cast<LPARAM>(selBuff));
  62.         selected = selBuff;
  63.         delete [] selBuff;
  64.     }
  65.     EndDialog(IDOK);
  66. }
  67.