Solved

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

Posted on 2011-09-12
6
317 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:tsp2002
  • 3
  • 2
6 Comments
 
LVL 33

Expert Comment

by:sarabande
ID: 36528904
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
 
LVL 33

Expert Comment

by:sarabande
ID: 36528940
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
 
LVL 33

Accepted Solution

by:
sarabande earned 500 total points
ID: 36528974
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
 

Author Comment

by:tsp2002
ID: 36529191
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
 

Author Closing Comment

by:tsp2002
ID: 36529195
thank you for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now