CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Reopen the Dialog.

  1. #1
    Join Date
    May 2015
    Posts
    430

    Reopen the Dialog.

    Hi,
    As per discussion one month back, I tried to create the MFC dialog from the existing one. But now when trying to test various scenarios, i am facing the issue. Actually, the dialog is created and handle is stored in the global.
    Now when I close this window and parent dialog, and reopen, them, (using the global handle, which is non null), i am not seeing the dialog, popping up again.

    The codefor the child window is :
    Code:
    #pragma warning (push, 3)
    #include "stdafx.h"
    #include "bcvcpch.h"
    #include "resource.h"
    #include "TACResultAnalysisDlg.h"
    #include "TACPlanDlgMgr.h"
    #include "TACPlanDataMgr.h"
    
    #include "plmn.h"
    #include "FilterComboBox.h"
    #include "Filters.h"
    #include "RegistryCache.h"
    #include "IVectorContainer.h"
    #include "DataMgr\DataManager.h"
    #include "DataMgr\ILogicalLayerManager.h"
    #include "MultiTechCell.h"
    #include "TechCellParams.h"
    #include "GSMCellParams.h"
    #include "ConfigCarrierBase.h"
    #include "CellCarrierBase.h"
    #include "Is95SectorCarrier.h"
    #include "view\distance.h"
    #include "distancechanger.h"
    #include "3g.hh"
    #include "asset.hh"
    #include "enterprise.hh"
    #include "version.h"
    #include "LicenseNames.h"
    #include "security.h"
    #include "ai_DBCore.h"
    #include "CoreSecurity.h"
    #include "GlobalTechTypeGuru.h"
    #include "GlobalObjectTypeGuru.h"
    #include "BO_FilterHelper.h"
    #include "progress.h"
    #include "WindowPlacementHelper.h"
    #include "ai_stdgui.h"
    #include "Reporter.h"
    #include "..\Core\UserGroupInstance.h"
    #include "..\Core\UserGroupManager.h"
    #include "..\Core\DBUser.h"
    #include "LogicalLayerManager.h"
    #include "DataManager.h"
    #include "DataMgr\BO_DBHelper.h"
    #include "ai_dbguiAFX.h"
    #include "ai_msg.h"
    #include "sybase.h"
    #include <sstream>
    #include "view\masterview.h"
    #include "RendererTypes.h"
    #include <shlobj.h>
    
    //#include "sitedlg.h"
    //#include "aicommondlgs.h"
    #include "ForeignLanguageSupport.h"
    using namespace ForeignLanguageSupport;
    
    #pragma warning (pop)
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    static const char* INI_FILE_SECTION		= "TACResultAnalysisSiteTree";
    static const char* INI_FILE_INTFCOLUMNS = "TACResultAnalysisCellDetails";
    const int SRC_COL_CENTRAL_SITE			= 0;
    const int SRC_COL_SITES					= 1;
    
    
    TACResultAnalysisDlg::TACResultAnalysisDlg(CWnd* pParent /*=NULL*/)
    	: AIMFCDialog(TACResultAnalysisDlg::IDD, pParent),
    	m_AnalysisFilter(NULL),
    	m_OWLModule(NULL),
    	m_OWLWindow(NULL),
    	m_nOldFilterSelIndex(-1),
    	m_nOldSiteSelIndex(-1),
    	m_bSiteListSetup(false),
    	m_bInFilterControlCreate(false)
    {
    	//{{AFX_DATA_INIT(TACResultAnalysisDlg)
    	//}}AFX_DATA_INIT
    	m_oldHeight = 650;
    	m_oldWidth = 900;
    
    
    	m_minDlgWidth = 0;
    	m_minDlgHeight = 0;
    	m_nLastDlgWidth = 0;
    	m_nLastDlgHeight = 0;
    	m_DispMode = TGNETWORK_UNKNOWN;
    	m_nSortedColumn = 0;
    	m_szSearchText = "";
    
    	m_bRenderOn2DView = false;
    
    }
    
    TACResultAnalysisDlg::~TACResultAnalysisDlg()
    {
    	delete m_AnalysisFilter;
    	delete m_OWLModule;
    }
    
    void TACResultAnalysisDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	DDX_Control(pDX, IDCANCEL, m_CloseButton);
    	DDX_Control(pDX, IDC_TAC_SITE_LIST, m_SiteTree);
    }
    
    BEGIN_MESSAGE_MAP(TACResultAnalysisDlg, AIMFCDialog)
    	//{{AFX_MSG_MAP(TACResultAnalysisDlg)
    	ON_BN_CLICKED(IDCANCEL, OnCloseMessage)
    	ON_WM_CLOSE()
    	ON_WM_SIZE()
    	ON_WM_GETMINMAXINFO()
    	ON_WM_HELPINFO()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	//}}AFX_MSG_MAP
    	ON_BN_CLICKED(IDC_APPLYTOSITEDB, &TACResultAnalysisDlg::OnBnAppltSiteDB)
    END_MESSAGE_MAP()
    
    BOOL TACResultAnalysisDlg::OnInitDialog() 
    {
    	CDialog::OnInitDialog();
    	
    	WindowPlacementHelper::RestorePosition(m_hWnd, GetUniqueName(),0, 0, SW_HIDE);
    
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    
    	CRect DlgRect;
    	GetWindowRect(&DlgRect);
    	m_minDlgWidth = DlgRect.Width();
    	m_minDlgHeight =  DlgRect.Height();
    
    	m_DispMode = TgNetType::TGNETWORK_LTE;
    
    	LangSpecificSymbolSupport objLSSS;
    	std::string strsymbol =  objLSSS.ReturnSymbol(LanguageSpecificSymbol::SQUARE);
    	CString strSquare = strsymbol.c_str();
    	switch (m_DispMode)
    	{
    	case TGNETWORK_LTE:
    		CellColStrings.push_back(CellColData("Central Site [ TAC ]",50));
    		CellColStrings.push_back(CellColData("List of Sites",50));
    		break;
    	}
    
    	CString windowText;
    	if (m_DispMode == TGNETWORK_UNKNOWN)
    	{
    		windowText = "No TAC Result in memory";
    	}
    	else
    	{
    		windowText = GetTechString()+ " TAC Result Analysis";
    	}
    	SetWindowTextA (windowText);
    
    	m_strIniSiteTree = INI_FILE_SECTION;
    	m_strIniIntfParams = INI_FILE_INTFCOLUMNS;
    	m_strIniSiteTree += GetTechString();
    
    	ReadFromINI();
    
    	m_SiteTree.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE);
    
    	for (size_t i = 0; i < CellColStrings.size(); i++)
    	{
    		m_SiteTree.InsertColumn((int)i,	CellColStrings[i].m_strname,	LVCFMT_LEFT, CellColStrings[i].m_defWidth); 
    	}
    	if(!m_OWLModule)
    	{
    		HINSTANCE hInst = AfxGetResourceHandle();
    		m_OWLModule = new TModule("",hInst);
    	}
    
    	if(!m_OWLWindow)
    	{
    		m_OWLWindow = new TWindow(m_hWnd);
    	}
    
    	// Get the TAC list stored in the TACDlgManager
    	TACPlanDataMgr * pTacData								= TACPlanDlgMgr::GetInstance()->GetTacPlanDataMgr();
    	std::map<int,  std::vector<int> > sAssignedTacSites		= TACPlanDlgMgr::GetInstance()->GetTACAssignResult();
    	std::map<std::string, int>			sSiteIdToSiteKeyMap = TACPlanDlgMgr::GetInstance()->GetSiteIdToSiteKeyMap();
    	int nRowIndex(0);
    	bool bIsfirstCentralsite(false);
    	for (auto configData : pTacData->GetTACWizData()->m_TacPlanData.GetConfigData())
    	{
    		int nIndex(0);
    		bIsfirstCentralsite = TRUE;
    
    		nIndex = m_SiteTree.InsertItem(m_SiteTree.GetItemCount(), (configData.GetCentralSite()+"  [ "+std::to_string(configData.GetTAC()).c_str() + " ]"));
    		for (auto sSiteKey : sAssignedTacSites[configData.GetTAC()])
    		{
    			if (bIsfirstCentralsite == FALSE)
    				nIndex = m_SiteTree.InsertItem(m_SiteTree.GetItemCount(), _T(""));
    
    			CString sSiteId;
    
    			for (std::map<std::string, int>::const_iterator it = sSiteIdToSiteKeyMap.begin(); it != sSiteIdToSiteKeyMap.end(); ++it)
    			{
    			    string site;
    				if (it->second == sSiteKey)
    				{
    					site = it->first;
    					sSiteId = site.c_str();
    					break;
    				}
    			}
    
    			m_SiteTree.SetItemText(nIndex, SRC_COL_SITES, sSiteId);
    
    			int sCentralSiteId = sSiteIdToSiteKeyMap[std::string(configData.GetCentralSite())];
    			m_SiteTree.SetItemData(nIndex, (DWORD)(sSiteIdToSiteKeyMap[std::string(configData.GetCentralSite())]));
    
    			bIsfirstCentralsite = FALSE;
    		}
    
    		nRowIndex++;
    	}
    
    
    	return TRUE;
    }
    
    CString TACResultAnalysisDlg::GetTechString()
    {
    	return CString(MAIN_NET_TYPE_STRINGS_SWITCH(m_DispMode));
    }
    
    void TACResultAnalysisDlg::OnCloseMessage() 
    {
    	// Do we need to cleanup site tree ?
    	WindowPlacementHelper::SavePosition(m_hWnd, GetUniqueName());
    
    	WriteToINI();
    
    	ShowWindow(SW_HIDE);
    
    	//CDialog::OnClose();
    	//DestroyWindow();
    
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////OVERRIDES///////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////
    
    
    LPCSTR TACResultAnalysisDlg::GetUniqueName()
    {
    	return "Interference Analysis Dialog";
    }
    
    void TACResultAnalysisDlg::MoveTheWindow(CWnd* pWnd, int x, int y, bool bStretchX, bool bStretchY)
    {
    	if (pWnd)
    	{
    		CRect rect;
    		pWnd->GetWindowRect(rect);
    		ScreenToClient(rect);
    		if (!bStretchX && !bStretchY)
    		{
    			pWnd->MoveWindow(rect.left+x ,rect.top+y,rect.Width(), rect.Height());
    		}
    		else if (bStretchX && !bStretchY)
    		{
    			pWnd->MoveWindow(rect.left ,rect.top+y,rect.Width()+x, rect.Height());
    		}
    		else if (!bStretchX && bStretchY)
    		{
    			pWnd->MoveWindow(rect.left+x ,rect.top ,rect.Width(), rect.Height()+y);
    		}
    		else // bStretchX && bStretchY
    		{
    			pWnd->MoveWindow(rect.left,rect.top ,rect.Width()+x, rect.Height()+y);
    		}
    	}
    }
    
    void TACResultAnalysisDlg::ReadFromINI()
    {
    	for (size_t i = 0; i < CellColStrings.size(); i++)
    	{
    		CellColStrings[i].m_defWidth = RegistryCache::GetInstance().GetEnterpriseProfileInt(m_strIniSiteTree, CellColStrings[i].m_strname, CellColStrings[i].m_defWidth); 
    	}
    
    }
    
    void TACResultAnalysisDlg::WriteToINI()
    {
    	for (size_t i = 0; i < CellColStrings.size(); i++)
    	{
    		RegistryCache::GetInstance().WriteEnterpriseProfileInt(m_strIniSiteTree, CellColStrings[i].m_strname, m_SiteTree.GetColumnWidth((int)i));
    	}
    }
    
    void TACResultAnalysisDlg::NetWorkChanged()
    {
    }
    
    void TACResultAnalysisDlg::TgNetWorkChanged()
    {
    }
    
    void TACResultAnalysisDlg::OnReport()
    {
    }
    
    void TACResultAnalysisDlg::CreateExcelRowFromCtrl(const int row, IAIReporter* reporter, CListCtrl& ListControl)
    {
    	CHeaderCtrl* pHeader = ListControl.GetHeaderCtrl();
    	CString str;
    	const int numItems = pHeader->GetItemCount();
    	for (int i =0; i < numItems; i++)
    	{
    		CString str;
    		str = ListControl.GetItemText(row,i);
    		reporter->add_cell_string(str, REPORTERFLAGS_UNSPECIFIED);
    	}
    }
    
    // TODO_PDK: As of now results are applied to site DB 
    // irrespective of "ApplySiteDB" Button is pressed.
    // Use the following function, in case of selective application.
    void TACResultAnalysisDlg::OnBnAppltSiteDB()
    {
    	POSITION pos = m_SiteTree.GetFirstSelectedItemPosition();
    	int nItem = m_SiteTree.GetNextSelectedItem(pos);
    
    	int nCentralSiteid = (int)m_SiteTree.GetItemData(nItem);
    }
    The parent dialog is:
    Code:
    void TACPlanDlgMgr::LaunchTACPlanWiz(TWindow* parent, TgNetType netType, TACPlanDataMgr* pTACPlanDataMgr)
    {
    	// Enter the Wizard
    	CWnd* wndParent = CWnd::FromHandle(parent->Handle);
    	AIWindowsDisabler	OWLWind(parent);
    	AIMFCWindowDisabler MFCWind(NULL);
    	OWLWind.Disable();
    	MFCWind.DisableMFCWindows();
    
    	if (!pTACPlanDataMgr)	//	we will provide the manager here instead
    	{
    		TACWizData wizData;
    		wizData.SetNetType(netType);
    
    		m_pDataMgr = new  TACPlanDataMgr(netType, &wizData);
    
    		TACPlanWizard TACPlanWizDlg(parent, nullptr, wndParent, 0, m_pDataMgr);
    
    		assert(m_pDataMgr);
    
    		if (TACPlanWizDlg.DoModal() == ID_WIZFINISH)
    		{
    			//TACPlanAnalysis tacPlanAnalysis;
    			std::list<int> plannedCellkeyList;
    			MDWORD carrierBitmaskInUse;
    			TACPlanWizDlg.GetPlannedCellKeyList(plannedCellkeyList, wizData.GetNetType(), carrierBitmaskInUse);
    			Region planReg = LocPlannerHelper::GetContainingRegion(netType, plannedCellkeyList, 100);
    			wizData.m_TacPlanData.SetCellKeys(plannedCellkeyList);
    			wizData.m_TacPlanData.SetNetType(netType);
    
    			m_pLogFile = fopen(wizData.m_TacPlanData.GetAlgorithmData().GetLogfileName().c_str(), "a");
    
    			if (wizData.m_TacPlanData.GetNbrOption() == TACPlanData::NbrOption::CalcNbr)
    			{
    				NbrDialogManager& nbrDlgMgr = NbrDialogManager::GetInstance();
    				CWnd* pWndNbranalysis = nbrDlgMgr.GetAnalysisWindow();
    				if (pWndNbranalysis)
    				{
    					MFCWind.RemoveWindowFromDisabledList(pWndNbranalysis);
    					nbrDlgMgr.CloseAnalysisWindow();
    				}
    
    				nbrDlgMgr.LaunchTACNbrWiz(parent, netType, planReg, plannedCellkeyList, carrierBitmaskInUse);
    
    
    			}
    
    			//AI_Message::instance()->Add("TAC planner: calculation started.");
    			if (RunTAC_Algorithm())
    			{
    				if(m_pLogFile!=NULL)
    					fprintf(m_pLogFile, "Running TAC Algo \n");
    				//AI_Message::instance()->Add("TAC planner: calculation completed.");
    			}
    			bool res = CreateTACResultAnalysisDlg();
    
    		}
    	}
    	else //Array Wizard executing in else condition
    	{
    		ASSERT(0); // not_impl
    	}
    	OWLWind.Enable();
    	MFCWind.EnableMFCWindows();
    
    	if(m_pLogFile!=NULL)
    		fclose(m_pLogFile);
    }
    
    bool  TACPlanDlgMgr::CreateTACResultAnalysisDlg()
    {	
    	//get resources from this module
    	AFX_MANAGE_STATE(AfxGetStaticModuleState())
    
    	if (m_pResultAnalysisDialog)
    	{
    		WINDOWPLACEMENT windowPlace;
    		windowPlace.length = sizeof(WINDOWPLACEMENT);
    		BOOL bOk = ::GetWindowPlacement(m_pResultAnalysisDialog->m_hWnd, &windowPlace);
    		if (bOk)
    		{
    			windowPlace.flags = WPF_SETMINPOSITION;
    			if (windowPlace.showCmd == SW_SHOWMINIMIZED)
    			{
    				::ShowWindow(m_pResultAnalysisDialog->m_hWnd,SW_RESTORE);
    			}
    		}
    		::BringWindowToTop(m_pResultAnalysisDialog->m_hWnd);
    		return true;
    	}
    	else
    	{
    		m_pResultAnalysisDialog = new TACResultAnalysisDlg();
    		if ( m_pResultAnalysisDialog )
    		{
    			m_pResultAnalysisDialog->Create(TACResultAnalysisDlg::IDD, GetLocationPlannersMainFrameWindow() );
    			m_pResultAnalysisDialog->ShowWindow(SW_SHOW);
    			return true;
    		}
    	}
    	return false;
    }
    When rerun, again after the close the red portion executes, as the handle is non null, but window never gets displayed

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,930

    Re: Reopen the Dialog.

    What if you add (the block in blue)?
    Code:
    	if (m_pResultAnalysisDialog)
    	{
    		WINDOWPLACEMENT windowPlace;
    		windowPlace.length = sizeof(WINDOWPLACEMENT);
    		BOOL bOk = ::GetWindowPlacement(m_pResultAnalysisDialog->m_hWnd, &windowPlace);
    		if (bOk)
    		{
    			windowPlace.flags = WPF_SETMINPOSITION;
    			if (windowPlace.showCmd == SW_SHOWMINIMIZED)
    			{
    				::ShowWindow(m_pResultAnalysisDialog->m_hWnd,SW_RESTORE);
    			}
    			else
    			{
    				::ShowWindow(m_pResultAnalysisDialog->m_hWnd, SW_SHOW);
    			}
    		}
    		::BringWindowToTop(m_pResultAnalysisDialog->m_hWnd);
    		return true;
    	}
    Last edited by VictorN; January 15th, 2021 at 07:57 AM.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2015
    Posts
    430

    Re: Reopen the Dialog.

    Thanks a lot Victor i tried it is not working.

    Code:
    	if (m_pResultAnalysisDialog)
    	{
    		WINDOWPLACEMENT windowPlace;
    		windowPlace.length = sizeof(WINDOWPLACEMENT);
    		BOOL bOk = ::GetWindowPlacement(m_pResultAnalysisDialog->m_hWnd, &windowPlace);
    		if (bOk)
    		{
    			windowPlace.flags = WPF_SETMINPOSITION;
    			if (windowPlace.showCmd == SW_SHOWMINIMIZED)
    			{
    				::ShowWindow(m_pResultAnalysisDialog->m_hWnd,SW_RESTORE);
    			}
    			else
    			{
    				::ShowWindow(m_pResultAnalysisDialog->m_hWnd, SW_SHOW);
    			}
    		}
    		::BringWindowToTop(m_pResultAnalysisDialog->m_hWnd);
    basically, the bOk is false, so doesnot go inside if (boK)

  4. #4
    Join Date
    May 2015
    Posts
    430

    Re: Reopen the Dialog.

    Basically i was relooking into code, and wondering, after the CLOSE, the window is destroyed, but the handle is still having not deleted. Is it wrong ? So tried the following it works, but not sure whether it is correct as per MFC

    Code:
    void TACResultAnalysisDlg::OnCloseMessage() 
    {
                    // Do we need to cleanup site tree ?
                    WriteToINI();
    
                    CDialog::OnClose();
                    DestroyWindow();
    
                    TACPlanDlgMgr::GetInstance()->CloseAnalysisDialog();
    
    }
    
    And in TACPlanDlgMgr.h
    
    void CloseAnalysisDialog()                                                                                                                                           
    { 
    delete m_pResultAnalysisDialog;
                   m_pResultAnalysisDialog = NULL;
    }
    So with this everytime a new window is created and InitDialog is called.

    If we just hide and show, the contents maynot get updated, because the InitDialog maynot get called again

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,455

    Re: Reopen the Dialog.

    What overly complicated code. Create a modeless dialog. Make its parent window the main app window. Store the pointer to it in the AfxApp (so you can access it from anywhere). Expose a method that hides/shows the dialog. Inside this method, you call UpdateData(..) to refresh the data as well as hide or show the dialog, and/or any resizing.

    You call it anywhere inside the code with GetAfxApp()-GetMyFancyModelessDlg().Show(TRUE);

    Note: the GetAfxApp() call may not be the correct name of the built-in method.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)