Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ensuring one instance of dialog box

Status
Not open for further replies.

rishabhs

Programmer
Nov 25, 2002
5
US
dear all
i have an mfc dialog based app with frame as main window.
on app start an icon appears at the system tray and on dbl clicking that a dialog box appears. the problem is that on every dbl click, a new dialog box appears
how do i ensure that only one dialog appears at a time?

can anyone suggest something?

thanx
 
Hi,

In your app declare a pointer to the dialog box and in the apps constructor set it to 0. In your hander for the dblclick do a test to see if the pointer is 0, if it is 0 then you create an instance of the dialog. If the dialog does exists then show it, since it's only hidden when "parked" in the systray.

Code:
if (!m_pResults)
{
    // Dialog doen't exist so create it.
    m_pResults = new CSearchResults(m_pSearch, this) ;
    if (m_pResults)
	m_pResults->Create(CSearchResults::IDD, this) ; 
}
if (!m_pResults)
    AfxMessageBox("Unable to create Results Form!") ; 
else
{
    if (m_pResults->m_Connected)
    {
	if (!m_pResults->IsWindowVisible())
	{ m_pResults->ShowWindow(SW_SHOW) ; }
	m_pResults->StartSearch() ;
	m_pResults->SetFocus() ;
    }
    else
	SendMessage(UM_DESTROY_DIALOG, 0, IDD_SEARCH_RESULTS) ;
}

The code above works for me in that I create a single search results window. This window is then used to display results from a search done by the User. If the change the search pattern while the window is open all that happens is that the results displayed are changed.

HTH
--

William
Software Engineer
ICQ No. 56047340
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top