Re: Custom CFileDialog with template
I'm not sure--your code is difficult to read. Looks like all the newlines
got cut out at the end of the post.
I would just point out that: The point of using a custom template is so you
can create addition controls in the dialog editor, not dynamically from
code. I see no reason to use a template if any additional controls will be
added dynamically.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Charlie Hoo" <Charlie@newsgroups.nospam> wrote in message
news:%23BsjQGxiGHA.4368@TK2MSFTNGP03.phx.gbl...
Hello,
I follow the example at
http://www.codeproject.com/dialog/fndsoundpreview.asp to create my own
custom CFileDialog-derived class called CImportFileDlg, I dynamically
create a "Select All" button at the bottom of the dialog, but I can never
catch the click event of the button. My code is following:
---ImportFileDlg.h----
/////////////////////////////
#pragma once
// CImportFileDlg
struct OPENFILENAMEEX : public OPENFILENAME
{
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
};
class CImportFileDlg : public CFileDialog
{
DECLARE_DYNAMIC(CImportFileDlg)
public:
//Initialization
CImportFileDlg(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for
FileSaveAs
LPCTSTR lpszDefExt = NULL, //Default Extension
LPCTSTR lpszFileName = NULL, //Initial filename that appears in the
filename edit box
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
|OFN_ALLOWMULTISELECT, //A combination of one or more flags that allow you
to customize the dialog box
CWnd* pParentWnd = NULL, //Parrent Window
BOOL bAutoPlay = FALSE, //Check the autoplay checkbox on start
LPCTSTR lpszFilter = "Image Files (*.jpg; *.jpeg)|*.jpg; *.jpeg|*.*||"
);
//Destruction
virtual ~CImportFileDlg();
protected:
//Overides
virtual void OnInitDone();
//{{AFX_VIRTUAL(CImportFileDlg)
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnSelectAll();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_VIRTUAL
//Member Variables
CButton m_selectAll;
DECLARE_MESSAGE_MAP()
private:
};
----ImportFileDlg.cpp----
// SoundFileDlg.cpp : implementation file
//
/////////////////////////////
#include "stdafx.h"
#include "ImportFileDlg.h"
//for extended controls:
#define IDC_IMPORTFILE_SELECTALL 6001 //Button
// CImportFileDlg
//IMPLEMENT_DYNAMIC(CImportFileDlg, CFileDialog)
CImportFileDlg::CImportFileDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags, CWnd* pParentWnd, BOOL bAutoPlay, LPCTSTR lpszFilter) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags,
lpszFilter, pParentWnd)
{
if(bOpenFileDialog)
{
m_ofn.Flags |= OFN_ENABLETEMPLATE;
m_ofn.Flags |= OFN_ALLOWMULTISELECT;
m_ofn.lStructSize = sizeof(OPENFILENAMEEX); // sizeof (OPENFILENAME) +
12;
m_ofn.hInstance = AfxGetInstanceHandle();
m_ofn.lpTemplateName = "IMPORTFILEDLG_TEMPLATE";
//IMPORTFILEDLG_TEMPLATE is defined in TestFileDialog.rc2.rc
}
}
CImportFileDlg::~CImportFileDlg()
{
}
IMPLEMENT_DYNAMIC(CImportFileDlg, CFileDialog)
BEGIN_MESSAGE_MAP(CImportFileDlg, CFileDialog)
//{{AFX_MSG_MAP(CImportFileDlg)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_IMPORTFILE_SELECTALL,OnSelectAll)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CImportFileDlg message handlers
void CImportFileDlg::OnInitDone()
{
CFileDialog::OnInitDone();
CRect cr,winRect;
CWnd * pWnd = this->GetParent();
pWnd->GetWindowRect(winRect);
pWnd->ScreenToClient(winRect);
/*
I realy don't know why but this window (the template)
doesn't let the dialog paint right in some systems (W2k and ME) when
resizing,
so I make all non fileDilaog controls be child of the actual dilaog,
and move the template window to 0,0 an resize it to 0x0.
*/
SetWindowPos(&wndBottom,0/*::GetSystemMetrics(SM_CXSCREEN)*/,0/*::GetSystemMetrics(SM_CYSCREEN)*/,0,0,0);
cr=winRect; CFont *pFont = pWnd->GetFont(); // GetFont(); //SelectAll
button cr.top = cr.bottom-50; cr.bottom = cr.top+25; cr.left =
cr.left+100; cr.right = cr.left+100;
m_selectAll.Create("SelectAll",BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE|WS_TABSTOP,cr,pWnd,IDC_IMPORTFILE_SELECTALL);
m_selectAll.SetFont(pFont); //The timer is set to redraw the pre-listen
window, //it couldn't be done with OnSize beacuse this object doesn't
//resizes when a dialog Resizes. if(m_ofn.Flags & OFN_ENABLESIZING)
SetTimer(1,1,NULL);}void CImportFileDlg::OnSelectAll(){ //why is never
called??????? AfxMessageBox("OnSelectAll");}void
CImportFileDlg::OnTimer(UINT nIDEvent){ if(nIDEvent==1) { //do resize }
CFileDialog::OnTimer(nIDEvent);}//it is never called?????void
CImportFileDlg::OnSize(UINT nType, int cx, int cy){
AfxMessageBox("OnSize"); CFileDialog::OnSize(nType, cx, cy); // TODO: Add
your message handler code
here}******************************************************Could you tell
me what is wrong with the code?Thanks a lot.Charlie