Sometimes people want to write a small tool to use, so use them again MFC, after all, to be a very simple interface, we intend to long-term record some small problems encountered and solutions.
1 mfc select a file button to increase the response:
BOOL isOpen = TRUE; // if open (otherwise save)
CString defaultDir; // = L "E: \\ FileTest"; // default file path open
CString fileName = L ""; // open the default file name
CString filter = L "file (* .txt) | * .txt || "; // file type misplaced
// Construct a CFileDialog CFileDialog object operations
CFileDialog openFileDlg (isOpen, defaultDir, fileName , OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, filter, NULL) ;
//openFileDlg.GetOFN().lpstrInitialDir = L "E: \\ \\ test.txt FileTest";
// the DoModal displays a dialog box allows the user to select
INT_PTR openFileDlg.DoModal Result = ();
CString filePath; / / the defaultDir + = "\\ test.txt";
IF (Result == IDOK)
{
// return GetPathName selected the full path
filePath = openFileDlg.GetPathName ();
}
---------------------------------------------
2 unicode string to an integer CODED
long num = 0;
num = _ttoi (temp);
--------------------------------------
3 long integer into a string:
CString tmp;
tmp.Format(_T("%I64X"),number);
tmp.Format(_T("%I64d"),number);
------------------------------------
4 Open file
CStdioFile file;
CFileException fileException;
if (!file.Open(filePath, CFile::typeText|CFile::modeReadWrite|CFile::shareExclusive,&fileException))
Read line by line
file.SeekToBegin();
while (file.ReadString(cstrLine))
{
}
// close the file
File.close ();
// -------------------------------------- ---------
// open the file parameter entry
// --------------------------------- --------------
CFile :: modeCreate
--- If the file does not exist it is created, if the file exists then open the file and empty the contents of the file
CFile :: modeCreate | CFile :: CFile :: modeNoTruncate
--- If the file does not exist is created, if the file exists then open the file and retain the contents of the file
CFile :: shareDenyNone
--- allow other processes to read and write files
CFile :: shareDenyRead
--- other processes are not allowed to file for reading
:: shareDenyWrite CFile
--- do not allow other processes to write to the file
CFile :: shareExclusive
--- open files in exclusive mode, do not allow other processes to read and write files
--------------------------------------
. 6 AfxMessageBox Response:
if(IDYES == AfxMessageBox(tips,MB_YESNOCANCEL))
{
exit(0);
}