Adding File names to list box.
-
Hello All, I have a List Box { IDC_FILE_LIST } and add button { IDC_FILE } When we click on the add button it should popup a window where we can browse some file name with path and it should be added to list box. For that I have used the below code but I am getting errors can anyone please tell me what is wrong in the below code. [code] BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_FILE: OpenFile(hwnd); break; --- ---- Function OpenFile : - void OpenFile(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_FILE_LIST); SendDlgItemMessage(hwnd, IDC_FILE_LIST, LB_ADDSTRING, 0, (LPARAM)ofn); } } [\code] Errors : - (134) : error C2065: 'OPENFILENAME' : undeclared identifier (134) : error C2146: syntax error : missing ';' before identifier 'ofn' (134) : error C2065: 'ofn' : undeclared identifier (139) : error C2228: left of '.lStructSize' must have class/struct/union type (140) : error C2228: left of '.hwndOwner' must have class/struct/union type (141) : error C2228: left of '.lpstrFilter' must have class/struct/union type (142) : error C2228: left of '.lpstrFile' must have class/struct/union type (143) : error C2228: left of '.nMaxFile' must have class/struct/union type (144) : error C2228: left of '.Flags' must have class/struct/union type (144) : error C2065: 'OFN_EXPLORER' : undeclared identifier (144) : error C2065: 'OFN_FILEMUSTEXIST' : undeclared identifier (144) : error C2065: 'OFN_HIDEREADONLY' : undeclared identifier (145) : error C2228: left of '.lpstrDefExt' must have class/struct/union type (147) : error C2065: 'GetOpenFileName' : undeclared identifier --------- Thanking you, Suresh HC
-
Hello All, I have a List Box { IDC_FILE_LIST } and add button { IDC_FILE } When we click on the add button it should popup a window where we can browse some file name with path and it should be added to list box. For that I have used the below code but I am getting errors can anyone please tell me what is wrong in the below code. [code] BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_FILE: OpenFile(hwnd); break; --- ---- Function OpenFile : - void OpenFile(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_FILE_LIST); SendDlgItemMessage(hwnd, IDC_FILE_LIST, LB_ADDSTRING, 0, (LPARAM)ofn); } } [\code] Errors : - (134) : error C2065: 'OPENFILENAME' : undeclared identifier (134) : error C2146: syntax error : missing ';' before identifier 'ofn' (134) : error C2065: 'ofn' : undeclared identifier (139) : error C2228: left of '.lStructSize' must have class/struct/union type (140) : error C2228: left of '.hwndOwner' must have class/struct/union type (141) : error C2228: left of '.lpstrFilter' must have class/struct/union type (142) : error C2228: left of '.lpstrFile' must have class/struct/union type (143) : error C2228: left of '.nMaxFile' must have class/struct/union type (144) : error C2228: left of '.Flags' must have class/struct/union type (144) : error C2065: 'OFN_EXPLORER' : undeclared identifier (144) : error C2065: 'OFN_FILEMUSTEXIST' : undeclared identifier (144) : error C2065: 'OFN_HIDEREADONLY' : undeclared identifier (145) : error C2228: left of '.lpstrDefExt' must have class/struct/union type (147) : error C2065: 'GetOpenFileName' : undeclared identifier --------- Thanking you, Suresh HC
-
Hello All, I have a List Box { IDC_FILE_LIST } and add button { IDC_FILE } When we click on the add button it should popup a window where we can browse some file name with path and it should be added to list box. For that I have used the below code but I am getting errors can anyone please tell me what is wrong in the below code. [code] BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_FILE: OpenFile(hwnd); break; --- ---- Function OpenFile : - void OpenFile(HWND hwnd) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrDefExt = "txt"; if(GetOpenFileName(&ofn)) { HWND hEdit = GetDlgItem(hwnd, IDC_FILE_LIST); SendDlgItemMessage(hwnd, IDC_FILE_LIST, LB_ADDSTRING, 0, (LPARAM)ofn); } } [\code] Errors : - (134) : error C2065: 'OPENFILENAME' : undeclared identifier (134) : error C2146: syntax error : missing ';' before identifier 'ofn' (134) : error C2065: 'ofn' : undeclared identifier (139) : error C2228: left of '.lStructSize' must have class/struct/union type (140) : error C2228: left of '.hwndOwner' must have class/struct/union type (141) : error C2228: left of '.lpstrFilter' must have class/struct/union type (142) : error C2228: left of '.lpstrFile' must have class/struct/union type (143) : error C2228: left of '.nMaxFile' must have class/struct/union type (144) : error C2228: left of '.Flags' must have class/struct/union type (144) : error C2065: 'OFN_EXPLORER' : undeclared identifier (144) : error C2065: 'OFN_FILEMUSTEXIST' : undeclared identifier (144) : error C2065: 'OFN_HIDEREADONLY' : undeclared identifier (145) : error C2228: left of '.lpstrDefExt' must have class/struct/union type (147) : error C2065: 'GetOpenFileName' : undeclared identifier --------- Thanking you, Suresh HC
include
Commdlg.h
.Prasad Notifier using ATL | Operator new[],delete[][^]
-
include
Commdlg.h
.Prasad Notifier using ATL | Operator new[],delete[][^]