Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include "resource.h"
- #include <commdlg.h>
- #include <string>
- #include <cstring>
- using namespace std;
- //#define "_CRT_SECURE_NO_WARNINGS"
- INT_PTR CALLBACK DlgProc(HWND hWin, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- //Reply
- int userReply;
- //Open
- static OPENFILENAME ofn;
- static char szFile[MAX_PATH];
- bool success;
- //ListBox
- static HWND hListBox;
- switch (msg)
- {
- case WM_INITDIALOG:
- //Init open
- ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = hWin;
- ofn.lpstrFile = szFile;
- ofn.nMaxFile = sizeof(szFile);
- //Init ListBox
- hListBox = GetDlgItem(hWin, IDC_LIST1);
- return TRUE;
- case WM_CLOSE:
- userReply = MessageBox(hWin, "Are you sure?", "Close", MB_YESNO | MB_ICONQUESTION);
- if (IDYES == userReply)
- {
- EndDialog(hWin, 0);
- }
- return TRUE;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case IDOK:
- EndDialog(hWin, 0);
- return TRUE;
- case IDCANCEL:
- userReply = MessageBox(hWin, "Are you sure?", "Close", MB_YESNO | MB_ICONQUESTION);
- if (IDYES == userReply)
- {
- EndDialog(hWin, 0);
- }
- return TRUE;
- case IDC_BUTTON1:
- strcpy_s(szFile, "");
- success = GetOpenFileName(&ofn);
- if (success)
- {
- SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)ofn.lpstrFile);
- char *next = NULL;
- char * pch = strtok_s(ofn.lpstrFile, " \\,.-?!:",&next);
- while (pch != NULL) // пока есть лексемы
- {
- SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)pch);
- pch = strtok_s(NULL, " \\,.-?!:", &next);
- }
- }
- return TRUE;
- default:
- return FALSE;
- }
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
- {
- DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment