Hello!
I am coding Win32 application.
It is necessary to fill the dynamic list from file by clicking on the "ID_OPENDB" button. The project is compiled and run.
But an exception "C000001E" is generated in function
MainDlgProc at the line “
return FALSE” ( after correct executing of OpenDialog, creating and filling list and filling ListView). I even don’t an idea why.
And what the most interesting, if to comment the line “Refresh(hList, list);” or on the contrary, to comment all except this line, then exception is absent. How to correct this? Code is below (I have left just the necessary).
P.S. The whole project in the attachment.
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow){
INITCOMMONCONTROLSEX icc;
WNDCLASSEX wcx;
ghInstance = hInstance;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
wcx.cbSize = sizeof(wcx);
if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
return 0;
wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wcx.lpszClassName = _T("deleteThClass");
if (!RegisterClassEx(&wcx))
return 0;
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}
//=======================================================
static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){
OPENFILENAME ofn;
static char szFile[256];
switch (uMsg){
case WM_INITDIALOG:
ListCreate(&list);
InitElement(&tmp, "грачи", "Васенцов", "пейзаж", "1788", 11, 50000);
AppendElement(list, tmp, TRUE);
InitElement(&tmp, "троица", "Рублев", "икона", "1800", 11, 90000);
AppendElement(list, tmp, TRUE);
hList= CreateWindow( WC_LISTVIEW, "MyList", LVS_REPORT|WS_CHILD|LVS_EDITLABELS|WS_VISIBLE|WS_BORDER|LVS_EX_GRIDLINES,
107, 6, 900, 500 , hwndDlg, (HMENU)ID_LISTBOX, NULL, NULL );
ListView_SetExtendedListViewStyleEx(hList, 0, LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
return TRUE;
case WM_SIZE:
return TRUE;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam)){
case ID_OPENDB: //if comment all the lines exept "Refresh(hList, list);" then the exception is absent
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = _T("Файлы БД .xdb\0*.xdb");
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile) / sizeof( szFile[0] );
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
if( GetOpenFileName(&ofn) ){
LoadDB( list, szFile );
}
Refresh(hList, list); //if to comment this line then the exception is absent too
break;
}
break;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
}
return FALSE; // HERE Exception c000001e
}
the Refresh() and LoadDB functions code:
int Refresh( HWND hList, TList *list ) {
ListView_DeleteAllItems( hList );
InitListViewColumns( hList );
InitListViewItems( hList, list ) ;
return 0;
}
int InitListViewColumns(HWND hList){
LVCOLUMN column;
for( int i= 0; i < 6; i++ ){
ListView_DeleteColumn(hList,0);
}
column.mask = LVCF_WIDTH | LVCF_TEXT;
column.fmt = LVCFMT_CENTER;
column.cx = 150;
column.pszText = "Картина";
ListView_InsertColumn(hList, 0, &column);
column.pszText = "Художник";
ListView_InsertColumn(hList, 1, &column);
column.pszText = "Жанр";
ListView_InsertColumn(hList, 2, &column);
column.pszText = "Дата написания";
ListView_InsertColumn(hList, 3, &column);
column.pszText = "Номер зала";
ListView_InsertColumn(hList, 4, &column);
column.pszText = "Цена, $";
ListView_InsertColumn(hList, 5, &column);
return 0;
}
//============================================================================================
int InitListViewItems(HWND hList, TList *list){
LVITEM item;
int i= 0;
char *tmp;
memset( &item, 0, sizeof( LV_ITEM ) );
item.mask = LVIF_TEXT;
MoveHead( list );
if( IsListEmpty(list) == 0 ){
do{
item.iItem = i;
ListView_InsertItem(hList, &item);
item.pszText= list->curr->name;
ListView_SetItemText( hList, i, 0, item.pszText );
item.pszText= list->curr->artist;
ListView_SetItemText( hList, i, 1, item.pszText );
item.pszText= list->curr->genre;
ListView_SetItemText( hList, i, 2, item.pszText );
item.pszText= list->curr->date;
ListView_SetItemText( hList, i, 3, item.pszText );
_itoa( list->curr->hall, tmp, 10);
item.pszText= tmp;
ListView_SetItemText( hList, i, 4, item.pszText );
_itoa( list->curr->price, tmp, 10);
item.pszText= tmp;
ListView_SetItemText( hList, i, 5, item.pszText );
i++;
}while( MoveForward(list) != 1 );
}
return 0;
}
//============================================================================================
int LoadDB(TList *list, char *path){
FILE *db= fopen(path, "rb");
if( db == NULL ){
MessageBox(0, "File is absent or corrupted", "Abstract error", MB_OK);
}
else{
DestroyList(list);
ListCreate(&list);
void *tmp;
while( !feof(db) ){
tmp= (TElement *)malloc(sizeof(TElement));
fread( tmp, sizeof(TElement), 1, db);
AppendElement(list, (TElement *)tmp, TRUE);
}
}
fclose(db);
return 0;
}