[ Home | Syllabus | Course Notes | Assignments | Search]
Where are we?
What we need:
What we know:
What we still need to know:
m_editSelection.GetWindowText(folder);
if(!msgFolderApp.msgFolder.OpenMsgFolder(folder))
MessageBox("Message Folder Corrupted!", "ERROR");
else {
SetWindowText("Message Folder Demo [" + folder + "]");
#define IDB_OPEN_MSG 206
#define IDB_CANCEL_MSG 207
#define IDC_MSG_SELECTION 208
#define IDC_MSG_LISTBOX 209
#include "ListMsgs.h"
class CMsgDlg : public CWnd // not CFrameWnd
{
public:
CMsgDlg();
~CMsgDlg();
void MakeDlg(CRect, CWnd*, CListMsgs&); // does the dirty work
protected:
afx_msg void OnOpenMsg();
afx_msg void OnCancelOpenMsg();
afx_msg void OnMsgSelection();
afx_msg void OnMsgDblClk();
DECLARE_MESSAGE_MAP()
private:
// and clean up OpenMessageFolder controls
void cleanUpOpenMsgDlg();
CListBox m_lBoxMsgs; // List Box for Messages
CButton m_btnOpenMsg;
CButton m_btnCancelMsg;
CStatic m_labelSelection; // label for selection
CEdit m_editSelection;
};
#endif
//**************** Class for the Selecting Message Dialog Window
//******************************************
// CMsgDlg: class for displaying the message selection dialog
// Off loads message handling, etc from main window
// Modelled after dialog for opening a message folder
//
#include "CMsgDlg.h"
#include "listMsgs.h"
// Message map - for Message Dialog Class
BEGIN_MESSAGE_MAP( CMsgDlg, CWnd )
ON_COMMAND(IDB_OPEN_MSG, OnOpenMsg)
ON_COMMAND(IDB_CANCEL_MSG, OnCancelOpenMsg)
ON_LBN_SELCHANGE(IDC_MSG_LISTBOX,OnMsgSelection)
ON_LBN_DBLCLK(IDC_MSG_LISTBOX,OnMsgDblClk)
END_MESSAGE_MAP()
CMsgDlg::CMsgDlg()
{
}
CMsgDlg::~CMsgDlg()
{
}
void CMsgDlg::OnOpenMsg()
{
CString message;
CString msgName;
m_editSelection.GetWindowText(msgName);
message = "You want to open " + msgName;
MessageBox(message,"open Message");
cleanUpOpenMsgDlg();
}
void CMsgDlg::OnCancelOpenMsg()
{
cleanUpOpenMsgDlg();
}
void CMsgDlg::OnMsgSelection()
{
CString selection;
int nIndex = m_lBoxMsgs.GetCurSel();
if (nIndex != LB_ERR) {
m_lBoxMsgs.GetText(nIndex,selection);
m_editSelection.SetWindowText(selection);
}
}
void CMsgDlg::OnMsgDblClk()
{
CString selection;
int nIndex = m_lBoxMsgs.GetCurSel();
if (nIndex != LB_ERR) {
m_lBoxMsgs.GetText(nIndex,selection);
m_editSelection.SetWindowText(selection);
OnOpenMsg();
}
}
// could we get away with only building the window once? and just changing its visibility
void CMsgDlg::MakeDlg(CRect rect, CWnd* parent, CListMsgs& listMsgs)
{
Create(NULL, "Message Dialog",
WS_CHILD|WS_VISIBLE,
CRect(0,0,700,500),
parent,400);
rect.right -= 100; // make room for buttons
rect.bottom -= 100; // make room for selection
m_lBoxMsgs.Create(WS_CHILD|WS_VISIBLE|LBS_STANDARD,rect,this,IDC_MSG_LISTBOX);
m_labelSelection.Create("Selected Message:", WS_CHILD|WS_VISIBLE,
CRect(CPoint(0,rect.bottom),CSize(200,25)),
this);
m_editSelection.Create(WS_CHILD|WS_VISIBLE|WS_BORDER,
CRect(CPoint(210,rect.bottom),CSize(rect.right-110,25)),
this,IDC_MSG_SELECTION);
m_btnOpenMsg.Create("Open Msg", WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON,
CRect(CPoint(rect.right+5,0),CSize(75,30)),
this,IDB_OPEN_MSG);
m_btnCancelMsg.Create("Cancel", WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON,
CRect(CPoint(rect.right+5,40),CSize(75,30)),
this,IDB_CANCEL_MSG);
Item thisItem;
for(int i = 1; i <= listMsgs.length(); i++) {
listMsgs.GetItem(i, thisItem);
m_lBoxMsgs.AddString(thisItem.topic);
}
}
void CMsgDlg::cleanUpOpenMsgDlg()
{
m_lBoxMsgs.DestroyWindow();
m_labelSelection.DestroyWindow();
m_btnCancelMsg.DestroyWindow();
m_btnOpenMsg.DestroyWindow();
m_editSelection.DestroyWindow();
DestroyWindow();
}