[Dev-C++] Dialog Box Data Retrieval Problem
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Bill H. <clu...@ya...> - 2005-04-09 11:27:18
|
I'm having trouble getting the data out of my Dialog Box.
I'm a Newbie, but have read all the Tutorials, HowTos and Manuals I can
find but have only become more confused.
Without exception the Tutorials indicate how to include a Cancel and OK
button, and perhaps a few other Controls and simply state that adding
other controls and retrieving the Data is easy and various texts seem to
outline different methods.
I don't have any trouble with OK and Cancel etc., but when I come to the
Data part, I have no luck at all. It may be that I have missed
something. In fact I probably have, but I have spent several days trying
to solve the problem on my own and would now welcome some assistance..
I shall eventually use SQLite as a database, but am currently just using
a binary file until I can get the Data retrieval problem sorted out.
The application I am working on is a simple General Ledger Accounting
programme.
The data is read into the Dialog Box displays perfectly. I just cannot
get the modified data out of the Dialog Box.
Here (hopefully) is enough snippets from the programme for someone who
knows what they are doing to determine what my problem is:
CORP.h an include file defining a structure to hold the individual Data
Items for the main Company file.
The types will not all be char. but currently I am just using the one
data type for simplicity.
struct CORP {
char corp_name[41];
char corp_address1[41];
char corp_address2[41];
char corp_city[41];
char corp_state[31];
char corp_zip[21];
char corp_capitalacct[7];
char corp_reacct[7];
char corp_yrend[5];
char corp_currfm[3];
char corp_init[4];
char corp_accntnts[41];
char corp_id[9];
char corp_dir[41];
};
DLGCORPEDIT.h
#define IDD_CORP_EDIT_DLG 1100
#define IDC_CORPEDIT_NAME 1101
#define IDC_CORPEDIT_ADDRESS1 1102
#define IDC_CORPEDIT_ADDRESS2 1103
#define IDC_CORPEDIT_CITY 1104
#define IDC_CORPEDIT_STATE 1105
#define IDC_CORPEDIT_ZIP 1106
#define IDC_CORPEDIT_CAPITALACCT 1107
#define IDC_CORPEDIT_RE 1108
#define IDC_CORPEDIT_YREND 1109
#define IDC_CORPEDIT_FM 1110
#define IDC_CORPEDIT_INIT 1111
#define IDC_CORPEDIT_ACCNTNTS 1112
#define IDC_CORPEDIT_ID 1113
#define IDC_CORPEDIT_DIR 1114
#define IDC_CORPEDIT_DAT_NAME 1115
#define IDC_CORPEDIT_DAT_ADDRESS1 1116
#define IDC_CORPEDIT_DAT_ADDRESS2 1117
#define IDC_CORPEDIT_DAT_CITY 1118
#define IDC_CORPEDIT_DAT_STATE 1119
#define IDC_CORPEDIT_DAT_ZIP 1120
#define IDC_CORPEDIT_DAT_REACCT 1121
#define IDC_CORPEDIT_DAT_CAPITALACCT 1122
#define IDC_CORPEDIT_DAT_YREND 1123
#define IDC_CORPEDIT_DAT_CURRFM 1124
#define IDC_CORPEDIT_DAT_INIT 1125
#define IDC_CORPEDIT_DAT_ACCNTNTS 1126
#define IDC_CORPEDIT_DAT_ID 1127
#define IDC_CORPEDIT_DAT_DIR 1128
RSRC.rc (Fragment for the EditCorp Dialog Box)
IDD_CORP_EDIT_DLG DIALOGEX 6,6,428,200
CAPTION "Edit Company"
FONT 8,"MS Sans Serif"
STYLE 0x10CF0000
EXSTYLE 0x00000000
BEGIN
CONTROL "Name",IDC_CORPEDIT_NAME,"Static",0x50000200,18,7,24,11,0x00000000
CONTROL
"Address1",IDC_CORPEDIT_ADDRESS1,"Static",0x50000200,18,25,36,11,0x00000000
CONTROL
"Address2",IDC_CORPEDIT_ADDRESS2,"Static",0x50000200,18,44,34,11,0x00000000
CONTROL "City",IDC_CORPEDIT_CITY,"Static",0x50000200,18,62,18,11,0x00000000
CONTROL
"State",IDC_CORPEDIT_STATE,"Static",0x50000200,18,81,22,11,0x00000000
CONTROL "Postal
Code",IDC_CORPEDIT_ZIP,"Static",0x50000200,250,81,42,11,0x00000000
CONTROL "Capital
Account",IDC_CORPEDIT_CAPITALACCT,"Static",0x50000200,18,99,54,11,0x00000000
CONTROL "Retained Earnings
Account",IDC_CORPEDIT_RE,"Static",0x50000200,202,99,94,11,0x00000000
CONTROL "Year End
Month",IDC_CORPEDIT_YREND,"Static",0x50000200,18,118,58,11,0x00000000
CONTROL "Current Fiscal
Month",IDC_CORPEDIT_FM,"Static",0x50000200,154,118,70,11,0x00000000
CONTROL "GL
Initialized",IDC_CORPEDIT_INIT,"Static",0x50000200,310,118,44,11,0x00000000
CONTROL
"Accountants",IDC_CORPEDIT_ACCNTNTS,"Static",0x50000200,18,136,46,11,0x00000000
CONTROL "Short
Identifier",IDC_CORPEDIT_ID,"Static",0x50000200,16,153,46,11,0x00000000
CONTROL "Data
Directory",IDC_CORPEDIT_DIR,"Static",0x50000200,182,153,50,11,0x00000000
CONTROL "",IDC_CORPEDIT_DAT_NAME,"Edit",0x50010000,86,7,320,11,0x00000200
CONTROL
"",IDC_CORPEDIT_DAT_ADDRESS1,"Edit",0x50010000,86,25,320,11,0x00000200
CONTROL
"",IDC_CORPEDIT_DAT_ADDRESS2,"Edit",0x50010000,86,44,320,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_CITY,"Edit",0x50010000,86,62,320,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_STATE,"Edit",0x50010000,86,81,148,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_ZIP,"Edit",0x50010000,310,81,96,11,0x00000200
CONTROL
"",IDC_CORPEDIT_DAT_CAPITALACCT,"Edit",0x50010000,86,99,98,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_REACCT,"Edit",0x50010000,312,99,96,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_YREND,"Edit",0x50010000,88,118,50,11,0x00000200
CONTROL
"",IDC_CORPEDIT_DAT_CURRFM,"Edit",0x50010000,238,118,54,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_INIT,"Edit",0x58010000,368,118,40,11,0x00000200
CONTROL
"",IDC_CORPEDIT_DAT_ACCNTNTS,"Edit",0x50010000,88,136,320,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_ID,"Edit",0x58010000,88,153,82,11,0x00000200
CONTROL "",IDC_CORPEDIT_DAT_DIR,"Edit",0x58010000,248,155,160,11,0x00000200
CONTROL "OK",IDOK,"Button",0x50010000,276,180,58,13,0x00000000
CONTROL "Cancel",IDCANCEL,"Button",0x50010000,348,180,60,13,0x00000000
END
MAIN.CPP - Dialog CallBack fragment
BOOL CALLBACK caglDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM
lParam)
{
switch(Message)
{
case WM_INITDIALOG:
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_NAME, "My New Company");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ADDRESS1, "My Court");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ADDRESS2, "Suite 803");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_CITY, "Antibes");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_STATE, "Alpes Maritimes");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ZIP, "06600");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_REACCT, "803999");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_CAPITALACCT, "803000");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_YREND, "07");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_CURRFM, "0504");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_INIT, "No");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ACCNTNTS, "Audit & Cie");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ID, "MYCO_001");
SetDlgItemText(hwnd, IDC_CORPEDIT_DAT_DIR, "data");
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
MAIN.CPP - Message Handler-Dialog CallBack fragment
/* This function is called by the Windowsfunction DispatchMessage( ) */
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_COMMAND:
switch( wParam )
{
case IDM_FILENEW:
case IDM_FILEOPEN:
case IDM_FILESAVE:
case IDM_FILESAVEAS:
case IDM_FILEPRINT:
case IDM_FILEPAGESETUP:
case IDM_FILEPRINTSETUP:
case IDM_EDITUNDO:
case IDM_EDITCUT:
case IDM_EDITCOPY:
case IDM_EDITPASTE:
case IDM_EDITDELETE:
MessageBox( hwnd, (LPSTR) "Function Not Yet Implemented.",
(LPSTR) szClassName,
MB_ICONINFORMATION | MB_OK );
return 0;
case IDM_HELPCONTENTS:
WinHelp( hwnd, (LPSTR) "Gl-Help.HLP",
HELP_CONTENTS, 0L );
return 0;
case IDM_HELPSEARCH:
WinHelp( hwnd, (LPSTR) "Gl-help.HLP",
HELP_PARTIALKEY, 0L );
return 0;
case IDM_HELPHELP:
WinHelp( hwnd, (LPSTR) "Gl-Help.HLP",
HELP_HELPONHELP, 0L );
return 0;
case IDM_FILEEXIT:
SendMessage( hwnd, WM_CLOSE, 0, 0L );
return 0;
case IDM_CORP_SELECT:
iReturnValue = DialogBox(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_CORP_SEL_DLG), hwnd, caglDlgProc);
// report success or failure
// pull messageboxes when code finalized
// on IDOK and IDCANCEL
if(iReturnValue == IDOK){
MessageBox(hwnd, "Dialog exited with IDOK.",
"Notice",
MB_OK | MB_ICONINFORMATION);
} else if(iReturnValue == IDCANCEL){
MessageBox(hwnd, "Dialog exited with
IDCANCEL.", "Notice",
MB_OK | MB_ICONINFORMATION);
} else if(iReturnValue == -1){
MessageBox(hwnd, "Dialog failed!", "Error",
MB_OK | MB_ICONINFORMATION);
}
// break;
// Other menu commands...
MessageBox( hwnd, (LPSTR) "Function Not Yet Implemented.",
(LPSTR) szClassName,
MB_ICONINFORMATION | MB_OK );
return 0;
case IDM_CORP_EDIT:
iReturnValue = DialogBox(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_CORP_EDIT_DLG), hwnd, caglDlgProc);
// report success or failure
// pull messageboxes when code finalized
// on IDOK and IDCANCEL
if(iReturnValue == IDOK){
typedef struct CORP company;
FILE* fh_ThisCorp;
company NewCorp;
system( "mkdir c:\\data" );
strcpy(szDataPath, "\\data\\newcorp.dat");
fh_ThisCorp = fopen(szDataPath, "wb");
strcpy(NewCorp.corp_name, "1123MY_NEW_COMPANY");
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_NAME, NewCorp.corp_name, 40);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ADDRESS1, NewCorp.corp_address1, 40);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ADDRESS2, NewCorp.corp_address2, 40);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_CITY, NewCorp.corp_city, 40);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_STATE, NewCorp.corp_state, 30);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ZIP, NewCorp.corp_zip, 20);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_REACCT, NewCorp.corp_reacct, 7);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_CAPITALACCT,
NewCorp.corp_capitalacct, 7);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_YREND, NewCorp.corp_yrend, 5);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_CURRFM, NewCorp.corp_currfm, 3);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_INIT, NewCorp.corp_init, 3);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ACCNTNTS, NewCorp.corp_accntnts, 40);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_ID, NewCorp.corp_id, 8);
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_DIR, NewCorp.corp_dir, 40);
fwrite(&NewCorp, sizeof(company), 1, fh_ThisCorp);
fclose(fh_ThisCorp);
MessageBox(hwnd, "Dialog exited with IDOK.",
"Notice",
MB_OK | MB_ICONINFORMATION);
} else if(iReturnValue == IDCANCEL){
MessageBox(hwnd, "Dialog exited with
IDCANCEL.", "Notice",
MB_OK | MB_ICONINFORMATION);
} else if(iReturnValue == -1){
MessageBox(hwnd, "Dialog failed!", "Error",
MB_OK | MB_ICONINFORMATION);
}
// break;
// Other menu commands...
MessageBox( hwnd, (LPSTR) "Rest of Function Not Yet
Implemented.",
(LPSTR) szClassName,
MB_ICONINFORMATION | MB_OK );
return 0;
case IDM_CORP_ADD:
iReturnValue = DialogBox(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_CORP_EDIT_DLG), hwnd, caglDlgProc);
// report success or failure
// pull messageboxes when code finalized
// on IDOK and IDCANCEL
if(iReturnValue == IDOK){
MessageBox(hwnd, "Dialog exited with IDOK.",
"Notice",
MB_OK | MB_ICONINFORMATION);
} else if(iReturnValue == IDCANCEL){
MessageBox(hwnd, "Dialog exited with
IDCANCEL.", "Notice",
MB_OK | MB_ICONINFORMATION);
} else if(iReturnValue == -1){
MessageBox(hwnd, "Dialog failed!", "Error",
MB_OK | MB_ICONINFORMATION);
}
// break;
// Other menu commands...
MessageBox( hwnd, (LPSTR) "Function Not Yet Implemented.",
(LPSTR) szClassName,
MB_ICONINFORMATION | MB_OK );
return 0;
case IDM_CORP_DELETE:
MessageBox( hwnd, (LPSTR) "Function Not Yet Implemented.",
(LPSTR) szClassName,
MB_ICONINFORMATION | MB_OK );
return 0;
case IDM_CORP_RESTORE:
MessageBox( hwnd, (LPSTR) "Function Not Yet Implemented.",
(LPSTR) szClassName,
MB_ICONINFORMATION | MB_OK );
return 0;
case IDM_HELPABOUT:
MessageBox (NULL, "By Bill Henderson", "Version
0.01", 1);
return 0;
}
break;
case WM_CLOSE:
DestroyWindow( hwnd );
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
break;
default: /* for messages that we don't deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
Despite attempts to use:
GetDlgItemText(hwnd, IDC_CORPEDIT_DAT_NAME, NewCorp.corp_name, 40);
all that I have in my "newcorp.dat" file after running the programme is
what was placed there as a test or contol value by the line preceding my
attempt to retrieve the data edited in the Dialog Box.
strcpy(NewCorp.corp_name, "1123MY_NEW_COMPANY");
Generally, apart from the Data Retrieval problem, everything seems to
work perfectly.
If anyone can help me out, please acept my thanks in advance.
Bill Henderson
|