Windows NT Systems Programming: Spring 1999

[ Home | Syllabus | Course Notes | Assignments | Search]


Version 4

Here is a quick sketch of the objects and their relationships in version 4.
crystal.gif (246 bytes) NOTE: there are some bad design decisions and obsolete code/objects in the current solution. Can you find them?
crystal.gif (246 bytes) In an event driven system used in GUI programming, it is helpful to define the state of the entire application at points in between user generated events.
crystal.gif (246 bytes) It is also helpful to trace the communications paths between the objects which set up these intermediate stable state values.

CMsgFolderApp
     CMsgFolder
     CMessage
     m_pMainWnd ---> CMainWindow
CMainWindow
     CMsgDlg
     IDR_MAIN_MENU \\ Menu generated by Resource Compiler
          OnOpenFolder( ) \\ Message Handler for Opening a Folder
               CFolderDlg \\ Folder Selection Dialog
                    m_folderName
          OnEditMsg( ) \\ Message Handler for Editing a Message
               CMsgDlg \\ Message Selection Dialog
                    m_MsgID
               CMessage
               CMsgEdit
                    m_pMsg \\ pointer to a Message Object

rainbow.gif (2243 bytes)

Define Major Stable States of the Application (what is transient and what is stable?):

Define the Major Events by the User which change these states:

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.


Creating Project


Building the Menu using resource editor


Building a Dialog Box

NOTE: you get OK and Cancel for free.


Connecting CDialog

 

// 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) : hptrd_left.gif (955 bytes)
	  CDialog(IDD_FOLDERhptrd_left.gif (955 bytes), 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
rainbow.gif (2243 bytes)

Implementation

 

// 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); // Parse this
		}
		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)) // Parse this - where are these?
		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()
{
	OnFolderSelection( ); hptrd_left.gif (955 bytes) // because this does both selection and opening
	OnOK( ); 
}
rainbow.gif (2243 bytes)

The (almost) Final Version 4

Project is here.

Solution consists of:

in CMsgFolder class:


Program Flow

rainbow.gif (2243 bytes)

 


Copyright chris wild 1999.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: February 22, 1999.