Create and Destroy Dialog

Ich can have a problem with destroying an dialog.
I use the following code:

void CTestPhasePPMDlg::OnBnClickedButtonStartOutput()
{
		
	if (theApp.m_pDlgPhaseOutput != NULL) {
		theApp.m_pDlgPhaseOutput->SetForegroundWindow();
		theApp.m_pDlgPhaseOutput->SetFocus();
	}
	else {		
		theApp.m_pDlgPhaseOutput = new CDlgPhaseOutput;
		theApp.m_pDlgPhaseOutput->Create(CDlgPhaseOutput::IDD);				
		// Ausgabe initialisieren		
		theApp.m_pDlgPhaseOutput->ShowWindow(SW_SHOW);	
	}	
}

void CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
{
	if (theApp.m_pDlgPhaseOutput != NULL)
	{
		theApp.m_pDlgPhaseOutput->DestroyWindow();
		delete theApp.m_pDlgPhaseOutput;
	}
}

It does show the dialog.
I also does destroy the dialog with the second button.
However if I then call the first function the application fails.
The problem is that after CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
the pointer theApp.m_pDlgPhaseOutput is NOT Null.

Am I doing something principle wrong ?

Matthias
0
4/18/2007 6:54:47 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
572 Views

Similar Articles

[PageSpeed] 51


"Matthias Pospiech" wrote:

> Ich can have a problem with destroying an dialog.
> I use the following code:
> 
> void CTestPhasePPMDlg::OnBnClickedButtonStartOutput()
> {
> 		
> 	if (theApp.m_pDlgPhaseOutput != NULL) {
> 		theApp.m_pDlgPhaseOutput->SetForegroundWindow();
> 		theApp.m_pDlgPhaseOutput->SetFocus();
> 	}
> 	else {		
> 		theApp.m_pDlgPhaseOutput = new CDlgPhaseOutput;
> 		theApp.m_pDlgPhaseOutput->Create(CDlgPhaseOutput::IDD);				
> 		// Ausgabe initialisieren		
> 		theApp.m_pDlgPhaseOutput->ShowWindow(SW_SHOW);	
> 	}	
> }
> 
> void CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
> {
> 	if (theApp.m_pDlgPhaseOutput != NULL)
> 	{
> 		theApp.m_pDlgPhaseOutput->DestroyWindow();
> 		delete theApp.m_pDlgPhaseOutput;
> 	}
> }
> 
> It does show the dialog.
> I also does destroy the dialog with the second button.
> However if I then call the first function the application fails.
> The problem is that after CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
> the pointer theApp.m_pDlgPhaseOutput is NOT Null.
> 
> Am I doing something principle wrong ?
> 
> Matthias
> 

delete theApp.m_pDlgPhaseOutput;
theApp.m_pDlgPhaseOutput = NULL;

And in general, after deleting a pointer set it NULL to avoid further 
headaches.


-- 
======
Arman

0
armancho_x1 (249)
4/18/2007 7:48:02 AM
"Matthias Pospiech" <matthias79@gmx.de> wrote in message 
news:f04fb8$jmp$1@newsserver.rrzn.uni-hannover.de...
> Ich can have a problem with destroying an dialog.
> I use the following code:
>
> void CTestPhasePPMDlg::OnBnClickedButtonStartOutput()
> {
>
> if (theApp.m_pDlgPhaseOutput != NULL) {
> theApp.m_pDlgPhaseOutput->SetForegroundWindow();
> theApp.m_pDlgPhaseOutput->SetFocus();
> }
> else { theApp.m_pDlgPhaseOutput = new CDlgPhaseOutput;
> theApp.m_pDlgPhaseOutput->Create(CDlgPhaseOutput::IDD); // Ausgabe 
> initialisieren theApp.m_pDlgPhaseOutput->ShowWindow(SW_SHOW); } }
>
> void CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
> {
> if (theApp.m_pDlgPhaseOutput != NULL)
> {
> theApp.m_pDlgPhaseOutput->DestroyWindow();
> delete theApp.m_pDlgPhaseOutput;
> }
> }
>
> It does show the dialog.
> I also does destroy the dialog with the second button.
> However if I then call the first function the application fails.
> The problem is that after CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
> the pointer theApp.m_pDlgPhaseOutput is NOT Null.
>
> Am I doing something principle wrong ?
>

