[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-09-12
6
Medium Priority
?
336 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
5 Comments
 
LVL 35

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 35

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 35

Accepted Solution

by:
sarabande earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

830 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