I read your code again....
I think you should break your code down into smaller blocks (that do one thing well and can be reused). It would help you see the flow of your code (as it is repeating operations and failing to do other ones) and avoid what appears to be some cut/paste errors.
Some issues I see...
You can not have 4 edits with the same ID (they need to be different if on the same dlg).
Originally Posted by
MSDN CreateWindow() hmenu param
For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.
This is what your code does...
Code:
//open pfile2 as C:\\reminder\\data\\backup1.xls
//if pfile2 failed to open
//open/create pfile as C:\\reminder\\data\\backup1.xls
//pfile2 == null
//open pfile as database1234.xls (on a possibly already used pfile)
//if database1234.xls failed to open
//if C:\\reminder\\data\\backup1.xls failed to open
//open pFile as C:reminder\\data\\backup1.xls (which may fail again leaving pfile null)
//pfile2 is null
//else pfile is null
//if database1234.xls opened
//close it and open in append mode
//close both files (up to 5 fopens for no reason....)
//open both files in append mode (what if you have read only permission or the file is already open or fails again etc? [will data be lost if this happens?])
//get entered text from edits
//write to file
//close files
//clear edits
This code could fail; getting no text or crash as text len exceeds buffer size.
Code:
len = GetWindowTextLength(hwndEdit) + 1;
//what happens if len is now bigger than 1000 (what text can hold) or zero (no text entered or error)?
//get the text from edit(1)
GetWindowText(hwndEdit, text, len);//the 3rd parameter should be the size of the char array (ie 1000)
GetWindowText(hwndEdit2, text2, len);//you are using the same len, from edit(1) for all edits, if it is zero....
What you want is...
Code:
Validate
Check user has entered text in all req edits
validate text if required
prompt user for more input if req
Check files can be opened in append mode
warn user and abort if fail
Get input
Write input to file
Clean up
Close files
Clear edits