When App close it wont open again.

08/09/2015 14:46 raventh1984#1
Hi elitepvpers,

I am wondering about something.
Inside WndFriendConfirm.cpp we have an class called CWndAddFriend()

Now what I did was remove it from the WndFriendConfirm and made an new file called WndAddFriend.cpp and .h.

I copied the function from WndFriendConfirm to WndAddFriend.

I also removed the m_pWndAddFriend from WndManager.cpp cause there are to many if/else constructions.

I show here the codes.

WndAddFriend.cpp
Code:
#include "stdafx.h"
#include "WndAddFriend.h"
#include "defineText.h"
#include "AppDefine.h"
#include "DPClient.h"
#include "WndFriendConFirm.h"
extern	CDPClient	g_DPlay;

CWndAddFriend g_AddFriend;

#include "WndManager.h"
/****************************************************
  WndId : APP_ADD_FRIEND - Add Friend
  CtrlId : WIDC_STATIC1 - Ä£±¸ À̸§
  CtrlId : WIDC_EDIT1 - 
  CtrlId : WIDC_OK - Ok
  CtrlId : WIDC_CANCEL - Cancel
****************************************************/

CWndAddFriend::CWndAddFriend()
{
	m_pWndAddFriend = NULL;
}
CWndAddFriend::~CWndAddFriend()
{
	SAFE_DELETE(m_pWndAddFriend);
}
void CWndAddFriend::OnDraw(C2DRender* p2DRender)
{
}
void CWndAddFriend::OnInitialUpdate()
{
	CWndNeuz::OnInitialUpdate();
	// 여기에 코딩하세요

	CWndEdit* pWndEdit = (CWndEdit*)GetDlgItem(WIDC_EDIT1);
	pWndEdit->SetFocus();

	// 윈도를 중앙으로 옮기는 부분.
	CRect rectRoot = m_pWndRoot->GetLayoutRect();
	CRect rectWindow = GetWindowRect();
	CPoint point(rectRoot.right - rectWindow.Width(), 110);
	Move(point);
	MoveParentCenter();
}
// 처음 이 함수를 부르면 윈도가 열린다.
BOOL CWndAddFriend::Initialize(CWndBase* pWndParent, DWORD /*dwWndId*/)
{
	// Daisy에서 설정한 리소스로 윈도를 연다.
	return CWndNeuz::InitDialog(g_Neuz.GetSafeHwnd(), APP_ADDFRIEND, 0, CPoint(0, 0), pWndParent);
}
BOOL CWndAddFriend::OnCommand(UINT nID, DWORD dwMessage, CWndBase* pWndBase)
{
	return CWndNeuz::OnCommand(nID, dwMessage, pWndBase);
}
void CWndAddFriend::OnSize(UINT nType, int cx, int cy) \
{
	CWndNeuz::OnSize(nType, cx, cy);
}
void CWndAddFriend::OnLButtonUp(UINT nFlags, CPoint point)
{
}
void CWndAddFriend::OnLButtonDown(UINT nFlags, CPoint point)
{
}
BOOL CWndAddFriend::OnChildNotify(UINT message, UINT nID, LRESULT* pLResult)
{
	if (nID == WIDC_OK)
	{
		LPCTSTR szAddName;
		CWndEdit* pWndEdit = (CWndEdit*)GetDlgItem(WIDC_EDIT1);
		szAddName = pWndEdit->GetString();
		if (strlen(szAddName) < MAX_NAME)
		{
			if (strcmp(szAddName, g_pPlayer->GetName()) != 0)
			{
				if (g_pPlayer->GetWorld() && g_pPlayer->GetWorld()->GetID() == WI_WORLD_GUILDWAR)
				{
					g_WndMng.OpenMessageBox(prj.GetText(TID_GAME_GUILDCOMBAT_CANNOT_FRIENDADD));	// "수정해야함 : 길드대전장에는 친구추가를 할수 없습니다" );
				}
				else
				{
					g_DPlay.SendAddFriendNameReqest(szAddName);
					//g_WndMng.PutString( "메신저 추가 요청중입니다. 잠시만 기다려주세요", NULL, 0xffff0000 );
					CString str;
					str.Format(prj.GetText(TID_GAME_MSGINVATE), szAddName);
					g_WndMng.PutString(str, NULL, prj.GetTextColor(TID_GAME_MSGINVATE));
				}
				Destroy();
			}
			else
			{
				pWndEdit->SetString("");
				g_WndMng.OpenMessageBox(_T(prj.GetText(TID_DIAG_0056)));
				//				g_WndMng.OpenMessageBox( "자기 자신은 추가할수 없습니다. 다시 입력해주세요." );
			}
		}
		else
		{
			pWndEdit->SetString("");
			g_WndMng.OpenMessageBox(_T(prj.GetText(TID_DIAG_0057)));
			//			g_WndMng.OpenMessageBox( "이름이 너무 깁니다. 다시 입력해주세요." );
		}
		// 여기다가 승락하는 처리 추가하시오
		//		g_DPlay.SendAddFriend( m_uLeader, m_nLeaderSex );
	}
	else
	if (nID == WIDC_CANCEL)
	{
		Destroy();
	}

	return CWndNeuz::OnChildNotify(message, nID, pLResult);
}
void CWndAddFriend::OnDestroyChildWnd(CWndBase* pWndChild)
{
	if (m_pWndAddFriend == pWndChild)
	{
		SAFE_DELETE(m_pWndAddFriend);
		pWndChild = NULL;
	}
}
void CWndAddFriend::Destroy(void)
{
	SAFE_DELETE(m_pWndAddFriend);
}
void CWndAddFriend::Free()
{
	SAFE_DELETE(m_pWndAddFriend);
}
I added CWndAddFriend::OnDestroyChildWnd() / CWndAddFriend::Destroy() and CWndAddFriend::Free()

