Question

I am developing a ATL/WTL software. It is a DLL library that works as a shell extension creating a property page for multimedia files in Windows (the software is called MediaTab, you can search it to understand me better, maybe)

Main dialog is managed in MediaTabDlg class (inherits from CPropertyPageImpl). In this dialog I have one button that I use to open a new dialog (modal) in order to config advanced setups. This modal dialog is managed in FileExtDlg class (inherits from CDialogImpl).

The problem comes here. I am able to open the modal dialog clicking the button, but no events are working on that dialog. Nor OK button, Cancel button or X in the corner are working so I can't close the dialog!

Here you have the relevant code:

MediaTabDlg.h

class MediaTabDlg : public CPropertyPageImpl<MediaTabDlg>
{
public:
MediaTabDlg(TCHAR file[MAX_PATH],int nfiles);
~MediaTabDlg(void);

enum { IDD = IDD_MEDIATAB_PROPPAGE };

BEGIN_MSG_MAP(MediaTabDlg)
    MESSAGE_HANDLER( WM_INITDIALOG,   OnInitDialog )
    COMMAND_HANDLER( IDC_EDITFILEEXT,   BN_CLICKED, OnEditFileExt )
    ...
    CHAIN_MSG_MAP( WTL::CPropertyPageImpl<MediaTabDlg> )
END_MSG_MAP()

    ...
LRESULT OnEditFileExt(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
};

MediaTabDlg.cpp

...
LRESULT MediaTabDlg::OnEditFileExt(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
    FileExtDlg dlg;
    dlg.DoModal();
    return S_OK;
}
...

FileExtDlg.h

class FileExtDlg :  public CDialogImpl<FileExtDlg>
{
public:
FileExtDlg();
~FileExtDlg(void);

enum { IDD = IDD_FILEEXTDLG };

BEGIN_MSG_MAP(FileExtDlg)
    MESSAGE_HANDLER( WM_INITDIALOG,   OnInitDialog )
    COMMAND_HANDLER( IDOK, BN_CLICKED, OnOK)
    COMMAND_HANDLER( IDCANCEL, BN_CLICKED, OnCancel )
END_MSG_MAP()

// manejadores de eventos
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
};

FileExtDlg.cpp

FileExtDlg::FileExtDlg() {}

FileExtDlg::~FileExtDlg(void) {}

LRESULT FileExtDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    SetDlgItemText ( IDCANCEL, _T("blablabla") );
    GetDlgItem(IDCANCEL).ShowWindow(false);
    return S_OK;
}

LRESULT FileExtDlg::OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    MessageBox(_T("Helloooo!"));
    EndDialog(1);
    return 0;
}

LRESULT FileExtDlg::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    MessageBox(_T("Hello!"));
    EndDialog(0);
    return 0;
}

And that is. No event handler is ever executed (no MessageBox show up, code from OnInitDialog don't run... and EndDialog never works), but dialog DOES show up.

What do you think?

Thank you

P.D: I have tried CSimpleDialog and works fine, but obviously it is not enough for me because I need to put some code in the dialog. However, it can be a clue: MediaTabDlg codes must be alright, I think...

P.D2: I have tried WTL 9.0, 8.1 and 8.0 with no success.

Was it helpful?

Solution

I solved the problem by myself.

I think there was some kind of conflict with dialog autogenerated code and ATL framework, because the issue was related with ID resource names. I don't know exactly why, but I changed ID of standard button to something else (IDOK -> IDC_OK, IDCANCEL -> IDC_CANCEL) and now all works: buttons, message maps, and so on.

My code revised (FileExtDlg.h)

class FileExtDlg : public ATL::CDialogImpl<FileExtDlg>
{
public:
    FileExtDlg();
    ~FileExtDlg(void);

    enum { IDD = IDD_FILEEXTDLG };

    BEGIN_MSG_MAP(FileExtDlg)
        MESSAGE_HANDLER( WM_INITDIALOG,   OnInitDialog )
        MESSAGE_HANDLER( WM_CLOSE, OnClose )
        COMMAND_HANDLER( IDC_OK, BN_CLICKED, OnOK)
        COMMAND_HANDLER( IDC_CANCEL, BN_CLICKED, OnCancel)
        COMMAND_HANDLER( IDC_PRUEBA, BN_CLICKED, OnPrueba)
    END_MSG_MAP()

    // event handlers
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    LRESULT OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnPrueba(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);

    // own functions
    LRESULT Cerrar(void);
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top