我新建的一个类CFileDlg(继承的CFileDialog),我在上面添加了一个按钮Button2,
我对他进行了消息映射,可是没有响应!
我试了WM_SIZE等几个消息,也是无法响应,是不是CFileDialog类屏蔽了什么消息?还有什么其他方法实现我需要的功能?(在CFileDialog对象上添加了一个按钮,触发事件)我的代码如下:BEGIN_MESSAGE_MAP(CFileDlg, CFileDialog)
//{{AFX_MSG_MAP(CFileDlg)
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
……
……
……
void CFileDlg::OnSize(UINT nType, int cx, int cy) 
{
CFileDialog::OnSize(nType, cx, cy);

// TODO: Add your message handler code here
MessageBox("d");
}void CFileDlg::OnButton2() 
{
// TODO: Add your control notification handler code here
MessageBox("Button2 is clicked!");
}

解决方案 »

  1.   

    你还少了afx_msg void OnSize(UINT nType, int cx, int cy);之类的东东吧
      

  2.   

    加了的说:
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnButton2();
      

  3.   

    CFileDialog的实现比较复杂, 不是象你想的那样,可以轻松加一个Button.
    CFileDialog实现的复杂性为的完成MFC对SDK控件的封装.
    有兴趣可以读一读CFileDialog的源程序.我想可能需要一两天才能明白CFileDialog的实现原理.反正我是费了不少功夫
    才明白的.以下是一个关于CFileDialog的一些描述,其中尤其要注意ID是"stc32"的隐藏
    窗口的功能,因为你的Button必须加到这个窗口上.在MSDN中以"stc32"为关键字查找,你会得到一些关于从如何从
    CFileDialog派生的信息.-------------------------------------------------------------
    Providing a custom template for CFileDialog
    With the old-style common file dialog box (that is, non-Explorer), the template used was the WHOLE file dialog box, with all of the standard controls. Now, with Explorer dialog boxes, you provide only the controls you would like to add to the dialog box. Your template is repositioned and resized to fit the standard controls when the CFileDialog window is first created. Or, if you want precise positioning of the standard controls, you can place a static control with an ID of stc32 on your template to indicate where you want the standard controls to be placed. This is the technique OfnKing uses.