Solved

Closing A File Handle And Initializing A Diaglog Box Value

Posted on 1998-02-08
4
193 Views
Last Modified: 2010-04-10
1.)  I have a dialog based application that opens a file with creatfile.  The file is then wrote to when the user hits the patch button and the application exits.  Now if the user hits the cancel button the program exits and does not write to the file.  Now my question is where should I close the file handle with CloseHandle();.  Right now I am closing the handle in the Patch function, but to me it seems as if the user clicks the cancel button the handle will not be closed.  I am thinking I should put The closehandle in the destructor of the class (of course checking to see if the handle exists before closing it)?

2.)  I have Edit boxes that are integer values.  When the program starts these edit boxes are initalized to 0.  I do not want them to be initalized to anything.  I just want them to be blank upon the programing running.  How can I do this..
0
Comment
Question by:larockd
4 Comments
 
LVL 3

Expert Comment

by:q2guo
ID: 1181221
1.  You can closehandle in the destructor of the class.  But why
can't you open file, do you stuff and close file right after you are done.

2.  You leave the Edit box blank, you will have to initalize it
to '\0'

0
 

Author Comment

by:larockd
ID: 1181222
1.)  The file is opened in a function loadfile, then the user makes changes, and then can hit the PATCH or CANCEL button.  The PATCH button to write the changes to the File or the CANCEL to not write the changes.  Right now I am closing the handle in the patch button, but if the user hits the cancel button the handle is never closed.  I figured to cover this situation I would want to close the handle in the classes destructor?

2.)The Edit box holds an integer value, How can you initalize it to "/0" when it is an integer value?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1181223
Although it is not a good practice, you do not need to close the file at all.  The operating system will close the file when you application terminates.

However, I would do one of two things:

(1) Close the file in a part of the program that is always executed (regardless of what button is hit), such as the end of main() or in a destructor for the dialog or other object.

(2) At the start of the program open the file, read it and close it.  Then if the user hits PATCH, open the file, write it, and close it.  (This is not a the best solution since it would allow multiple programs to edit the file at once.)


0
 
LVL 2

Accepted Solution

by:
AlFa earned 20 total points
ID: 1181224
How an edit box knows what is supposed to be in it?
You can initialize your dialog box with what you want! you just have to be careful!
so if i understand you want to have a dialog box whith retrieve values and never init them! so just do it that way in the DoDataExchange use the m_bSaveAndValidate member of the cdataexchange.

What about your file?
I think it's a good idea to close it in the destructor. If you do not like that try in  WM_DESTROY message handler.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Implementing a ResolveEventHandler in C++ 13 133
how to understand recursion 12 226
how to convert c++ code to Android App 3 95
How to convert MFC APP to Win32 APP. 19 79
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question