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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
switch(LOWORD(wParam))
{
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);
HWND List = GetDlgItem(hWnd, IDC_LISTBOX1);
do
{
char name[MAX_PATH];
nameFile.getline(name, MAX_PATH);
SendMessage(List, LB_ADDSTRING, 0, (LPARAM)name);
}
while(!nameFile.eof());
nameFile.close();
}
} break;
case IDC_BUTTON2: {
string txt;
ofstream myFile;
SendMessage(ListBox1, LB_GETCOUNT, NULL, nCount);
myFile.open( ".\abc.txt", ifstream::in|ios::out);
if(myFile.good()) {
c = char(nCount+'0');
for(int i = 0; i< c ; i++) {
MessageBox(hWnd,NULL,(LPCSTR)nCount,MB_OK);
//myFile.write((char*)c,2);
}
myFile.close();
}
} break;
} break;
|