You need to add

  theApp.mPDlgPhaseOutput = NULL;


after deleting it in ONBnClickedButtonEndOutput().

-- David 


0
dc2983 (3206)
4/18/2007 1:56:46 PM
A pointer will not be "null'd" out for you automatically.  The problem here 
is tha tyou are checking to see if the pointer (m_pDlgPhaseOutput) is NULL 
indicating that it is not showing at the time.  Then when you destroy it you 
don't set the point to NULL so the next time that test fails.  You will also 
want to set the pointer to NULL to initialize it as well.

Alternatively, you could choose not to destroy the window and just hide it 
until you need it again.  Then you would destroy it when you program is 
closing like in the OnClose() function in your mainframe.  It all depends on 
how often you use the window.

Tom

"Matthias Pospiech" <matthias79@gmx.de> wrote in message 
news:f04fb8$jmp$1@newsserver.rrzn.uni-hannover.de...
> Ich can have a problem with destroying an dialog.
> I use the following code:
>
> void CTestPhasePPMDlg::OnBnClickedButtonStartOutput()
> {
>
> if (theApp.m_pDlgPhaseOutput != NULL) {
> theApp.m_pDlgPhaseOutput->SetForegroundWindow();
> theApp.m_pDlgPhaseOutput->SetFocus();
> }
> else { theApp.m_pDlgPhaseOutput = new CDlgPhaseOutput;
> theApp.m_pDlgPhaseOutput->Create(CDlgPhaseOutput::IDD); // Ausgabe 
> initialisieren theApp.m_pDlgPhaseOutput->ShowWindow(SW_SHOW); } }
>
> void CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
> {
> if (theApp.m_pDlgPhaseOutput != NULL)
> {
> theApp.m_pDlgPhaseOutput->DestroyWindow();
> delete theApp.m_pDlgPhaseOutput;
> }
> }
>
> It does show the dialog.
> I also does destroy the dialog with the second button.
> However if I then call the first function the application fails.
> The problem is that after CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
> the pointer theApp.m_pDlgPhaseOutput is NOT Null.
>
> Am I doing something principle wrong ?
>
> Matthias 

0
tom.nospam (3240)
4/18/2007 2:01:14 PM
OI'm curious why the app is involved in this transaction at all.

You should not do the delete where you do it.  You should do that in the PostNcDestroy
handler.  You can then post a message telling the owner of the dialog that the dialog is
gone.

I fail to see why the app gets into the picture at all.  
				joe

On Wed, 18 Apr 2007 08:54:47 +0200, Matthias Pospiech <matthias79@gmx.de> wrote:

>Ich can have a problem with destroying an dialog.
>I use the following code:
>
>void CTestPhasePPMDlg::OnBnClickedButtonStartOutput()
>{
>		
>	if (theApp.m_pDlgPhaseOutput != NULL) {
>		theApp.m_pDlgPhaseOutput->SetForegroundWindow();
>		theApp.m_pDlgPhaseOutput->SetFocus();
>	}
>	else {		
>		theApp.m_pDlgPhaseOutput = new CDlgPhaseOutput;
>		theApp.m_pDlgPhaseOutput->Create(CDlgPhaseOutput::IDD);				
>		// Ausgabe initialisieren		
>		theApp.m_pDlgPhaseOutput->ShowWindow(SW_SHOW);	
>	}	
>}
>
>void CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
>{
>	if (theApp.m_pDlgPhaseOutput != NULL)
>	{
>		theApp.m_pDlgPhaseOutput->DestroyWindow();
>		delete theApp.m_pDlgPhaseOutput;
>	}
>}
>
>It does show the dialog.
>I also does destroy the dialog with the second button.
>However if I then call the first function the application fails.
>The problem is that after CTestPhasePPMDlg::OnBnClickedButtonEndOutput()
>the pointer theApp.m_pDlgPhaseOutput is NOT Null.
>
>Am I doing something principle wrong ?
>
>Matthias
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
4/22/2007 8:35:26 PM
Reply:

Similar Artilces:

c:/temp/FixEngine folder created
Hi everyone. I've noticed a new folder created on November 16, 2006 called c:/temp. Inside this folder is a folder called FixEngine which is empty. I have found no information yet on Microsoft.com website about it's creation. Does anyone know what created these folders and is it safe to delete c:/temp or c:temp/FixEngine. You�ve landed in a Mac Office group. Sorry, you'll have to ask somewhere else--I assume a Windows forum. On 11/21/06 6:13 PM, "Vince" wrote: > Hi everyone. I've noticed a new folder created on November 16, 2006 called > c:/temp. Ins...

creating a reversal design graph
I used to be able to create this type of graph in Excel 2003, but there does not seem to be a way to do this in Excel 2007. I am also trying to create a single subject design graph. Help with either of these would be appreciated. Hi, Maybe if you explained what a 'reversal design graph' is we could help. Or explain how you did it in xl2003 and what is not working as expected in 2007. Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Paul Reynolds" <Paul Reynolds@discussions.microsoft.com> wrote in message news:814FB8B0-FD79-46E5-AD43-38...

BuyerID in Po's be populated from BusinessPortal user who creates
My customer CE Europe have requested that the user who creates the PO in Business Portal, populates with the buyerID within the Purchase Order that is created in Great Plains. This would mean additional setup in Business Portal to associate a user with a specific Buyer ID ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and ...