well here is the problem. When I open the Add Friend App and close it. It wont open up again. I need to close the Neuz entirely to be able to open up the APP_ADD_FRIEND.

I am learning on how it works by seeing other Wnd functions that doenst involve WndManager so I can clear things up.

If you have an tip on where I need to look I can do the rest my self.
Atm I am an bit lost.

With kind regards,
08/09/2015 17:43 Mognakor#2
Are you sure you want to destroy the APP?
Shouldn't you just close it.
08/09/2015 18:36 raventh1984#3
Well if I take an close look to some other Applets they are all getting destroyed.

It only happens when I take the m_pWndAddFriend out of WndManager.cpp inside these functions

void CWndMgr::Free()
void CWndMgr::OnDestroyChildWnd( CWndBase* pWndChild )

When I leave it in there then its working fine. I think its because CWndMgr is Class extension of CWndBase correct?
08/09/2015 19:35 Mognakor#4
Did you compare the way you create/open the applet to how other applets do it?

And can you show us the code which creates/opens your applet?
08/09/2015 21:48 raventh1984#5
Well this one is quite simple because its an existing code. Its the code to add an player to your Friends list.

Here it is
Code:
BOOL CWndMessenger::OnChildNotify( UINT message, UINT nID, LRESULT* pLResult ) 
{
        if( nID == WIDC_ADD )
	{
//		if( g_WndMng.GetWndBase( APP_ADD_FRIEND ) == FALSE )
		if( !g_WndAddFriend.m_pWndAddFriend )
		{
			g_WndAddFriend.m_pWndAddFriend = new CWndAddFriend;
			g_WndAddFriend.m_pWndAddFriend->Initialize();
			
		}
	}
}
Because I no longer use the CWndMngr I have it now like the above code instead of

Code:
BOOL CWndMessenger::OnChildNotify( UINT message, UINT nID, LRESULT* pLResult ) 
{ 
	if( nID == WIDC_ADD )
	{
//		if( g_WndMng.GetWndBase( APP_ADD_FRIEND ) == FALSE )
		if( !g_WndMng.m_pWndAddFriend )
		{
			g_WndMng.m_pWndAddFriend = new CWndAddFriend;
			g_WndMng.m_pWndAddFriend->Initialize();
			
		}
	}