Sie sind auf Seite 1von 14

NTFS Master Boot Record

CFile untuk File


Access
File yang didukung disediakan oleh Cfile
Object pada Visual C++
CString FileName = "C:\\test\\Test.txt";
CFile File;
if ( !File.Open( FileName, CFile::modeWrite |
CFile::modeCreate ) )
{
MessageBox("Cannot open file:" + FileName,
"Information", MB_OK);
exit(0); // if file cannot be opened quit program
}
// test.txt now exists in folder test with a length of 0 bytes

CString FileName = "C:\\Test1.txt";


CFile File;
unsigned char Buffer[256];
if ( !File.Open( FileName, CFile::modeWrite |
CFile::modeCreate ) )
{
AfxMessageBox("Cannot open file: " + FileName);
exit(0);
}
for ( int a = 0; a < 256; a++ ) //fill the Buffer
Buffer[a] = 'A';
File.Write( Buffer, sizeof( Buffer ) ); //write the buffer
File.Close(); //close file

CString FileName = "C:\\Test1a.txt";


CFile File;
CFileException ex;
unsigned char Buffer[256];
unsigned int FileByteCount;
CWaitCursor wait;
//display hour glass
if ( !File.Open( FileName, CFile::modeRead, &ex ) )
{
TCHAR Cause[255]; //if file error
CString Str;
ex.GetErrorMessage(Cause, 255);
Str = _T("File could not be opened. Error = ");
Str += Cause;
AfxMessageBox(Str);//display error message
}
else //no file error
{
FileByteCount = File.Read( Buffer, sizeof( Buffer ) );
File.Close();
}
wait.Restore(); //return to normal cursor

CString FileName = "C:\\Test1.txt"; //change to display a different file


CFile File;
CFileException ex;
unsigned char Buffer[16];
unsigned int FileByteCount;
unsigned int Address = 0;
Label1.put_Caption(FileName);
CWaitCursor wait;
if ( !File.Open( FileName, CFile::modeRead, &ex ) )
{
TCHAR Cause[255];
CString Str;
ex.GetErrorMessage(Cause, 255);
Str = _T("File could not be opened. Error = ");
Str += Cause;
AfxMessageBox(Str);
}
else
{
while ( ( FileByteCount = File.Read( Buffer, sizeof( Buffer ) ) )!= 0)
{
CString ascii, line;
line = Disph(Address, 8);
for (int a = 0; a < FileByteCount; a++ )
{
line += " " + Disph(Buffer[a], 2);
if ( Buffer[a] >= 32 )
ascii += Buffer[a];
else
ascii += ".";
}
Address += 16;
Rich1.put_Text(Rich1.get_Text() + line + " " + ascii + "\n");
}
File.Close();
}
wait.Restore();

Seek
CString FileName = "C:\\test1.txt";
CFile File;
CFileException ex;
unsigned char Buffer[256];
CWaitCursor wait;
if ( !File.Open( FileName, CFile::modeWrite, &ex ) )
{
TCHAR Cause[255];
CString Str;
ex.GetErrorMessage(Cause, 255);
Str = _T("File could not be opened. Error = ");
Str += Cause;
AfxMessageBox(Str);
}
else
{
File.Seek(0, CFile::end); //go to end of file
File.Write(Buffer, 256); //append file
File.Close();
}
wait.Restore();

//Place these 2 lines after TODO: in the OnInitDialog function


TimeDate();
SetTimer( 1, 1000, 0 );
//Functions for the TimeDate application
void CTimeDateDlg::TimeDate(void)
{
COleDateTime DateTime =
COleDateTime::GetCurrentTime();
LabelTime.put_Caption( DateTime.Format( "%#I:%M:%S
%p" ) );
LabelDate.put_Caption( DateTime.Format( "%A %B %#d,
%Y" ) );
}
void CTimeDateDlg::OnTimer(UINT nIDEvent)
{
TimeDate();
CDialog::OnTimer(nIDEvent);
}

Bubble Sort

BOOL CBubSortDlg::PreTranslateMessage(MSG* pMsg)


{
if ( Count != 10 && pMsg->message == WM_KEYDOWN && pMsg->wParam == 13 )
{
CString temp;
char flag;
char temp1[10];
UINT *pNumbers = &Numbers[0];
//get array pointer
Numbers[Count] = GetDlgItemInt(IDC_EDIT1);
GetDlgItemText(IDC_EDIT1, temp);
SetDlgItemText(IDC_EDIT1, "");
Label1.put_Caption(Label1.get_Caption() + temp);
if ( Count != 9 )
Label1.put_Caption(Label1.get_Caption() + ", ");
Count++;
if ( Count == 10 )
{
_asm{
mov ecx,9
;9 for 10 numbers
L1:
mov flag,0
;clear flag
mov edx,0
L2:
mov ebx,pNumbers
mov eax,[ebx+edx*4]
cmp eax,[ebx+edx*4+4]
jbe L3
push eax
;swap
mov eax,[ebx+edx*4+4]
mov [ebx+edx*4], eax
pop dword ptr [ebx+edx*4+4]
mov flag,1
;set flag
L3:
inc edx
cmp edx,ecx
jne L2
cmp flag,0
jz L4:
;if no swaps
loop L1
L4:
}
for ( int a = 0; a < 9; a++ )
Label2.put_Caption(Label2.get_Caption() +
+ ", ");
Label2.put_Caption(Label2.get_Caption() + itoa(Numbers[9],
}
return true;
}
return CDialog::PreTranslateMessage(pMsg);
}

itoa(Numbers[a], temp1, 10)


temp1, 10));

//PreTranslateMessage function
BOOL CEncrDlg::PreTranslateMessage(MSG* pMsg)
{
char EncryptionKey = 0x45;
//Random Key
CString temp;
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == 13 )
{
GetDlgItemText(IDC_EDIT1, temp);
for ( int a = 0; a < temp.GetLength(); a++ )
{
char code = temp.GetAt(a);
_asm
{
mov al,code
xor al,EncryptionKey
mov code,al
inc EncryptionKey
}
temp.SetAt(a, code);
Label1.put_Caption(temp);
}
return true;
}
return CDialog::PreTranslateMessage(pMsg);
}

SEKIAN DAN TERIMA KASIH

Das könnte Ihnen auch gefallen