Windows NT Systems Programming

[ Home | Syllabus |Course Notes]


Version 4

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) :
	  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

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);
		}
		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();
	}
}

The (almost) Final Version 4

Project is here.

Solution consists of:

in CMsgFolder class:


Program Flow

rainbow.gif (2243 bytes)

 


Copyright chris wild 1997.
For problems or questions regarding this web contact [Dr. Wild].
Last updated: October 01, 1997.