Closing A File Handle And Initializing A Diaglog Box Value

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..
larockdAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

q2guoCommented:
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
larockdAuthor Commented:
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
nietodCommented:
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
AlFaCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.