General subclass dialog box

Source: Internet
Author: User
MFC contains several encapsulation classes designed for Windows general-purpose dialog boxes. For example, you can use the common cdialog member function domodal () to manipulate the universal file dialog box in cfiledialog.

To derive from a public dialog box class such as cfiledialogProgramMember's own subclass. In the traditional method, you need to create a "subdialog template" and associate the template with the derived cfiledialog class. This template can only include controls that can be added to the dialog box.

However, because the system places the message priority of the derived dialog box template before the normal dialog box order, the MFC message path will not reach this new control class, therefore, there is no way to write a message in the derived cfiledialog class by ing messages.Code.

In Visual C ++ 6.0, this problem has been partially solved: the MFC message routing can work, but programmers still cannot use classwizard to add message processors and member variables. Moreover, if you try to use classwizard to derive a class from cfiledialog, it will not enable the "dialog ID" box, and there is no way to assign an ID number to your dialog box, classwizard does not add associated code for the dialog box.

You can solve this problem using the following methods:

Use classwizard to derive a new class from cdialog (instead of cfiledialog), and then modify the base class and the constructor that generates the new class. As a result, the new class will be derived from the cfiledialog class, And classwizard will be able to process the new control.

The procedure is as follows:

1. Create your own template.

2. Associate the template with a class derived from cdialog and use classwizard (for example, cnewfiledialog.

3. Insert the following code in the definition of cnewfiledialog. h In the header file:

Declare-dynamic (cnewfiledialog)

Modify the constructor declaration:

Cnewfiledialog (bool bopenfiledialog, lpctstr lpszdefext = NULL,

Lpctstr lpszfilename = NULL,

DWORD dwflags = OFN-HIDEREADONLY | OFN-OVERWRITEPROMPT,

Lpctstr lpszfilter = NULL, cwnd pparentwnd = NULL );

4. In the implementation file (. cpp) of the new derived class, insert the following code:

Implement-dynamic (cnewfiledialog, cfiledialog)

Then modify the constructor definition:

Cnewfiledialog: cnewfiledialog (bool bopenfiledialog,

Lpctstr lpszdefext, lpctstr lpszfilename,

DWORD dwflags, lpctstr lpszfilter, cwnd pparentwnd ):

Cfiledialog (bopenfiledialog, lpszdefext, lpszfilename,

Dwflags, lpszfilter, pparentwnd)

{

M_ofn.flags | = OFN-ENABLETEMPLATE | OFN-PATHMUSTEXIST |

OFN-FILEMUSTEXIST | OFN-SHAREAWARE | OFN-ALLOWMULTISELECT;

M-ofn.lpTemplateName = makeintresource (IDD-ABOUTBOX1 );}

Finally, cfiledialog is replaced with cdialog in all header files and implementation files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.