Click here to Skip to main content
15,919,245 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Kernel32.dll Pin
Johann Gerell18-Nov-03 23:35
Johann Gerell18-Nov-03 23:35 
GeneralRe: Kernel32.dll Pin
Mike Dimmick18-Nov-03 23:47
Mike Dimmick18-Nov-03 23:47 
GeneralRe: Kernel32.dll Pin
hph18-Nov-03 23:52
hph18-Nov-03 23:52 
GeneralRe: Kernel32.dll Pin
peterchen19-Nov-03 6:45
peterchen19-Nov-03 6:45 
GeneralRe: Kernel32.dll Pin
Antti Keskinen19-Nov-03 10:07
Antti Keskinen19-Nov-03 10:07 
GeneralRe: Kernel32.dll Pin
parths18-Nov-03 23:58
parths18-Nov-03 23:58 
GeneralRe: Kernel32.dll Pin
Rama Krishna Vavilala19-Nov-03 11:29
Rama Krishna Vavilala19-Nov-03 11:29 
GeneralProblem with deriving a class from CFileDIalog Pin
Rob Manderson18-Nov-03 23:07
protectorRob Manderson18-Nov-03 23:07 
I'm sure the answer to this will be obvious (about 5 seconds after I read the response) but I'm mightily puzzled by this...

I've derived a class from CFileDialog that looks like this...

C++
class CLoadLogFilesDlg : public CFileDialog
{
    DECLARE_DYNAMIC(CLoadLogFilesDlg)
public:
                    CLoadLogFilesDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL);
                    ~CLoadLogFilesDlg();

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CLoadLogFilesDlg)
protected:
    virtual void    DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

    virtual BOOL    OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
    
private:
    CStringList     m_slFileList;

protected:
    //{{AFX_MSG(CLoadLogFilesDlg)
    virtual BOOL    OnFileNameOK();
    virtual void    OnOK();
    afx_msg void    OnLoadAll();
    afx_msg void    OnLoadToday();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};


and the class implementation is this...

C++
IMPLEMENT_DYNAMIC(CLoadLogFilesDlg, CFileDialog)

CLoadLogFilesDlg::CLoadLogFilesDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName, DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) : CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
    CString csInitDir;
    TCHAR   szWinDir[_MAX_PATH + 1];

    m_ofn.lStructSize = sizeof(OPENFILENAME);
    m_ofn.Flags |= OFN_ENABLETEMPLATE | OFN_ALLOWMULTISELECT;
    m_ofn.hInstance = AfxGetInstanceHandle();
    m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_LOADLOGS);

    GetWindowsDirectory(szWinDir, _MAX_PATH);
    csInitDir.Format(_T("%s\\%s"), szWinDir, COMMANDPIPENAME);

    m_ofn.lpstrInitialDir = csInitDir;
    m_ofn.lpstrFile = new TCHAR[10000];
    m_ofn.nMaxFile = sizeof(m_ofn.lpstrFile);
    memset(m_ofn.lpstrFile, 0, sizeof(m_ofn.lpstrFile));
}

CLoadLogFilesDlg::~CLoadLogFilesDlg()
{
    delete m_ofn.lpstrFile;
}

void CLoadLogFilesDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BOOL CLoadLogFilesDlg::OnFileNameOK()
{
    return FALSE;
}

BOOL CLoadLogFilesDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
    OFNOTIFY* pNotify = (OFNOTIFY*) lParam;

    TRACE("pNotify->hdr.code == %x\n", 0 - pNotify->hdr.code);
    
    if (pNotify->hdr.code == CDN_FILEOK)
        return OnFileNameOK();
    
    return CFileDialog::OnNotify(wParam, lParam, pResult);
}

BEGIN_MESSAGE_MAP(CLoadLogFilesDlg, CFileDialog)
    //{{AFX_MSG_MAP(CLoadLogFilesDlg)
    ON_COMMAND(IDC_LOADALL, OnLoadAll)
    ON_COMMAND(IDC_LOADTODAY, OnLoadToday)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CLoadLogFilesDlg::OnLoadAll()
{
}

void CLoadLogFilesDlg::OnLoadToday()
{
    CString csPattern;

    csPattern.Format(_T("%s\\*.log"), m_ofn.lpstrInitialDir);

    CFileFind ff;
    BOOL      bWorking = ff.FindFile(csPattern);

    while (bWorking)
    {
        bWorking = ff.FindNextFile();
        m_slFileList.AddHead(ff.GetFilePath());
    }

    CFileDialog::OnOK();
}

void CLoadLogFilesDlg::OnOK() 
{
    CFileDialog::OnOK();
}


The problem is that I never ever see a call to CLoadLogFilesDlg::OnFileNameOK() even though it's an override of a virtual function. When I see calls to the overridden OnNotify function the trace output is

