[ Home | Syllabus |Course Notes]
Some Steps in converting home grown dialogs for message folders to one using CDialog
Also used the visual editing tool for menus and dialog boxes.
NOTE: you get OK and Cancel for free.
// FolderDlg.h: interface for the CFolderDlg class. // ////////////////////////////////////////////////////////////////////// #ifndef H_FOLDERDLG #define H_FOLDERDLG #include <afxwin.h> #include "resource.h" class CFolderDlg : public CDialog { public: CFolderDlg(CWnd* pParentWnd = NULL) : CDialog(IDD_FOLDER, pParentWnd) {} virtual BOOL OnInitDialog(); CString m_folderName; protected: virtual void OnOK(); afx_msg void OnFolderSelection(); afx_msg void OnFolderDblClk(); DECLARE_MESSAGE_MAP() // set up message map handling }; #endif
// FolderDlg.cpp: implementation of the CFolderDlg class. // ////////////////////////////////////////////////////////////////////// #include "FolderDlg.h" #include "main.h" extern CMsgFolderApp msgFolderApp; // Message map - maps message IDs to their handlers BEGIN_MESSAGE_MAP( CFolderDlg, CDialog ) ON_LBN_SELCHANGE(IDC_FOLDER_LIST,OnFolderSelection) ON_LBN_DBLCLK(IDC_FOLDER_LIST,OnFolderDblClk) END_MESSAGE_MAP() ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// BOOL CFolderDlg::OnInitDialog() { CDialog::OnInitDialog(); // build list of message folders in current directory HANDLE folder; WIN32_FIND_DATA findData; folder = FindFirstFile("*", &findData); while( folder != INVALID_HANDLE_VALUE) { if(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // assume all directories are folders ((CListBox*)GetDlgItem(IDC_FOLDER_LIST))->AddString(findData.cFileName); } if(!FindNextFile(folder, &findData)) break; } FindClose(folder); return TRUE; } void CFolderDlg::OnOK() { ((CEdit*)GetDlgItem(IDC_SELECTION))->GetWindowText(m_folderName); if(msgFolderApp.msgFolder.OpenMsgFolder(m_folderName)) CDialog::OnOK(); // clean up and return successfully else { MessageBox("Message Folder Corrupted!\n Try another folder", "ERROR"); } } void CFolderDlg::OnFolderSelection() { CString selection; int nIndex = ((CListBox*)GetDlgItem(IDC_FOLDER_LIST))->GetCurSel(); if (nIndex != LB_ERR) { ((CListBox*)GetDlgItem(IDC_FOLDER_LIST))->GetText(nIndex,selection); ((CEdit*)GetDlgItem(IDC_SELECTION))->SetWindowText(selection); } } void CFolderDlg::OnFolderDblClk() { CString selection; int nIndex = ((CListBox*)GetDlgItem(IDC_FOLDER_LIST))->GetCurSel(); if (nIndex != LB_ERR) { ((CListBox*)GetDlgItem(IDC_FOLDER_LIST))->GetText(nIndex,selection); ((CEdit*)GetDlgItem(IDC_SELECTION))->SetWindowText(selection); OnOK(); } }
Solution consists of:
in CMsgFolder class: