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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exiting Program

Status
Not open for further replies.

milner

Programmer
Apr 15, 1999
28
0
0
CA
I have an application using MFC Doc/View Arcitecture. My program currently starts by showing the application Frame with my form view inside as normal.

I'm now trying to add a login dialog to force users to log in before they can use the application. I've made a login dialog and it works fine. Right now, I show it (DoModal) during my view's OnInitialUpdate() Function. The login dialog doesn't close until the password is correct.

My Problem is, I want to have a cancel button on the login dialog which will close the application without showing the main window at all. Currently, if I use something like PostQuitMessage(0) or exit(0) I get memory leaks when I exit as follows:

[tt]Warning: destroying CSingleDocTemplate with live document.
Detected memory leaks!
[/tt]

How can I exit BEFORE I show my View?? If I can't, what is a way around this?

Thanks,

- Mike -
 
Mike,

> How can I exit BEFORE I show my View?? If I can't, what is
> a way around this?

Wow, there are so many ways to do both, and I'm sure I don't know all of them!

Ok so here is a simple one, in your CWinApp derived function ::InitInstance() you probably have some code that looks like this:

m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

then you return TRUE which causes the application to continue to run.

So before you show the MainFrame window you can run your log in dialog and if it returns 'CANCEL' then you can return FALSE from InitInstance() which will cause the application to exit without showing the MainFrame window.

Now as I stated earlier, there are, I don't know how many, other techniques to solve your problem.

Hope this helps
-pete
 
The only problem with this is that I have the list of users in my Document (Because I load them from the same place as the rest of my document and I need to edit them in my application).

How can I get my document data into my CWinApp derived class?

Thanks

- Mike -
 
Mike,

Here we have a great example of how someones time is wasted when a poster asks for a solution without providing all of the operational specifications, criteria and restrictions. Now you need a different solution due to your previously excluded information.

Create another view for the application and make it the first view. It can be something real simple like a bitmap with a message saying that no one is logged in. Have all of your menu items disabled accept for things that the user can do before they are logged in like, exit and 'log in'.

Once they select the login dialog and log in you switch the view to your main application view.

You can still display the login dialog at startup if that is desired.

Good luck
-pete
 
Mike,

1. Start Your Dialog before pDocTemplate created (the best way - in InitInstance() on this place:
CSingleDocTemplate* pDocTemplate;
CMyDialog dlg;
dlg.DoModal();
pDocTemplate = new CSingleDocTemplate(...);
etc.). But not at begin InitInstance()!
2. If You call Your Dialog from another function with CStrings usage or use CStrings in InitInstance() or Your Dialog before You exits , some memory leaks can be from these CStrings. Replace CStrings with char[]. Some other objects makes leaks to. Try to use new - delete with these objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top