Can't create count and sum totals at bottom of form
Hello, I'm trying to create some count and sum totals at the bottom of my form, but I keep getting #Name? error. All I'm trying to do is get a sum and count for each type of company and payroll type from the table that my form is bound to Master_Table). In this table I have 470 total records which add to $163,563,76 - I was able to create the Sum and count for these totals amounts, but when I try to be more specific, I run into problems. I have 2 companies (I'll call them acme and xyz) and 2 payroll types (Hourly and Salary). The detail (body) of my form contains all of the 470...

Error creating rules
Running Office 2000 suite, and Windows 2000. When trying to create a rule, outlook returns a meesage "Outlook.exe has encountered a fatal error." Any ideas on why this might happen? Thanks ...

creating serial number for vouchers
How do you create a serial number for a voucher? I've created a new item with item type - voucher when I move to the serial tab and try to add a serial number I then create serial number 1000. It shows available on the screen Move to the POS and type in the PLU for gift certificate. The screen prompts for a serial number, I type in 1000 and it says not available would you like an automatically? Press "no" and "look-up" the serial number - there it is!! Why won't the initial screen prompt allow me to add the serial number as I want? hi Cheese, try to app...

CRM 3.0/4.0: Views to show record that is created X Days Ago
I have a simple requirement to create a View with condition that the record is created x days ago, for example the record that is created 3 days ago. The only operator that is available for datetime (e.g. createdon) is only Last X Days, which if i show Last 3 Days, will show the records that were created today, yesterday, and 2 days ago. Is there any operator or any way to show the record that were created 3 days ago? I try to put condition "createdon Last 3 Days" and "NOT createdon Last 2 days", but there is no "NOT" operator in CRM. I try to insert new attribut...

Creating Football League Tables
I work for a premier football club, and wish to put results in to a format so that position and points can be updated at home showing league position week by week Cheers See http://www.xldynamic.com/source/xld.LeagueTable.html -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Andy" <Andy@discussions.microsoft.com> wrote in message news:B16ACC8D-EC8A-4B75-ADDF-77EC37F9D948@microsoft.com... >I work for a premier football club, and wish to put results in to a format >so > that position and points can be updated at home...

Quick Create for Custom Entities
Hi ALL, Do we have any provision to have Quick Create facility for Custom Entities. We are able to create the same for system entities like Contacts and Accounts. Please let us know if any workaround is available to facilitate the same. Thanks and Regards Vijay Vijay, You can use the following JavaScript code to open the quick create form: var entityTypeCode = 10000; var newRecord = openStdDlg("/_forms/QuickCreateReturn/quickcreate.aspx?crmFormSubmitObjectType=" + entityTypeCode, entityTypeCode, 400, 400); newRecord is null if the user cancels the dialog and a LookupControlI...

creating template for multiple emails
How or can one create an email template (same subject line and message)for multiple emails (approx 100's)? Needing to shorten the time it takes sending 100's of individual emails (with the same subject line and same message) to sales staff on a weekly (some times daily) basis. Company does not want sales force using other sales persons email addresses (they are contractors). Try using a Distriburtion List, send one message, it goes to all of them, or get the message ready, put your address in the TO: field, and put everyone else in the BCC: field?? That way no one can see wher...

Dialog controls
Hello. What is the unit of measurement for the dimensions of dialog controls? I had assumed pixels, but I'm now doubtful. Thanks and regards. On 4 jul, 10:45, andrew.kend...@yahoo.co.uk wrote: > Hello. > > What is the unit of measurement for the dimensions of dialog controls? > I had assumed pixels, but I'm now doubtful. > > Thanks and regards. Certainly, the unit is not pixels, it's "dialog units". From Prosise's "Programming Windows with MFC": "Horizontally, one dialog box unit is equal to one-fourth the average width of a chara...

How to set a form in dialog mode??
Hi all, I have a form that shows a combo box. This form is launched by a piece of code from another form. The VBA code needs to wait that the form has closed befor continuing, having catch the user selection. I know how to open the form in dialog mode, using docmd.OpenForm, formname,,,,,acDialog. However I start the form by instanciating a form object, like: Dim frm As Form_myForm Set frm As new Form_myForm How can I set the form in dialog mode, so that the code waits until the form closes? TIA, Philippe can't you put the part of the code that needs to wait in the on close event ...

Customization close opp form dialog
hi: Does it possible change the close opportunity form dialog?. I don´t found it. i need you help , please. i need make some modifications at this form. when close opportunity, show this form for close opportunity Please, somebody, tell me where i found that, or how custom. ...

In Visio, how do i create a toolbar that contains my most commonl.
I am trying to draw some business process models, only I find that the arrows that I want are not in the toolbar for business process models. so my questions are: 1) Where can I see a list of all available arrows ? 2) How can I ad these to my toolbar ? A search on "arrows" generates over 100 hits and creates a toolbar that is not really very useful. Thanks ...

"Can't Create Backup FIle. Save [filename] Without Backp?
I get the following message every so often when running Excel 2003 under Win XP: "Can't create backup file. Save [finename] without backup?" I respond: "OK" "Your changes could not be saved to [filename] because of a sharing violation. Try saving to a different file." I respond: "OK". It presents me with the standard window allowing me to enter a new filename, which I do, then press OK. Then I get: "Do you want to save the changes you made to [fileename]? I respond: "Yes" "Document not saved." This is VERY annoying. I am t...

dialog within a dialog
I was just wondering if there is a way to have a dialog within a dialog. I want something like a property sheet but more flexible. My hex editor has like property sheets within a dialog box. Check out the first couple of screen shots at http://www.softcircuits.com/cygnus/find.htm. Don't know that I can describe, right here, the entire proceeedure of how I did it. I know I plopped a Tab control onto my dialog template. I created dialog templates with content for each of the tabs (child style). And, in my main dialog's OnInitDialog() method, I created the child dialogs and then ...

View settings for open/save dialogs ?
Helo, Running windows 7 pro 64bit. I want to select certain icon view setting for open/save dialogs for all files/dirs. For now I was able to set custom view for certain file/dir - but all others are forced details view. I want to set them all at once and permanently. How do I do that ? Main explorer window customizes ok. thanks Vilius ...

