Example #1
0
// This function tries to execute a Java program (parameter 1) using 
// the supplied call (parameter 2). The first parameter ("the executable") 
// is needed for internal error management (i.e. did the Java call fail or 
// was the executable not found?). The function checks whether Java is 
// installed on the user's machine; if Java is installed, the function 
// determines if the desired program exists (thus we need parameter 1); 
// if the program exists, this function tries to execute the program 
// within a shell window
void ShellExecuteJava(const CString &_javaProgram, const CString &_javaProgramCompleteCall, const CString &_path) {

	CString javaProgram = _javaProgram;
	CString javaProgramCompleteCall = _javaProgramCompleteCall;

	// check if Java is installed
	if(reinterpret_cast<int>(ShellExecute(NULL, NULL, "java", NULL, NULL, SW_HIDE)) <= 32) {
		CString message;
		message.LoadStringA(IDS_STRING_JAVA_JRE_NOT_INSTALLED);
		AfxMessageBox(message, MB_ICONINFORMATION);
		return;
	}
	// check if Java program is there
	javaProgram.Insert(0, _path);
	struct stat javaProgramFileInformation;
	if(stat(javaProgram.GetBuffer(), &javaProgramFileInformation) != 0) {
		CString message;
		message.Format(IDS_STRING_JAVA_PROGRAM_NOT_FOUND, javaProgram);
		AfxMessageBox(message, MB_ICONINFORMATION);
		return;
	}
	// try to execute the Java progam
	if(reinterpret_cast<int>(ShellExecute(NULL, NULL, "java", javaProgramCompleteCall, _path, SW_HIDE)) <= 32) {
		CString message;
		message.LoadStringA(IDS_STRING_JAVA_PROGRAM_EXECUTION_FAILED);
		AfxMessageBox(message, MB_ICONSTOP);
		return;
	}	
}
void CDlgSolitaireAnalyse::OnBnClickedButton5()
{
	UpdateData(true);
   CString csErr;
   int res = myD->loaddeck( "*.txt" );

   switch ( res ) {
      case 0:
         return;
      case 1:
         break;
      case -1:
         csErr.LoadStringA(IDS_SOLITAIRE_COULD_NOT_LOAD_DECK);
         MessageBox( csErr );
         return;
      case -2:
         csErr.LoadStringA(IDS_SOLITAIRE_COULD_NOT_LOAD_DECK);
         MessageBox( csErr );
         return;
   };
//   myD->readdeck( "LastFinaldeck" );
	kartenanzahl=myD->anzahl-3;
	kartenanzahlneu=kartenanzahl+3;
	gefundenesDeck=myD->getDeck();
	zwischendeck=gefundenesDeck;
	schluesselstrom="";
	Initialdeck="";
	enablebut(false);
	hinten.EnableWindow(true);
	vorne.EnableWindow(true);
	waehlen.EnableWindow(true);
	entschluesseln.EnableWindow(false);
	schluesselerzeugen.EnableWindow(false);
	m_kartenanzahl.EnableWindow(false);
	UpdateData(false);
}
void CDlgKeyHomophone::OnLoadKey() 
{
	SHOW_HOUR_GLASS

	UpdateData(TRUE);

	CString SKeyID;
	SKeyID.LoadStringA(IDS_CRYPT_HOMOPHONE);
	if ( FALSE == PasteKey(SKeyID, m_KeyCStr ) )
	{
		m_KeyCtrl.SetSel(0,-1);
		m_KeyCtrl.Paste();
		m_KeyCtrl.GetWindowText(m_KeyCStr);
	}

	HB.load_enc_table(m_KeyCStr.GetBuffer(16000));	
	m_NoOfHomophones = HB.GetKeySize();
	m_Bitlength = HB.LogKeySize( 2 );
	m_listview.DeleteAllItems(); 
	m_InputType = HB.GetKeyType();

	LoadListBox();	
	int Flag = 0;

	CString newAlphabet = _T("");
	for(int i=0;i<range;i++)
	{
		if(HB.GetEncryptionData1(i)>0) 			
		{
			if ( char(i) == '\n' || char(i) == '\t' || char(i) == '\r' )  
			{
				Flag |= 1;
			}
			newAlphabet += char(i);
			if ( 0 > theApp.TextOptions.getAlphabet().Find(char(i)) ) 
			{
				Flag |= 2;
			}
		}
	}
	if ( (HOM_ENC_TXT == m_InputType) && (Flag & 1) ) m_ctrlEncryptFormatCharacters.SetCheck(1);
	if ( (HOM_ENC_TXT == m_InputType) && (Flag & 2 || newAlphabet.GetLength() != theApp.TextOptions.getAlphabet().GetLength()) ) {
		Message( IDS_MSG_HOMOPHONE_CHANGE_OF_ALPHABET, MB_ICONINFORMATION,
			 theApp.TextOptions.getAlphabet(), newAlphabet );
		theApp.TextOptions.refAlphabet() = newAlphabet;
	}

	if ( m_InputType == HOM_ENC_TXT )
	{
		m_ctrlEncodeUmlauts.EnableWindow();
		m_ctrlEncryptFormatCharacters.EnableWindow();
	}
	else
	{
		m_ctrlEncodeUmlauts.EnableWindow(FALSE);
		m_ctrlEncryptFormatCharacters.EnableWindow(FALSE);
	}


// === Reset selected homophonic list
	m_EditNoOfHomophones = 0;
	m_RowHomophonesList = _T("");
	m_HomophonesList = _T("");

	UpdateData(FALSE);

	HIDE_HOUR_GLASS
}
BOOL CDlgKeyHomophone::OnInitDialog() 
{
	int colWidth = 100;										// Spaltenbreite in Pixel

	CDialog::OnInitDialog();

	m_ctrlEncodeUmlauts.SetCheck(FALSE);
	m_AlphabetBackup = theApp.TextOptions.getAlphabet();

	LoadString(AfxGetInstanceHandle(),IDS_PARAM_HOMOPHONE,pc_str,STR_LAENGE_STRING_TABLE);
	CString HParam;
	if ( PasteKey( pc_str, HParam ) )
	{
		UpdateData(true);
		int d = strlen("PARAMETER: ");
		m_BaseHomophones          = (int)(HParam[d] - '0');
		m_ctrlEncryptFormatCharacters.SetCheck((int)(HParam[d+2] - '0'));
		m_ctrlEncodeUmlauts.SetCheck((int)(HParam[d+4] - '0'));
		m_InputType				  = (int)(HParam[d+6] - '0');
		m_NoOfHomophones          = (int)atoi( HParam.GetBuffer(0) +(d+8) );
		UpdateData(false);



		// TEXT 
		int ReInitFlag = 0;
		if ( !m_InputType )
		{
			int l_alphabetLength = theApp.TextOptions.getAlphabet().GetLength();
			if (m_NoOfHomophones < l_alphabetLength) {
				UpdateData();
				m_NoOfHomophones = l_alphabetLength;
				UpdateData(FALSE);
			}


			if ( m_ctrlEncryptFormatCharacters.GetCheck() )
			{	
				if ( 0 > theApp.TextOptions.getAlphabet().Find("\n", 0) ) 
					theApp.TextOptions.refAlphabet().Insert(0, "\n"); 
				if ( 0 > theApp.TextOptions.getAlphabet().Find("\t", 0) ) 
					theApp.TextOptions.refAlphabet().Insert(0, "\t");
				if ( 0 > theApp.TextOptions.getAlphabet().Find("\r", 0) ) 
					theApp.TextOptions.refAlphabet().Insert(0, "\r");			
				ReInitFlag = 1;
			}	
			else
			{
				int ndx;
				if ( 0 <= (ndx = theApp.TextOptions.getAlphabet().Find("\n", 0)) ) 
					theApp.TextOptions.refAlphabet().Delete(ndx);
				if ( 0 <= (ndx = theApp.TextOptions.getAlphabet().Find("\t", 0)) ) 
					theApp.TextOptions.refAlphabet().Delete(ndx);
				if ( 0 <= (ndx = theApp.TextOptions.getAlphabet().Find("\r", 0)) ) 
					theApp.TextOptions.refAlphabet().Delete(ndx);
			}
		}

		if ( m_NoOfHomophones != HB.GetKeySize() )
		{
			HB.Resize( m_NoOfHomophones );
			UpdateData();
			m_Bitlength = HB.LogKeySize( 2 );
			UpdateData(FALSE);
			ReInitFlag = 1;
		}
		if ( ReInitFlag )
			HB.Init_Data();
	}

	m_listview.SetExtendedStyle( LVS_EX_FULLROWSELECT );
	// LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGN,pc_str,STR_LAENGE_STRING_TABLE);
	m_listview.InsertColumn(1,"Ord",LVCFMT_LEFT,colWidth-48,1);							// Ordnung Zeichen
	LoadString(AfxGetInstanceHandle(),IDS_STRING_SIGN,pc_str,STR_LAENGE_STRING_TABLE);
	m_listview.InsertColumn(2,pc_str,LVCFMT_LEFT,colWidth-32,1);							// Zeichen
	LoadString(AfxGetInstanceHandle(),IDS_STRING_COLUMN_FREQUENCY,pc_str,STR_LAENGE_STRING_TABLE);
	m_listview.InsertColumn(3,pc_str,LVCFMT_LEFT,colWidth-24,2);							// Anzahl
	LoadString(AfxGetInstanceHandle(),IDS_STRING_QUANTITY,pc_str,STR_LAENGE_STRING_TABLE);
	m_listview.InsertColumn(4,pc_str,LVCFMT_LEFT,colWidth-8,3);							// Verschl├╝sselung
	LoadString(AfxGetInstanceHandle(),IDS_STRING_LIST_OF_HOMOPHONES,pc_str,STR_LAENGE_STRING_TABLE);
	m_listview.InsertColumn(5,pc_str,LVCFMT_LEFT,colWidth+2000,4);							// Verschl├╝sselung
	Init_ListBox();

	LOGFONT LogFont;
	CFont *defaultFont=m_listview.GetFont();				// this->GetFont() sollte auch funktionieren
	defaultFont->GetLogFont(&LogFont);						// Default Systemschrift ermitteln
	strncpy(LogFont.lfFaceName,"Courier",32);				// Auf Courier umstellen
	m_Font.CreateFontIndirect(&LogFont);					// Font initialisieren
	m_listview.SetFont(&m_Font);

	if ( DeactivateDecryptionButton )
		m_ButtonDecryption.EnableWindow(FALSE);

	VERIFY(m_Paste.AutoLoad(IDC_BUTTON2,this));

	// add tool tip to the paste button
	CString buttonPasteText;
	buttonPasteText.LoadString(IDS_STRING_PASTE_KEY_FROM_KEY_STORE);
	m_Paste.SetToolTipText(&buttonPasteText);

	if ( m_InputType == HOM_ENC_TXT )
	{
		m_ctrlEncodeUmlauts.EnableWindow();
		m_ctrlEncryptFormatCharacters.EnableWindow();
		m_ctrlTextOptions.EnableWindow();
	}
	else
	{
		m_ctrlTextOptions.EnableWindow(FALSE);
		m_ctrlEncodeUmlauts.EnableWindow(FALSE);
		m_ctrlEncryptFormatCharacters.EnableWindow(FALSE);
	}

	CString SKeyID;
	SKeyID.LoadStringA(IDS_CRYPT_HOMOPHONE);
	if ( IsKeyEmpty( SKeyID ) )
	{
		m_Paste.EnableWindow(TRUE);
	}
	else
	{
		m_Paste.EnableWindow(FALSE);
	}
	return(TRUE);
}