|
I have a CDialogImpl-based class, implementing a modeless dialog. My application can have a number of such dialogs, so I'm using this code to create one:
CMyDialog *pDlg = new CMyDialog;
pDlg->Create(NULL);
pDlg->ShowWindow(SW_SHOW); When user will press the close-button in the upper right corner of my dialog - I must destroy the object and the window, so I'm using DestroyWindow(); in WM_CLOSE handler and delete this; in OnFinalMessage().
The problem is that the program falls with ASSERT(pThis->m_pCurrentMsg == &msg) in atlwin.h, line 2281. Btw, if I close the main application - these dialogs are destroying without any ASSERTs...
How can I delete the class after the window have been destroyed?
With the best regards, Vitaly.
|
|
|
|
|
Surely if you've called DestroyWindow then that is all you need to do. Have you traced back to see what was called to cause the ASSERT? I'm betting on delete this.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
I don't think that DestroyWindow() is enough. Cause my destructor is not called in such case.
With the best regards, Vitaly.
|
|
|
|
|
The problem is this code near the bottom of that function in atlwin.h
pThis->OnFinalMessage(hWnd);
You can't call delete this from a function that's being called by this. I hope that makes sense.
The way I would solve this is to create a WM_USER function which does the delete from the main app such as:
#define WM_USER_DELETE_DIALOG WM_USER+1
CMyDialog::DeleteMe()
{
PostMessage(parent, WM_USER_DELETE_DIALOG , 0, 0);
}
CApp::OnDeleteDialog()
{
delete pDlg;
}
|
|
|
|
|
That's odd, though. The docs on CDialogImpl::OnFinalMessage() say:Called after receiving the last message (typically WM_NCDESTROY ). Note that if you want to automatically delete your object upon the window destruction, you can call delete this; here.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
I've read the same in MFC documentation. And I've thought that atl works the same way but it doesn't
I don't like idea with WM_USER-based message but it seems to be the only way to solve this problem.
With the best regards, Vitaly.
|
|
|
|
|
Yes, I've though about this way. The problem is that I will have many windows like this. Different windows, different classes... So I must implement some kind of window manager for them.
But I still hope that delete this; will work somewhere
With the best regards, Vitaly.
|
|
|
|
|
From the WTL newsgroup (sign up! -- http://groups.yahoo.com/group/wtl)
From: "Tim Smith" <tim.smith@o...>
Date: Thu Jan 18, 2001 11:41 am
Subject: Re: DestroyWindow and OnFinalMessage ?
Here is a basic roadmap of what you need to do. First, inside your
dialog box class, you need make a new version of DialogProc. I just
copied the DialogProc from ATL.
Next, add a flag to your class called m_fDeferDelete. Initialize it
to false.
Inside your new DialogProc, in the WM_NCDESTROY clause after the call
to OnFinalMessage, add the following lines:
if (pThis ->m_pCurrentMsg == NULL)
delete pThis;
else
pThis ->m_fDeferDelete = true
Then in your new DialogProc, after the call to ProcessWindowMessage,
add the code:
if (pThis ->m_fDeferDelete && pOldMsg == NULL)
{
delete pThis;
return FALSE;
}
There might be a better way to do it, but this will work.
In my real code, I created a new base class that included an auto
delete flag. All my dialogs are based on this class. If the auto
delete flag is not set, then the dialog works normally. If it is
set, then the class self deletes as expected.
|
|
|
|
|
In a multi user environment / LAN it is sometime required to figure out who
/ which user on the LAN is "Holding" a file open (maybe that user crashed
and is not even aware of that) and I need to replace the file...
So I need a window with a user list and for each user - list of files they
have a hold on, or alternatively - a list of files and which users are
currently holding these files.
Any help will be appreciated
Thanks,
Alex
|
|
|
|
|
|
I'm looking for a tool to quickly implement syntax coloring in a RichEditCtrl. Most of what I have seen appears to be complex for the sake of being complex. Any suggestions to chase down some tools or some direction in creating my own would be greatly appreciated. I have created my own syntax coloring, but I'm not happy with the performance or flexibility.
Thanks!!
VDC
|
|
|
|
|
I have a problem when rendering a document in a CScrollView derived class. I started with both a simple approach (a version of HexView from a sample included with the book, "Windows 95 MFC"), and a more complex one from an MS site. In each case, everything "almost" works. However as you scroll, on occassion, it appears as though a remnant from a previous line persists. In adapting these two approaches, the problem either doesn't exist with the original code or is minimal. It is only when I try to add my own data that the problem shows up. Initially I thought that I had incorrectly adapted the sample's logic and while that is probably the case it is not obvious.
In both cases, the sample code is retrieving data from a file - reading the data into an array then pulling out the appropriate number of array lines for display. What I am trying to do is the equivalent of dynamically adding some data to what is pulled out of the array and appending that data for display in the view. The reason is that once I can determine the real problem I will use the logic to display information that is interpreted (not a one::one relationship with what is on the file/document).
Anyway, that is when the problem is exhibited, once additional data is added that wasn't retrieved from the file.
The problem must be obvious, but I don't see it.
There was too much code to try to decide what "snippet" would make this more understandable, so I havent included any. But I figured I am not the first person to run into (or create) this problem and maybe one of you have had the same problem.
Any ideas would be appreciated. Thanks - Mike
|
|
|
|
|
Hi everybody,
I have a problem with my dialog base window :
when "enter" or "escape" key is striked, my window is destroyed by OnDestroy().
I don't know why and how easily avoid this.
Could someone help me please?
Thanks.
Jean-Guillot
|
|
|
|
|
Handle OnOk() for enter and OnCancel() for escape, in which you prevent the program from terminating.
|
|
|
|
|
Hey Guys
does anyone know how to enumerate all the key containers using the crypto API and then get them displayed in a list box which the user can select one from. I have written what i think should work but it doesn't it just ends up displaying a null string ie iiiiiiiiiiiiiiiiiiiiiiiiiietc so my guess is the key stores arn't even being read and put in the string.
Your Help Is greatly Appreciated
Peter
|
|
|
|
|
to tell the truth, im quite embarrassed to ask this question.
is it possible for me to still use the resource editor even though i will not be using mfc?
you see, i'm new to visual c++, a newbie, and can't seem to understand the intricacies of the language, particularly mfc. i've decided that creating applications using the basic win32 windows api, without the use of mfc, would be a nice start for me. please tell me if this is true. or better yet, just answer the question.
|
|
|
|
|
yes. I suggest that you read a book about visual c++.
|
|
|
|
|
i have. there's not much about books about visual c++ from where i am. the thing is, its a programming reference book. class listings, fields, methods ang all that stuff. not much about explaining the programming environment. if you please, kind sir, could you explain it do me, if it won't bother you.
|
|
|
|
|
What exactly do you need explained?
You can order books via the internet, you know..
|
|
|
|
|
thank you for your interest to reply. i need the resource editor explained, if you please.
i am just a student. i have no income and books cost a lot. that is why i resort to programming reference books...best 'bang' for the buck.
|
|
|
|
|
If you can't afford to buy books ( and I was a student once too, so I know how you feel ) then I'd suggest looking for free books on the net. It's a poor substitute but could be your best bet for now. However, if you're serious about it, you *will* have to spring for some books eventually. Look at the list on this site for books that are highly recommended so you don't blow your cash.
However, it sounds to me more like you need to learn C++ before diving into Windows or MFC. MFC makes Windows programming *easier*, not harder. I'd recommend going Win32 AFTER learning it in MFC, unless you own Pethold's book, but even then, I still think it is more complex.
The resource editor allows you to create things like menus and bitmaps which you can load from the resource, meaning they are stored in your .exe file. The dialog editor allows you to design a dialog box, then you can double click on it to create a class that uses that dialog template, and use the class wizard to add message handlers for events and controls on the dialog.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
i seem to have not placed my question correctly...
here is the problem. if i dont use the mfc, i seem to create the components in my program during run time. when that happens, it is my impression that i *cant* use the DIALOG editor. i shall ask this quesion:
is it possible to use the dialog editor, even though i will not use mfc?
it is also my impression that mfc will make my program easier to write but after several tries and several programs later, i still cant understand all that other stuff that gets included in my programs. that is why i think i will do better without mfc. thanks
|
|
|
|
|
I don't know if it can be done.
I would suggest again that you don't need to understand every line of code you get for free from MFC, you just need to learn bit by bit as you use them. You should also use the msdn online as much as possible, and there is a ton of online help for MFC there.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
If the question is: can I use the Resource Editor in a Win32 application, not using MFC?
The answer is: Yes, sure!
If you create a new project with AppWizard, choosing Win32 Application -> Hello World , you can see the About dialog in the project's resources and all the other resources as well.
Is there something I missed?
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
Yes, you can use the resource editor without using MFC. I write programs all the time that do not use MFC but have dialogs, menus, icon, string, etc. I use the resource editor to create my dialogs, menu, icons, and string tables.
All the resource editor does is give you a graphical tool for editing the .rc files. There's no MFC involved when it comes to editing resources.
|
|
|
|