//***** // THIS PROGRAM illustrates the editing of messages using a set of C++ control objects // Particularly powerful is the CEdit class of objects, which is demonstrated here. // This object has cut/paste/copy built in // Because the MsgFolder is not implemented yet, the user must type in the name of the // Message file // Also should really define a focus order to be able to tab between edit areas. - next time // AUTHOR: Chris Wild // DATE: September 15. 1997 #include "main.h" #include // Create an instance of the application CMsgApp msgApp; // Init the application and the main window BOOL CMsgApp::InitInstance() { m_pMainWnd = new CMainWindow(); m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } // Message map - maps message IDs to their handlers BEGIN_MESSAGE_MAP( CMainWindow, CWnd ) // ON_COMMAND(IDC_SAVE, HandleSave) ON_BN_CLICKED(IDC_SAVE, HandleSave) ON_COMMAND(IDC_CLEAR, HandleClear) ON_COMMAND(IDC_LOAD, HandleLoad) END_MESSAGE_MAP() // Window constructor CMainWindow::CMainWindow() { // Create the window Create(NULL, "Edit Message Demo", WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU, CRect(0,0,500,700)); MakeDlg(); // create edit control windows } CMainWindow::~CMainWindow() { } void CMainWindow::MakeDlg() { CRect rect; // used to get size of window GetClientRect(&rect); // get size of window // Create the window // Create the labels m_msgIDTitle.Create("Message ID", WS_CHILD|WS_VISIBLE, CRect(CPoint(0,0),CSize(150,24)), this); m_topicTitle.Create("Message Topic", WS_CHILD|WS_VISIBLE, CRect(CPoint(0,60),CSize(150,24)), this); m_textTitle.Create("Message Text", WS_CHILD|WS_VISIBLE, CRect(CPoint(0,120),CSize(150,24)), this); // Create the edit controls // FOr demo let user type in message file name m_msgID.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, CRect(CPoint(50,30),CSize(440,24)), this, IDC_MSGID); m_msgID.LimitText(10); // topic edit area m_topic.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, CRect(CPoint(50,90),CSize(440,24)), this, IDC_TOPIC); m_topic.LimitText(SIZE_TOPIC); // text edit area m_text.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP|WS_VSCROLL|ES_MULTILINE, CRect(CPoint(50,150),CSize(440,450)), this, IDC_TEXT); m_text.LimitText(SIZE_TEXT); // Create buttons m_save.Create("&Save", WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON, CRect(CPoint(0,600),CSize(100,50)), this, IDC_SAVE); m_load.Create("&Load", WS_CHILD|WS_VISIBLE|WS_TABSTOP, CRect(CPoint(200,600),CSize(100,50)), this, IDC_LOAD); m_clear.Create("&Clear", WS_CHILD|WS_VISIBLE|WS_TABSTOP, CRect(CPoint(400,600),CSize(100,50)), this, IDC_CLEAR); m_topic.SetFocus(); } // Handle the save button void CMainWindow::HandleSave() // Saves the message { CString topic; CString text; CString fileName; HANDLE msgFile; m_topic.GetWindowText(topic); msgApp.msg.SetTopic((LPCTSTR)topic); m_text.GetWindowText(text); msgApp.msg.SetText((LPCTSTR)text); m_msgID.GetWindowText(fileName); msgFile = CreateFile(fileName,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0); if(msgFile == INVALID_HANDLE_VALUE) { cerr << "Error: " << GetLastError() << " when creating file:" << fileName << endl; ExitProcess(1); } if(!msgApp.msg.WriteMsg(msgFile)) { cerr << " Error writing message msg1\n"; ExitProcess(1); } CloseHandle(msgFile); } void CMainWindow::HandleLoad() // Saves the message { char topic[SIZE_TOPIC]; char text[SIZE_TEXT]; HANDLE msgFile; char fileName[SIZE_FILENAME+1]; m_msgID.GetLine(0, fileName, SIZE_FILENAME); msgFile = CreateFile(fileName,GENERIC_READ,0,0,OPEN_EXISTING,0,0); if(msgFile == INVALID_HANDLE_VALUE) { cerr << "Error: " << GetLastError() << " when opening file: " << fileName << endl; ExitProcess(1); } msgApp.msg.ReadMsg(msgFile); CloseHandle(msgFile); msgApp.msg.GetTopic(topic); msgApp.msg.GetText(text); m_topic.SetWindowText(topic); m_text.SetWindowText(text); } // Handle changes to any edit area void CMainWindow::HandleClear() // Handles Clearing of edit areas { MessageBox("test"); SetDlgItemText(IDC_TOPIC,""); SetDlgItemText(IDC_TEXT,""); }