YauhenMardan

UP_1.1

Jun 4th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <windows.h>
  2. #include "resource.h"
  3. #include <commdlg.h>
  4. #include <string>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. //#define "_CRT_SECURE_NO_WARNINGS"
  9. INT_PTR CALLBACK DlgProc(HWND hWin, UINT msg, WPARAM wParam, LPARAM lParam)
  10. {
  11. //Reply
  12. int userReply;
  13. //Open
  14. static OPENFILENAME ofn;
  15. static char szFile[MAX_PATH];
  16. bool success;
  17. //ListBox
  18. static HWND hListBox;
  19.  
  20. switch (msg)
  21. {
  22. case WM_INITDIALOG:
  23. //Init open
  24. ofn.lStructSize = sizeof(OPENFILENAME);
  25. ofn.hwndOwner = hWin;
  26. ofn.lpstrFile = szFile;
  27. ofn.nMaxFile = sizeof(szFile);
  28. //Init ListBox
  29. hListBox = GetDlgItem(hWin, IDC_LIST1);
  30. return TRUE;
  31. case WM_CLOSE:
  32. userReply = MessageBox(hWin, "Are you sure?", "Close", MB_YESNO | MB_ICONQUESTION);
  33. if (IDYES == userReply)
  34. {
  35. EndDialog(hWin, 0);
  36. }
  37. return TRUE;
  38. case WM_COMMAND:
  39. switch (LOWORD(wParam))
  40. {
  41. case IDOK:
  42. EndDialog(hWin, 0);
  43. return TRUE;
  44. case IDCANCEL:
  45. userReply = MessageBox(hWin, "Are you sure?", "Close", MB_YESNO | MB_ICONQUESTION);
  46. if (IDYES == userReply)
  47. {
  48. EndDialog(hWin, 0);
  49. }
  50. return TRUE;
  51. case IDC_BUTTON1:
  52. strcpy_s(szFile, "");
  53. success = GetOpenFileName(&ofn);
  54. if (success)
  55. {
  56. SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)ofn.lpstrFile);
  57. char *next = NULL;
  58. char * pch = strtok_s(ofn.lpstrFile, " \\,.-?!:",&next);
  59. while (pch != NULL) // пока есть лексемы
  60. {
  61. SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)pch);
  62. pch = strtok_s(NULL, " \\,.-?!:", &next);
  63. }
  64. }
  65. return TRUE;
  66. default:
  67. return FALSE;
  68. }
  69. break;
  70. default:
  71. return FALSE;
  72. }
  73. return TRUE;
  74. }
  75.  
  76. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
  77. {
  78. DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment