[SOLVED]Win32 C++ Open File and list into listbox Question

Why is this not working? What Am I doing wrong? I am new to Win32 GUI

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
case IDC_BUTTON1:
				{
					OPENFILENAME ofn;
					char szFileName[MAX_PATH] = "";

					ZeroMemory(&ofn, sizeof(ofn));

					ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
					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))
					{
						ifstream nameFile(szFileName);
						do
						{
							char name[MAX_PATH];
							nameFile.getline(name, MAX_PATH);
							SendMessage(ListBox1, LB_ADDSTRING, 0, (LPARAM)name);
						}
							 
						while(!nameFile.eof());
							nameFile.close();
							//SendMessage(hEdit,LB_ADDSTRING,NULL,(LPARAM) "Test");// Do something usefull with the filename stored in szFileName 
					}
				}
				break;
Last edited on
Topic archived. No new replies allowed.