creating charts with XY
Hi, I thought I was well versed with Excel and charting, but... How can I create a chart with several lines, where I indicate the X and Y coordinates? For example, a chart with X = 100, Y = 100, and another line where X = 170, Y = 120? Can this be done in either Excel directly, or VBA? Thanks in advance, Willy Im sorry but I dont understand what you want? "Willy" wrote: > Hi, I thought I was well versed with Excel and charting, but... > How can I create a chart with several lines, where I indicate the X and > Y coordinates? > For example, a chart with X = 100, Y = 100...

Error
Outlook 2002(XP) - After receiving an email with an email address in the body of the email, we click on the email address and it opens up a box that says, "Can't create this item". If we click on a website address in the body of the email, it works. It just does not want to create a new outgoing email. I have repaired/reloaded outlook a few times with out any success. I have removed "HOTBAR" & some other adware crap using Lavasoft's Adaware. Repaired/Reloaded Outlook after removing "HOTBAR". I could not find any default email formats in t...

Bypassing Pop-Up Dialogs
I have a series of queries I must run on a monthly basis, that are make-table type. The tables created already "exist." I have button control on a form, that, when pressed, it initiated the series of about 10 queries that create all the tables. The problem is that I get a pop-up telling me, for example, that it is going to overwrite the data in the output table, and then, at the end, it asks me if it is ok to write all the rows into the table. My response are always "yes" to all 30+ of these queries pop-ups. Is it possible to have change a setting to automatical...

Dynamic change of dialog controls' properties
I've recently started to learn programming for Windows with MFC, and it seems quite difficult to find any pertinent info on how to dynamically change properties of the dialog controls that are specified in a resource file. For example, there are static text, input field and spin button controls that are initially disabled or grayed (i.e. has the WS_DISABLE attribute). I want to change their status to the opposite when one of the parent radio buttons is selected or de-activated. How do I do this Thanks a lot YuriP "YuriP" <anonymous@discussions.microsoft.com> wrote in mes...

Resizing the dialog bar
Hi, I am trying to resize the dialog bar programatically to fit exactly to its parent window's width. I have problem with this dialogbar when working on different monitors. Can any one please help me? Thanks Show your code. joe On Wed, 16 Dec 2009 09:08:01 -0800, Ram <Ram@discussions.microsoft.com> wrote: >Hi, > >I am trying to resize the dialog bar programatically to fit exactly to its >parent window's width. > >I have problem with this dialogbar when working on different monitors. > >Can any one please help me? > &g...

how do I create a handwritten signature?
I would like a facimile hand writen signature to my emails but do not know how to do it and add it to my outlook account You can scan in your signature so it will become an image. Then you can insert it like any other image into your electronic signature. For details about the signature feature in Outlook see; http://www.howto-outlook.com/howto/signatures.htm -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World Questions, Real World A...

How do I create a windows form that is an ellipse
Hi! Normally when you create a form it's shape is a rectangle. Now I want to create a windows form that is not a rectangle but an ellipse instead I wonder if anyone have some good example of code where this is done. //Tony "Tony Johansson" <johansson.andersson@telia.com> wrote in message news:ec84YWZ0KHA.348@TK2MSFTNGP02.phx.gbl... > Hi! > > Normally when you create a form it's shape is a rectangle. > Now I want to create a windows form that is not a rectangle but an ellipse > instead > I wonder if anyone have some good ex...

[ANN] Create a TinyURL-no more broken links
Part 4 in the series AppleScripting Entourage: "Create a TinyURL-no more broken links" describes how to use an AppleScript to automate the process of creating a TinyURL as well as an alternative to running AppleScripts in Entourage with TypeIt4Me and TextExpander. If you're not familiar with a TinyURL, it's an online service that converts long URLs into short ones more appropriate to share in email. It's especially helpful sending out long links.Long links that are notorious for breaking. A TinyURL will not break in email postings and never expires. Create a TinyURL-no...