Need some help with Debug erro after I close my dialog, please help

Hello,
I try to find out why I got a debug error.
From the MainFrame I will open a Password Dialog. The code is not long....so I have enclosed all my code of this dialog.
The user has to enter a password....If correct I call OnCancle to close the Password Dialog and then the 2. dialog will open.
Everything works fine. But when I close the 2.dialog I got a debug stop.
500 points with a solution.
Thank you for your help.
Best regards
Thomas




Here is the function of the Password Dialog where I check the correct password and call the 2.dialog
//######################################################################### 
void CPassword_Logbuch::Check_Password(void)
{
	CString str_Password;
	m_Editbox_Password.GetWindowText(str_Password);
	//=========== Überprüfe Password =====================
	 if(str_Password=="30041966" ||str_Password=="ms" )
	 {
		
		if(str_IP_ADRESSE=="192.168.10.2" ||str_IP_ADRESSE=="192.168.10.1" || str_IP_ADRESSE=="192.168.10.22" )
		{	 //192.168.10.2 = Thomas
			 //192.168.10.22= Thomas Windows 7 PC 
             //192.168.10.1 = Michael
		 
            //------- Schließe diesen Dialog mit Password -------
	 	    CDialog::OnCancel();
		   
			 
			//-------------- Öffne Logbuch Dialog ---------------
			m_Logbuch_Dialog.mb_Kennzahl_first_show_up=true;
 
		    if(m_Logbuch_Dialog.DoModal()==IDOK)		    {
		    }
	 
		   //---------------------------------------------------
 
			
		}
		else
		{
			MessageBox("no access","Caution", MB_OK|MB_ICONSTOP);
		}

	}
	else
	{
		MessageBox("wrong password...no access","Caution", MB_OK|MB_ICONSTOP);
	}
	 
	//==================================================
  
}
//#########################################################################

Open in new window



Here you see how I call the Password Dialog from CMainFrame
//#####################################################################
void CMainFrame::OnDialogPasswortLogbuch()
{
	 
	 //---------- LogBuchEintrag --------------------------------------------------
	 CTime time=CTime::GetCurrentTime();
     m_DatumZeit = time.Format("%d.%m.%y %H:%M:%S");
                              //24.08.09 11:45:35
	 m_Programm="Logbuch";
	 LogBuchEintrag(IP_Adresse, m_BenutzerName, m_Programm, m_DatumZeit);//Funktion
      //----------------------------------------------------------------------------
 
	CPassword_Logbuch *pMeinDialog;
	pMeinDialog = new CPassword_Logbuch;
	pMeinDialog->ShowWindow(SW_SHOW);

  	
}
//###################################################################

Open in new window

// Password_Logbuch.cpp : Implementierungsdatei
//

#include "stdafx.h"
#include "Stockbruegger.h"
#include "MsgBox.h"
#include "Password_Logbuch.h"
#include "Logbuch.h"
#include ".\password_logbuch.h"

#include "winsock2.h"
#define NUM_ELEMENTS(x)  (sizeof((x)) / sizeof((x)[0])) // Für IP auslesen 


// CPassword_Logbuch-Dialogfeld

IMPLEMENT_DYNAMIC(CPassword_Logbuch, CDialog)
CPassword_Logbuch::CPassword_Logbuch(CWnd* pParent /*=NULL*/)
	: CDialog(CPassword_Logbuch::IDD, pParent)
{
	Create(CPassword_Logbuch::IDD, pParent);
}

CPassword_Logbuch::~CPassword_Logbuch()
{
	 
}

void CPassword_Logbuch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_PASSWORD, m_Editbox_Password);
}


BEGIN_MESSAGE_MAP(CPassword_Logbuch, CDialog)
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
	ON_WM_CLOSE()

END_MESSAGE_MAP()


// CPassword_Logbuch-Meldungshandler

//######################################################################### 
void CPassword_Logbuch::OnCancel()
{
}
//######################################################################### 
void CPassword_Logbuch::OnOK()
{
}
//######################################################################### 
void CPassword_Logbuch::PostNcDestroy()
{
	CDialog::PostNcDestroy();
	delete this;
}
//######################################################################### 
void CPassword_Logbuch::OnBnClickedOk()
{
}
 
void CPassword_Logbuch::OnBnClickedCancel()
{
	OnCancel();
}
//######################################################################### 
void CPassword_Logbuch::OnClose()
{
	CDialog::OnCancel();
}
//######################################################################### 
BOOL CPassword_Logbuch::OnInitDialog()
{
	CDialog::OnInitDialog();

	//============= IP Adresse vom Netzwerkcomputer lesen ===============
    char IP_ADRESSE[16]; 
    IP_Adresse_Lesen(IP_ADRESSE); //aufruf von der Funktion  
	//===================================================================           

	

	return TRUE;  // return TRUE unless you set the focus to a control
	// AUSNAHME: OCX-Eigenschaftenseite muss FALSE zurückgeben.
}
 
