Click here to Skip to main content
15,845,565 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've created a rich edit control in IDD_DIALOG2, ThirdDlg.cpp. When I click button void CSecondDlg::BtnNextThirdDlg() to go to the next dialog ThirdDlg.cpp, I can't go there because I have an error: "Services.exe has triggered a breakpoint". When I search Call Stack, I have this "> Services.exe!CSecondDlg::BtnNextThirdDlg() Line 542 C++". I have an arrow that is showing one of the lines of code int screenWidth = GetSystemMetrics(SM_CXSCREEN); in this function:
C++
void CSecondDlg::BtnNextThirdDlg()
{
	/*
	if (m_bRadioSelected && !m_bUserExistChecked)
	{
		AfxMessageBox(_T("Użytkownik musi sprawdzić czy istnieje"));
		return; // Przerywamy działanie funkcji, 
                // aby użytkownik nie przejdzie dalej.
	}
	*/

	CString strFirstPassword, strSecondPassword;
	GetDlgItemText(IDC_EDIT1, strFirstPassword);
	GetDlgItemText(IDC_EDIT2, strSecondPassword);
	//..........................................................................
	
	// Pobierz wybrany przycisk radio
	CButton* pRadExist = (CButton*)GetDlgItem(IDC_RADIO1);
	int nChecked = pRadExist->GetCheck();

	/*
	else if (nChecked == BST_UNCHECKED) {  // Przycisk "IsntExist" 
                                           // jest wybrany
	 // Tutaj nie ma już potrzeby sprawdzania pola username 
     // ani wyświetlania komunikatu

	 // Pobierz zawartość kontrolki EdtFirstPassword
		CString password;
		GetDlgItemText(IDC_EDIT1, password);

		bool containsSpecialCharacter = false;
		// ... reszta sprawdzania hasła ...
	}
	*/
	//..........................................................................

	CString password;
	GetDlgItemText(IDC_EDIT1, password);

	bool containsSpecialCharacter = false;
	bool containsNumber = false;
	bool containsUppercase = false;
	bool containsLowercase = false;

	for (int i = 0; i < password.GetLength(); ++i) 
	{
		if (!isalnum(password[i]) && !isspace(password[i])) 
		{
			containsSpecialCharacter = true;
		}
		if (isdigit(password[i])) 
		{
			containsNumber = true;
		}
		if (isupper(password[i])) 
		{
			containsUppercase = true;
		}
		if (islower(password[i])) 
		{
			containsLowercase = true;
		}
	}
	//..........................................................................

	//expectedPassword = "xsw2!QAZ";

	CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO1);
	int selectedIndex = pCombo->GetCurSel();

	CString enteredPassword;
	GetDlgItemText(IDC_EDIT1, enteredPassword);

	if (nChecked == BST_CHECKED) // Przycisk "IsExist" jest wybrany
	{  
		CString username;
		GetDlgItemText(IDC_EDIT3, username);

		if (username.IsEmpty())
		{
			AfxMessageBox(_T("Użytkownik musi napisać 
                              nazwę użytkownika."), MB_ICONWARNING);
		}

		// Pobierz zawartość kontrolki EdtFirstPassword
		CString password;
		GetDlgItemText(IDC_EDIT1, password);

		bool containsSpecialCharacter = false;
		// ... reszta sprawdzania hasła ...
	}

	/*
	else if (m_RadIsntExist.GetCheck() == 
       BST_CHECKED) // Sprawdzamy, czy przycisk radio jest zaznaczony
	{
		CString selectedText;
		m_ComboExistUser.GetWindowText(selectedText);

		if (selectedText == _T("Test")) // Sprawdzamy, 
                                        // czy wybrano "Test" w ComboBox
		{
			CString password;
			m_EdtFirstPassword.GetWindowText(password);

			if (password == _T("xsw2!QAZ")) // Sprawdzamy, czy wpisane 
                                            // hasło jest poprawne
			{
				// Wykonaj akcje po prawidłowym haśle
				AfxMessageBox(_T("Poprawne hasło"));
			}
			else
			{
				AfxMessageBox(_T("Błędne hasło"));
			}
		}
	}
	*/

	// Compare the entered password with the expected password	
	
	else if (enteredPassword != _T("xsw2!QAZ"))
	{	
		// Password is incorrect; display an error message
		AfxMessageBox(_T("Hasło jest nieprawidłowe"));
	}	

	else if (IsDlgButtonChecked(IDC_RADIO2) != BST_CHECKED)
	{
		if (strFirstPassword != strSecondPassword) {
			AfxMessageBox(_T("Hasła muszą być takie same."), 
                              MB_ICONWARNING);
			return;
		}
	}

	else if (strFirstPassword.GetLength() < 8) {
		AfxMessageBox(_T("Hasło musi mieć więcej lub 
                          równe 8 znaków"), MB_ICONWARNING);
		return;
	}

	else if (!containsSpecialCharacter || !containsNumber || 
             !containsUppercase || !containsLowercase) {
		AfxMessageBox(_T("Regulamin haseł: 1. Hasło musi mieć 
        chociaż jeden znak specjalny.  2.Hasło musi mieć chociaż 
        jedną liczbę.  3.Hasło musi mieć chociaż jedną dużą literę.  
        4.Hasło musi mieć chociaż jedną małą literę."), MB_ICONWARNING);
	}
	
	else
	{
		CDialog dlg(IDD_DIALOG1, this);

		CRect rectSecondDlg;
		m_thirdDlg.GetWindowRect(&rectSecondDlg);
		int screenWidth = GetSystemMetrics(SM_CXSCREEN);
		int screenHeight = GetSystemMetrics(SM_CYSCREEN);
		int dlgWidth = rectSecondDlg.Width();
		int dlgHeight = rectSecondDlg.Height();
		int dlgX = (screenWidth - dlgWidth) / 2;
		int dlgY = (screenHeight - dlgHeight) / 2;
		m_thirdDlg.SetWindowPos(NULL, dlgX, dlgY, 0, 0, 
                   SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);

		ShowWindow(SW_HIDE);
		m_thirdDlg.ShowWindow(SW_SHOW);
	}
}


What I have tried:

In ThirdDlg.cpp, I've added not many lines of code because I was thinking that maybe the control/light is empty, so I did this:
C++
void CThirdDlg::OnEnChangeRichedit22()
{
	// Pobierz długość tekstu w kontrolce Rich Edit
	int nLength = m_EditRich.GetWindowTextLength();

	if (nLength > 0) {
		// Kontrolka Rich Edit nie jest pusta, możesz pobrać zawartość
		CString strRichEditContent;
		m_EditRich.GetWindowText(strRichEditContent);

		// Tutaj możesz wykonać logikę związana z niepustą kontrolką Rich Edit
		SetDlgItemText(IDC_EDIT1, strRichEditContent);
	}
	else {
		// Kontrolka Rich Edit jest pusta
		AfxMessageBox(_T("Kontrolka Rich Edit jest pusta."));
	}
}
Posted
Updated 13-Sep-23 13:25pm
v4
Comments
Richard MacCutchan 13-Sep-23 9:14am    
It is much more likely that the error was caused by the previous line. But without some more detailed information it is impossible to guess. You should use the debugger to step through the code and examine the system when the error occurs. Please also use proper <pre> tags arounf=d your code, so it is at least readable.
jeron1 13-Sep-23 16:02pm    
Has thirdDlg been created when you call

m_thirdDlg.GetWindowRect(&rectSecondDlg); ?
Inczu 14-Sep-23 4:33am    
I've created ThirdDlg but it wouldn't open with rich edit control. Before rich edit control I had error but I could omit it and open ThirdDlg.
Richard MacCutchan 14-Sep-23 7:58am    
You have too many dialogs, and you are not using them correctly. You should only need a single dialog active at any one time. If a dialog creates a second (and third) then there is something wrong with your design. And you should always use Dialog Data Exchange | Microsoft Learn[^] unless there is a specific reason not to.
Inczu 14-Sep-23 8:11am    
I've delete rich edit control 2.0, create a edit control and stretch it. Now I will try to add some code so when the text will hit right vertical line it will go to the next text line

1 solution

I think jeron1 is on the right track with his comment. Try adding few lines of code like this :
C++
    else
    {
        CDialog dlg(IDD_DIALOG1, this);

#ifdef _DEBUG                            // additions begin here
        if( IsWindow( m_thirdDlg ) )
        {
            TRACE( "m_thirdDlg is valid\n" );
        }
        else
        {
            TRACE( "m_thirdDlg is not valid\n" );
        }
#endif                                   // end of additions
        CRect rectSecondDlg;
        m_thirdDlg.GetWindowRect(&rectSecondDlg);
        ...
that should tell if you if the dialog's window handle is valid. The run-time error implies that it is not.
 
Share this answer
 
Comments
Inczu 14-Sep-23 4:41am    
I've copy and paste your code but it still can't open ThirdDlg.
jeron1 14-Sep-23 12:44pm    
Does the TRACE output show that m_thirdDlg is valid?
Also, have you called AfxInitRichEdit() before trying to do this?
Rick York 14-Sep-23 12:57pm    
Your code is not trying to open thirdDlg. It is calling ShowWindow on the dialog after setting its position. That means it has to be open first. Did the trace message say the thirdDlg was valid or not? Also - make sure it is being moved to a valid position. Actually I would try it first by not moving it just to rule out that aspect of things.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900