Help with a Dialog design
Mihir Dalal -- m_dalal@ECE.concordia.CA
Tuesday, March 04, 1997
[Mini-digest: 3 responses]
Obviously, the best way of doing this would be to write your dialog all
the way from scratch, but what really matters, is whether most of the
functionality which your box has to have is encapsulated in CFileDialog
or not. If yes, it is really not worth the trouble to write everything
from scratch.
After reading your mail, I do feel that, the kind of box, you want to
implement can be implemented using the CFileDialog, and that it will
really save you lot of trouble.
I can give you some sample code to get you started on a few things. The
following dialog box, I have written, shows a lot of customizations
implemented in a derived CFileDialog class.
It includes, creation of a "delete" button at run time on the box. That
should show you how to write your "Add" button at run time.
Also depicted, is the selective enabling/disabling of list boxes and even
removing them visually from the interface etc.
Email me if you have more problems.
Mihir.
// myfdlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMyFileDlg dialog
#ifndef OFN_NONETWORKBUTTON
#define OFN_NONETWORKBUTTON 0x00020000
#endif
class CMyFileDlg : public CFileDialog
{
// Construction
public:
CMyFileDlg(CWnd* pParent = NULL); // standard constructor
public:
CButton m_deleteButton;
BOOL m_bDeleteFlag;
// Implementation
protected:
virtual BOOL OnInitDialog();
afx_msg void OnDeleteButton();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void OnOK();
// Generated message map functions
//{{AFX_MSG(CMyFileDlg)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
----------------------------[Seperator]-------------------------------
// myfdlg.cpp : implementation file
//
#include "stdafx.h"
#include "myapp.h"
#include "myfdlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyFileDlg dialog
CMyFileDlg::CMyFileDlg(CWnd* pParent /*=NULL*/)
: CFileDialog(TRUE, NULL, "*.dbf")
{
m_ofn.lpstrFilter = "DBase(*.dbf)\0"; // file filter
m_ofn.lpstrTitle = "File Open/Delete"; // dialog caption
m_ofn.lpstrInitialDir = "c:/Windows/";
m_ofn.Flags |= OFN_NONETWORKBUTTON;
}
BOOL CMyFileDlg::OnInitDialog()
{
m_bDeleteFlag = FALSE;
CRect rect(372, 105, 459, 129); // button location in dialog window
m_deleteButton.Create("Delete",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
rect, this, IDC_DELETE);
SetDlgItemText(IDOK, "Open"); // change OK button's caption to Open
CWnd* pDirList = GetDlgItem(1121);
pDirList->EnableWindow(FALSE);
pDirList->ShowWindow(SW_HIDE);
CWnd* pDriveList = GetDlgItem(1137);
pDriveList->EnableWindow(FALSE);
CWnd* pFTypeList = GetDlgItem(1136);
pFTypeList->EnableWindow(FALSE);
CenterWindow();
return CFileDialog::OnInitDialog();
}
void CMyFileDlg::OnDeleteButton()
{
m_bDeleteFlag = TRUE;
SendMessage(WM_COMMAND, IDOK, BN_CLICKED);
}
void CMyFileDlg::DoDataExchange(CDataExchange* pDX)
{
CFileDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyFileDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyFileDlg, CFileDialog)
//{{AFX_MSG_MAP(CMyFileDlg)
// NOTE: the ClassWizard will add message map macros here
ON_BN_CLICKED(IDC_DELETE, OnDeleteButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyFileDlg message handlers
void CMyFileDlg::OnOK()
{
CString OFile;
OFile = GetFileTitle();
WritePrivateProfileString("Current File","file",OFile,"myapp.ini");
EndDialog(TRUE);
MessageBox("My Beautiful Dialog !!","Sample Code", MB_OK|MB_ICONEXCLAMATION);
EndDialog(TRUE);
CFileDialog::OnOK();
}
On Mon, 3 Mar 1997, Balakrishnan, Subramanian wrote:
> Environment: VC++ 4.2b Win NT 3.51
>
> I am trying to design a modal dialog (a CDialog ) with the following
> properties:
>
> Dialog has the a drive selector, Directory tree, a File Name List box,
> File name
> filter ( all the three of them same as that of a Standard File Open
> Dialog ).
>
> Dialog has following buttons "OK", "Cancel", "Add".
>
> Dialog also has a list box control which displays the filenames selected
> by the
> user ( by selecting a file from File Name list box and by clicking on
> the "Add" button ).
>
> I am planning to customize CFileDialog based on the on-line book
> articles.
> Is that the best way of implementing this ?
>
> Thanks for your time,
>
> Subu Balakrishnan
>
> ( subub@tencor.com )
>
>
>
> Subramanian Balakrishnan
> subub@tencor.com
> 415 988 6031
> http://www.geocities.com/SiliconValley/Park/1686
>
_________________________________________________________________________
Mihir Dalal , M.Engg. (Electrical) Student
Department of Electrical and Computer Engineering
Concordia University, Montreal, Canada
http://www.ECE.Concordia.CA/~m_dalal/addr.html
-----From: "Hemanta Banerjee"
Yes that's the best method.
>
> Environment: VC++ 4.2b Win NT 3.51
>
> I am trying to design a modal dialog (a CDialog ) with the following
> properties:
>
> Dialog has the a drive selector, Directory tree, a File Name List box,
> File name
> filter ( all the three of them same as that of a Standard File Open
> Dialog ).
>
> Dialog has following buttons "OK", "Cancel", "Add".
>
> Dialog also has a list box control which displays the filenames selected
> by the
> user ( by selecting a file from File Name list box and by clicking on
> the "Add" button ).
>
> I am planning to customize CFileDialog based on the on-line book
> articles.
> Is that the best way of implementing this ?
>
> Thanks for your time,
>
> Subu Balakrishnan
>
> ( subub@tencor.com )
>
>
>
> Subramanian Balakrishnan
> subub@tencor.com
> 415 988 6031
> http://www.geocities.com/SiliconValley/Park/1686
>
>
Thanks & Regards,
Hemanta Banerjee.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Office :- Residence :-
HCL Technologies Limited, #17, Sriramnagar 1st Cross,
50-53 Greams Road, Thiruvanmiyur,
Madras - 600 0006. Madras - 600 041.
Ph :- (91)-(44)-8279140,8279312 (91)-(44)-4913160 PP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----From: jtalkar@optika.com (Jeremiah Talkar)
I would definitely do it this way. Customizing the common dialogs using
MFC is really easy. Just make sure you don't get into setting up your own
hook etc.
Derive a class from CFileDialog to handle notifications from the controls
you have added ( Add, Listbox etc. ). I don't think ClassWizard will let
you add member variables for these controls, so add them manually. Also
update your DoPropExchange() function to include macros for these two
controls.
Let me know if there are futher doubts.
Jeremiah
-----Original Message-----
From: Balakrishnan, Subramanian
Sent: Monday, March 03, 1997 10:33 AM
To: 'MFC List - Send'
Subject: Help with a Dialog design
Environment: VC++ 4.2b Win NT 3.51
I am trying to design a modal dialog (a CDialog ) with the following
properties:
Dialog has the a drive selector, Directory tree, a File Name List box,
File name
filter ( all the three of them same as that of a Standard File Open
Dialog ).
Dialog has following buttons "OK", "Cancel", "Add".
Dialog also has a list box control which displays the filenames selected
by the
user ( by selecting a file from File Name list box and by clicking on
the "Add" button ).
I am planning to customize CFileDialog based on the on-line book
articles.
Is that the best way of implementing this ?
Thanks for your time,
Subu Balakrishnan
( subub@tencor.com )
Subramanian Balakrishnan
subub@tencor.com
415 988 6031
http://www.geocities.com/SiliconValley/Park/1686
Dulepov Dmitry -- dima@ssm6000.samsung.ru
Wednesday, March 05, 1997
[Mailer: "Groupware E-Mail". Version 1.03.000]
> [From: Balakrishnan, Subramanian
>
>I am planning to customize CFileDialog based on the on-line book
>articles.
>Is that the best way of implementing this ?
>
>Subu Balakrishnan
>
Check these articles. They give enough information.
VC Books online: "Customizing the FileOpen Common Dialog in Windows 95"
MSDN Jan 97: "Using the Common Dialogs Under Windows 95."
Dmitry A. Dulepov
Software Design Engineer
Samsung Electronics Co., Ltd.
Russian Research Center
E-mail: dima@src.samsung.ru
*** WWW page is coming soon! ***
====================================
Become an MFC-L member
| Вернуться в корень Архива
|