//######################################################################### 
void CPassword_Logbuch::Check_Password(void)
{
	CString str_Password;
	m_Editbox_Password.GetWindowText(str_Password);
	//=========== Überprüfe Password =====================
	 if(str_Password=="30041966" ||str_Password=="ms" )
	 {
		
		if(str_IP_ADRESSE=="192.168.10.2" ||str_IP_ADRESSE=="192.168.10.1" || str_IP_ADRESSE=="192.168.10.22" )
		{	 //192.168.10.2 = Thomas
			 //192.168.10.22= Thomas Windows 7 PC 
             //192.168.10.1 = Michael
		 
            //------- Schließe diesen Dialog mit Password -------
	 	    CDialog::OnCancel();
		   
			 
			//-------------- Öffne Logbuch Dialog ---------------
			m_Logbuch_Dialog.mb_Kennzahl_first_show_up=true;
 
		    if(m_Logbuch_Dialog.DoModal()==IDOK)//CLogbuch m_Logbuch_Dialog;
		    {
		    }
	 
		   //---------------------------------------------------
 
			
		}
		else
		{
			MessageBox("no access","Caution", MB_OK|MB_ICONSTOP);
		}

	}
	else
	{
		MessageBox("wrong password...no access","Caution", MB_OK|MB_ICONSTOP);
	}
	 
	//==================================================
  
}
//######################################################################### 
BOOL CPassword_Logbuch::PreTranslateMessage(MSG* pMsg)
{
	 if(pMsg->message==WM_KEYDOWN)
	{
		if(pMsg->wParam==VK_RETURN)
		{
			//-------- Ermittle welches Element den Focus hat --------
			CWnd *pFocus = NULL;
			pFocus = GetFocus();
			if(pFocus==NULL)return FALSE;
			//--------------------------------------------------------

			//------------- Welches Element hat den Focus ------------
			int nID = pFocus->GetDlgCtrlID();

			//-------------------------------------------------------
			
			
			switch(nID)
			{
				//___________________________________________________________________IDC_EDIT_PASSWORD 
                case IDC_EDIT_PASSWORD:
					{
						//------------------
						Check_Password();//Funktion
						//------------------
						pFocus = GetDlgItem(IDC_EDIT_PASSWORD ); // setze Focus auf
						pFocus->SetFocus();
						CEdit* pEdt =((CEdit*)GetDlgItem(IDC_EDIT_PASSWORD ));
					    ASSERT(pEdt);
                        int nPos=-1;
						pEdt->SetSel(0,nPos);
					
					break;
			    	}
			 
			//______________________________________________________	
				default:
				 
					break;
			}
			return 0;
		}
	}
       

	return CDialog::PreTranslateMessage(pMsg);
}
 
//######################################################################### 
bool CPassword_Logbuch::IP_Adresse_Lesen(char* IP_ADRESSE)
{
	struct    hostent* h; 
     WSADATA   wsaData; 
     UCHAR     ucAddress[4]; 
     CHAR      szHostName[MAX_PATH]; 
     int       x;   

    WSAStartup(MAKEWORD(1, 1), &wsaData); 
    if(SOCKET_ERROR != gethostname(szHostName, NUM_ELEMENTS(szHostName))) 
    { 
        if(NULL != (h = gethostbyname(szHostName))) 
        { 
            for(x = 0; (h->h_addr_list[x]); x++) 
            {                 
                ucAddress[0] = h->h_addr_list[x][0]; 
                ucAddress[1] = h->h_addr_list[x][1]; 
                ucAddress[2] = h->h_addr_list[x][2]; 
                ucAddress[3] = h->h_addr_list[x][3]; 

                wsprintf(IP_ADRESSE, "%d.%d.%d.%d", ucAddress[0], ucAddress[1], ucAddress[2], ucAddress[3]); 
            } 
        } 
    } 
    WSACleanup(); 

	//------- MemberVariable str_IP_ADRESSE -------
	str_IP_ADRESSE=IP_ADRESSE;
	//---------------------------------------------
    
  return TRUE; 
 
}
//########################################################

Open in new window

1.BMP
2.BMP
tsp2002Asked:
Who is Participating?
 
sarabandeConnect With a Mentor Commented:
if you don't want an ok button you can make an invisible default button instead. the OnOk still would be called on <Enter>.

note, the PreTranslateMessage is a dangerous place to call any dialog functions cause it is the very first function called when a message for the dialog (window) was going to be processed (handled). so while you are in PreTranslateMessage the screen is frozen cause no other message of the messsage queue could be processed.

Sara
0
 
sarabandeCommented:
don't call OnCancel but

EndDialog(IDCANCEL);


the OnCancel is a handler where you could do (add) some termination code. it doesn't actually close the dialog however.

Sara
0
 
sarabandeCommented:
i wouldn't overload the PreTranslateMessage just to catch the enter key. instead make the ok button the default button (what it normally is) and implement the OnOk. the OnOk would be called on <Enter> or when the ok button was clicked on or when the ok button has focus and the space bar was pressed.

Sara
0
 
tsp2002Author Commented:
Hello Sara,
you are right, the error comes from the PreTranslateMessage.
I did it with out the  PreTranslateMessage and a button and everythings runs fine.
Thank you for your help.

P.S. it would be great if you could take a look at my new question (Need some help to print a bitmap with StretchBlt)
I need a help here....thanks.
0
 
tsp2002Author Commented:
thank you for your help
0
All Courses

From novice to tech pro — start learning today.