Mix MessageBox, cfiledialog and fopen VC and MFC

Source: Internet
Author: User

MessageBox is a commonly used message prompt box. msdn defines it as follows:

 
Int MessageBox (hwndHwnd, LpctstrLptext, LpctstrLpcaption, UintUtype);
 
Generally, when using MFC, you can only write the prompt content MessageBox ("message prompt! ");
 
Or write two parameters and the title or three add-type buttons.
 
What I want to say is that when you write another VC header file and implementation file and call it in the MFC project, the first parameter must be written, otherwise Vs will fail.
 
But you may have to call multiple windows. Is that a problem?
 
This can be selected based on the current window. Use global: Afxgetapp ()-> getmainwnd ()-> getsafehwnd ()
 
Get the current window and prompt
At this time, the four parameters MessageBox (: Afxgetapp ()-> getmainwnd ()-> getsafehwnd (), "prompt content", "title", "type");
 
 
 
2. Use cfiledialog and then use fopen to return null.
 
The file to be opened is placed in the current path and can be called directly. No problem. When the file in another directory is selected in the open file dialog box, null is returned when the file is opened with fopen.
 
I initially thought that the file operations of MFC and C cannot be used together. I think it's wrong. After many experiments, it still doesn't work. Sometimes the success may fail. A colleague suggested that the file path should be incorrect when fopen fails to be opened,
 
I changed it to an absolute path and found it. I thought the reason should be that after selecting a file with cfiledialog, I changed the default path of the project. The path to fopen is incorrect, the specified file cannot be found.

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.