pNotify->hdr.code == 25b
pNotify->hdr.code == 25a
pNotify->hdr.code == 25a


now when we look at the CFileDialog::OnNotify() function we find this code...

C++
BOOL CFileDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	ASSERT(pResult != NULL);

	// allow message map to override
	if (CCommonDialog::OnNotify(wParam, lParam, pResult))
		return TRUE;

	OFNOTIFY* pNotify = (OFNOTIFY*)lParam;
	switch(pNotify->hdr.code)
	{
	case CDN_INITDONE:
		OnInitDone();
		return TRUE;
	case CDN_SELCHANGE:
		OnFileNameChange();
		return TRUE;
	case CDN_FOLDERCHANGE:
		OnFolderChange();
		return TRUE;
	case CDN_SHAREVIOLATION:
		*pResult = OnShareViolation(pNotify->pszFile);
		return TRUE;
	case CDN_HELP:
		if (!SendMessage(WM_COMMAND, ID_HELP))
			SendMessage(WM_COMMANDHELP, 0, 0);
		return TRUE;
	case CDN_FILEOK:
		*pResult = OnFileNameOK();
		return TRUE;
	case CDN_TYPECHANGE:
		OnTypeChange();
		return TRUE;
	}

	return FALSE;   // not handled
}


and if we look at the definitions of the case labels we find they're

C++
#define CDN_LAST    (0U-699U)

// Notifications when Open or Save dialog status changes
#define CDN_INITDONE            (CDN_FIRST - 0x0000)
#define CDN_SELCHANGE           (CDN_FIRST - 0x0001)
#define CDN_FOLDERCHANGE        (CDN_FIRST - 0x0002)
#define CDN_SHAREVIOLATION      (CDN_FIRST - 0x0003)
#define CDN_HELP                (CDN_FIRST - 0x0004)
#define CDN_FILEOK              (CDN_FIRST - 0x0005)
#define CDN_TYPECHANGE          (CDN_FIRST - 0x0006)
#define CDN_INCLUDEITEM         (CDN_FIRST - 0x0007)


it's pretty obvious that the notification codes my dialog procedure is seeing don't match any of those constants which is why I'm not seeing calls to my overrides. I have no idea why? Any ideas?

Rob Manderson

http://www.mindprobes.net

"I killed him dead cuz he was stepping on my turf, cutting me out of my bling the same way my ho cuts cookies, officer"

"Alright then, move along"
- Ian Darling, The Lounge, Oct 10 2003
GeneralRe: Problem with deriving a class from CFileDIalog Pin
Neville Franks18-Nov-03 23:48
Neville Franks18-Nov-03 23:48 
GeneralRe: Problem with deriving a class from CFileDIalog Pin
Rob Manderson19-Nov-03 18:06
protectorRob Manderson19-Nov-03 18:06 
GeneralRe: Problem with deriving a class from CFileDIalog Pin
igor196019-Nov-03 10:21
igor196019-Nov-03 10:21 
GeneralRe: Problem with deriving a class from CFileDIalog Pin
Rob Manderson19-Nov-03 10:25
protectorRob Manderson19-Nov-03 10:25 
GeneralRe: Problem with deriving a class from CFileDIalog Pin
igor196019-Nov-03 10:34
igor196019-Nov-03 10:34 
GeneralRe: Problem with deriving a class from CFileDIalog Pin
Rob Manderson19-Nov-03 18:18
protectorRob Manderson19-Nov-03 18:18 
GeneralNeed information about port in CSocket Pin
Aswin18-Nov-03 23:03
Aswin18-Nov-03 23:03 
GeneralRe: Need information about port in CSocket Pin
Mike Dimmick18-Nov-03 23:50
Mike Dimmick18-Nov-03 23:50 
GeneralContents of Grid Pin
naveensg18-Nov-03 23:00
naveensg18-Nov-03 23:00 
Generalcontrol names Pin
naveensg18-Nov-03 22:56
naveensg18-Nov-03 22:56 
GeneralRe: control names Pin
Michael P Butler18-Nov-03 23:07
Michael P Butler18-Nov-03 23:07 
GeneralRe: control names Pin
naveensg18-Nov-03 23:13
naveensg18-Nov-03 23:13 
GeneralRe: control names Pin
David Crow19-Nov-03 3:29
David Crow19-Nov-03 3:29 
GeneralRe: control names Pin
naveensg19-Nov-03 3:40
naveensg19-Nov-03 3:40 
GeneralRe: control names Pin
David Crow19-Nov-03 4:57
David Crow19-Nov-03 4:57 
GeneralRe: control names Pin
naveensg19-Nov-03 17:14
naveensg19-Nov-03 17:14 
GeneralRe: control names Pin
igor196019-Nov-03 10:53
igor196019-Nov-03 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.