Password dialog at application startup

From: Selin Metin (nospam_at_nospam.com.tr)
Date: 04/13/04


Date: Tue, 13 Apr 2004 14:40:21 +0300

Hi everyone,
I want to display a password dialog before my application starts in order to
get the username and password. If they are wrong or dialog box returns
IDCANCEL , the application won't start. So I included the header file for
the password dialog class to the *app.cpp file of my application and did the
following in InitInstance:

////////////////////////////////////////////////////
BOOL CMyApp::InitInstance()
{
 SetRegistryKey(_T("Local AppWizard-Generated Applications"));

 LoadStdProfileSettings(); // Load standard INI file options (including
MRU)

 // Create username and password db if not exists
 CreateUserDB();

CPasswordDlg dlg;
int nRet = dlg.DoModal();

if (nRet == IDCANCEL)
    return FALSE;

 // Register the application's document templates. Document templates
 // serve as the connection between documents, frame windows and views.

 CSingleDocTemplate* pDocTemplate;
 pDocTemplate = new CSingleDocTemplate(
  IDR_MAINFRAME,
  RUNTIME_CLASS(CMyDoc),
  RUNTIME_CLASS(CMainFrame), // main SDI frame window
  RUNTIME_CLASS(CMyView));
 AddDocTemplate(pDocTemplate);

 // Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 // Dispatch commands specified on the command line
 if (!ProcessShellCommand(cmdInfo))
  return FALSE;

 // The one and only window has been initialized, so show and update it.
 m_pMainWnd->ShowWindow(SW_SHOW);
 m_pMainWnd->UpdateWindow();

 return TRUE;
}
////////////////////////////////////////////////////

The dialog box appears and when correct username and password are entered
and OK button is clicked, the application should start with the priviledges.
However, nothing is displayed on the emulator window when IDOK returns from
the password dialog. Although I can see that my application is running from
remote kernel tracker, I can't see its view. If I call DoModal method after
m_pMainWnd->UpdateWindow(), both the dialog box and my application's view
are displayed. But I don't want my application to be visible before correct
password is entered.

How can I accomplish this task properly?
TIA,

--
Selin Metin
selinm_at_esit_dot_com_dot_tr