📄 stgraphdlg.cpp
字号:
// StGraphDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StGraph.h"
#include "StGraphDlg.h"
#include "FileDlg.h"
#include <math.h>
#include "ResulrDlg.h"
#include "Password.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStGraphDlg dialog
CStGraphDlg::CStGraphDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStGraphDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStGraphDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStGraphDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStGraphDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_progress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStGraphDlg, CDialog)
//{{AFX_MSG_MAP(CStGraphDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnSource)
ON_BN_CLICKED(IDC_BUTTON2, OnBMP)
ON_BN_CLICKED(IDC_BUTTON3, OnRecover)
ON_BN_CLICKED(IDC_BUTTON4, OnDO_IT)
ON_BN_CLICKED(ID_about, OnAbout)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStGraphDlg message handlers
BOOL CStGraphDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
AfxMessageBox("I hope you enjoy my program . ");
srcBin=new char [2];
srcBMP=new char [2];
CreateBinLookUpTable();
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CStGraphDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CStGraphDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStGraphDlg::OnAbout ()
{
AfxMessageBox("Hi All , Me 'Ahmed Osama', Communication & Electronics Engineer :) ahmed_osama@ieee.org");
}
void CStGraphDlg::OnSource()
{
// TODO: Add your control notification handler code here
// ** Opening the text file & reading every byte and converting **
// ** to binary bits to be stored in array **
CFileDlg dlg(TRUE,"txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"text (*.txt)|*.txt|");
dlg.DoModal ();
CFile f;
if (!f.Open ((LPCTSTR)dlg.GetPathName (),CFile::modeRead|CFile::typeBinary ))
return;
int l=f.GetLength (); // ** Getting the text file size **
CPassword enterpassword;
again:
enterpassword.DoModal ();// ** Showing the password entry dialog **
if (enterpassword.m_password1!=enterpassword.m_password2)
{ AfxMessageBox("Check your password , the two passwords are not matching !!!");
goto again;}
if (enterpassword.m_password1.GetLength ()!=5)
{
AfxMessageBox("Check your password , less than 5 letters !!!");
goto again;
}
char *buffer = new char [l];
// ** buffer which will contain the text file
CString temp;
int a=0;
delete [] srcBin;
binLen=(l+5+5)*8; // ** Calc. the binary array size
// ** size=(each byte of text +each byte of the pass+
// ** each byte of 5 digit no) * (8 bits per byte)
srcBin=new char [binLen]; // ** binary array for the text file **
f.ReadHuge (buffer,l);
char buffer1[50];
_gcvt( l , 10, buffer1 );//** Converte txt file size no to str **
CString temp1=buffer1;// ** if txt file is 20 bytes -->temp1="20."*
temp1=temp1.Left (temp1.GetLength ()-1);// ** Removing the point **
CString temp2="0";
// ** We assuming the max txt file size is 99999 (5 digits) **
// ** So to be sure that it is always 5 digits **
// ** after converting the txt size to str we add extra zero**
// ** Example txt size is 20 bytes
// ** will be conv. to "20" ---fixing it to --- "00020" **
if (temp1.GetLength ()<5)
{
for (int k=1 ; k<5-temp1.GetLength () ; k++)
temp2=temp2+"0";
}
temp2=temp2+temp1+enterpassword.m_password1;
temp2=temp2.Left (10);
// ** temp2 holds the header which will be added to the txt file**
// ** temp2="the fixed txt file size"(5 digits)+"password" **
CString temp3(buffer); // ** temp3 hold now the raw text file **
temp3.Insert (0,temp2);// ** Adding the header to the raw txt file**
for (int i=0 ; i<(binLen/8) ;i++)
{
// ** Converting each byte to bin bits and storing in in **
// ** the srcBin array. **
temp=bin[(unsigned char)temp3[i]];
// ** Example 'a'--->ascii--->97--->bin[97]="01100001"
// ** putting each bit in the srcBin array
// ** 0--->srcBin[a]
// ** 1--->srcBin[a+1] and So on........
srcBin[a]=temp[0];
srcBin[a+1]=temp[1];
srcBin[a+2]=temp[2];
srcBin[a+3]=temp[3];
srcBin[a+4]=temp[4];
srcBin[a+5]=temp[5];
srcBin[a+6]=temp[6];
srcBin[a+7]=temp[7];
a=a+8;
}
delete [] buffer;
f.Close ();
CWnd * koko=GetDlgItem (IDC_BUTTON2);
koko->EnableWindow ();
AfxMessageBox("Text File Loaded");
}
void CStGraphDlg::OnBMP()
{
// ** This function handle opening the raw bmp file to hide in it thr txt **
CFileDlg dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|");
dlg.DoModal ();
if (!bmpFile.Open ((LPCTSTR)dlg.GetPathName (),CFile::modeReadWrite|CFile::typeBinary ))
return;
int l=bmpFile.GetLength ();
bmpLen=l; // ** contains the bmp file length(size) **
delete [] srcBMP;
srcBMP=new char [l]; // ** This is the buffer which will contains the bmp file **
bmpFile.ReadHuge (srcBMP,l); // ** Loading the bmp file into the buffer **
AfxMessageBox("File Loaded");
CWnd * koko=GetDlgItem (IDC_BUTTON4);
koko->EnableWindow (); // ** Activate "Hide Text" button **
}
void CStGraphDlg::OnRecover()
{
// ** This function used to recover the txt file from the bmp **
ResulrDlg dllg;
int min,max;
m_progress.GetRange (min,max);
m_progress.SetPos (min);
CFileDlg dlg(TRUE,"bmp",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"Only BMP (*.bmp)|*.bmp|");
dlg.DoModal ();
CFile f;
if (!f.Open ((LPCTSTR)dlg.GetPathName (),CFile::modeReadWrite|CFile::typeBinary ))
return;
int l=f.GetLength (); // ** l=the bmp size **
char *buffer = new char [l] ; // ** buffer which will hold the bmp file **
int *recBin=new int [l]; // ** buffer which will hold the bmp fle bits **
char temp;
CString mssg;
f.ReadHuge (buffer,l); // ** loading the bmp file to the buffer **
CString temp1=buffer;// ** temp1 holds the bmp file **
for(int j=55 ; j<55+8*10 ;j++)
{
recBin[j]=(unsigned char) ((unsigned char)buffer[j] & 1);
// ** conveting each byte in the bmp(after the header) to bits **
// ** stored in the recBin array **
}
for (j=55 ; j<55+8*10 ;j=j+8)
{
temp=128*recBin[j]+64*recBin[j+1]+32*recBin[j+2]+16*recBin[j+3]+8*recBin[j+4]+4*recBin[j+5]+2*recBin[j+6]+1*recBin[j+7];
mssg=mssg+temp;
// ** reading the last bit in each 8 bit **
// ** converting them to decimal again (ascii code) **
// ** but just the first 10 bytes (our header which contain the pass**
// ** and the txt file size **
}
CPassword enterpassword;
enterpassword.hide =true;
int ii=1;
again :
enterpassword.DoModal ();
// ** our header consist of two part as we knew each 5 bytes **
// ** txt file size + pass
// ** checking the password
if (enterpassword.m_password1 !=mssg.Right (5))
{
AfxMessageBox("Bad Password !! ");
}
else
{
goto safe;
}
ii++;
if (ii<4) goto again;
if (ii==4) this->DestroyWindow ();
// ** after three trials the program exit **
safe:
int length=atoi(mssg.Left(5) );
// ** getting the txt file size but it is string
// ** so converting it back to int using atoi() function
m_progress .SetRange (55,2*l-8);
// ** setting the min and max limit for the progress bar **
for(int i=55+8*10 ; i<55+8*10+length*8;i++)
{
recBin[i]=(unsigned char) ((unsigned char)buffer[i] & 1);
// ** reading the bits of the txt file **
}
mssg="";
for (i=55+8*10 ; i<55+8*10+length*8 ;i=i+8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -