Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include "resource.h"
- #include <tchar.h>
- #include <vector>
- #include <string>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- MSG msg ;
- HWND hwnd;
- WNDCLASS wc;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.lpszClassName = TEXT( "Window" );
- wc.hInstance = hInstance ;
- wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
- wc.lpfnWndProc = WndProc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
- RegisterClass(&wc);
- hwnd = CreateWindow( wc.lpszClassName, TEXT("File Manager"),
- WS_SYSMENU | WS_VISIBLE,
- 100, 100, 640, 250, NULL, NULL, hInstance, NULL);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while( GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int) msg.wParam;
- }
- std::vector< std::basic_string< TCHAR > > fVec;
- LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
- {
- static HWND listbox = 0;
- static HWND button = 0;
- static HWND file_name = 0;
- static HWND path = 0;
- static HWND fformat = 0;
- static HWND aadd = 0;
- static HWND applets = 0;
- static HWND del = 0;
- switch(msg)
- {
- case WM_DESTROY:
- {
- PostQuitMessage(0);
- return 0;
- }
- case WM_CREATE:
- {
- listbox = CreateWindow(TEXT("listbox") , NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY | WS_VSCROLL,
- 10, 10, 320, 180, hwnd,(HMENU) 1, NULL, NULL);
- button = CreateWindow(TEXT("button") , TEXT("Создать"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 420, 160, 208, 25, hwnd,(HMENU) 2, NULL, NULL);
- file_name = CreateWindow(TEXT("edit") , TEXT("file.txt"), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOVSCROLL,
- 335, 90, 293, 25, hwnd,(HMENU) 3, NULL, NULL);
- path = CreateWindow(TEXT("edit") , TEXT("default"), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_WANTRETURN | ES_MULTILINE,
- 335, 10, 293, 75, hwnd,(HMENU) 4, NULL, NULL);
- fformat = CreateWindow(TEXT("button") , TEXT("Формат"), WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
- 335, 160, 80, 25, hwnd,(HMENU) 5, NULL, NULL);
- aadd = CreateWindow(TEXT("button") , TEXT("Add"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 335, 120, 40, 25, hwnd,(HMENU) 6, NULL, NULL);
- del = CreateWindow(TEXT("button") , TEXT("Clr"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 375, 120, 40, 25, hwnd,(HMENU) 7, NULL, NULL);
- applets = CreateWindow(TEXT("edit") , TEXT("апплет"), WS_CHILD | WS_VISIBLE | WS_BORDER,
- 420, 120, 208, 25, hwnd,(HMENU) 8, NULL, NULL);
- break;
- }
- case WM_COMMAND:
- {
- switch(LOWORD(wParam)){
- case ID_FILE_INFO:
- {
- MessageBox(0, L"Programm by Push", L"Info", 0);
- break;
- }
- case LBN_SELCHANGE:
- {
- if(HIWORD(wParam) == 1){
- TCHAR* buff[2] = {(TCHAR*)calloc(MAX_PATH, sizeof(TCHAR)), (TCHAR*)calloc(MAX_PATH, sizeof(TCHAR))};
- GetWindowText(path, buff[0], MAX_PATH);
- if(!_tccmp(buff[0], L"default"))
- GetCurrentDirectory(MAX_PATH, buff[0]);
- SendMessage(listbox, LB_GETTEXT, SendMessage(listbox, LB_GETCURSEL, NULL, NULL), (LPARAM)buff[1]);
- if(MessageBox(hwnd, L"Вы хотите запустить этот файл?", L"Question", MB_OKCANCEL) == IDOK)
- ShellExecute(hwnd, L"open", buff[1], NULL, buff[0], SW_MAXIMIZE);
- free(buff[0]);
- free(buff[1]);
- }
- break;
- }
- case IDM_SEARCH:
- {
- TCHAR buff[2048];
- WIN32_FIND_DATA fData = {0};
- GetWindowText(path, buff, sizeof(buff));
- if(!_tccmp(buff, L"default"))
- GetCurrentDirectory(sizeof(buff), buff);
- wcscat(buff, L"\\*");
- HANDLE hFile = FindFirstFile(buff, &fData);
- if(hFile != INVALID_HANDLE_VALUE)
- do {
- if(_tccmp(fData.cFileName, L".") && _tccmp(fData.cFileName, L"..")){
- BOOL isInvalid = FALSE;
- _tcscpy(buff, fData.cFileName);
- if(!IsDlgButtonChecked(hwnd, 5))
- _ftcstok(buff, L".");
- if(!fVec.empty())
- for(std::vector< std::basic_string< TCHAR > >::iterator i = fVec.begin(); i < fVec.end(); i++)
- if(!_tcsstr(buff, i->c_str())) isInvalid = TRUE;
- if(isInvalid) continue;
- SendMessage(listbox, LB_ADDSTRING, NULL, (LPARAM)buff);
- }
- } while (FindNextFile(hFile, &fData));
- FindClose(hFile);
- break;
- }
- case IDM_CLEAR_LIST:
- {
- SendMessage(listbox, LB_RESETCONTENT, 0, 0);
- break;
- }
- case 5:
- {
- CheckDlgButton(hwnd, 5, IsDlgButtonChecked(hwnd, 5) ? BST_UNCHECKED : BST_CHECKED);
- }
- }
- if(HIWORD(wParam) == BN_CLICKED)
- {
- switch(LOWORD(wParam))
- {
- case 2:
- {
- TCHAR* file = (TCHAR*)calloc(MAX_PATH, sizeof(TCHAR)), *Tptr;
- DWORD dd;
- std::vector< std::basic_string< TCHAR > > fVec;
- GetWindowText(file_name, file, MAX_PATH);
- Tptr = _ftcstok(file, L",");
- while(Tptr != NULL)
- {
- fVec.push_back(Tptr);
- Tptr = _ftcstok(NULL, L",");
- }
- for(std::vector< std::basic_string< TCHAR > >::iterator i = fVec.begin(); i!= fVec.end();i++)
- {
- HANDLE hFile = CreateFile(i->c_str(), GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
- for(WORD i=0;i < SendMessage(listbox, LB_GETCOUNT, 0, 0); i++)
- {
- SendMessage(listbox, LB_GETTEXT, i, (LPARAM)file);
- _tcscat(file, L"\r\n");
- WriteFile(hFile, file, _tcsclen(file)*sizeof(TCHAR), &dd, 0);
- }
- CloseHandle(hFile);
- }
- free(file);
- break;
- }
- case 6:
- {
- TCHAR buff[1024];
- GetWindowText(applets, buff, sizeof(buff));
- fVec.push_back(buff);
- MessageBox(hwnd, (fVec.end() - 1)->c_str(), L"Апплет добавлен", MB_OK);
- break;
- }
- case 7:
- {
- fVec.clear();
- MessageBox(hwnd, L"Список апплетов пуст.", L"Информация", 0);
- break;
- }
- }
- }
- break;
- }
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment