Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <dwmapi.h>
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <string>
- #include "resource.h"
- #include <commctrl.h>
- #include <vector>
- #include <algorithm>
- #pragma warning(disable : 4800)
- #pragma comment( lib, "comctl32.lib" )
- #define WM_TRAY (WM_USER + 100)
- int pipeCounter = -1, procInfCounter = -1;
- std::vector<HANDLE>pipeHandles;
- std::vector<PROCESS_INFORMATION>procInf;
- std::vector<std::string>killRing;
- bool showWindowB = false;
- bool showWindowC = false;
- bool showWindowD = false;
- bool showWindowE = false;
- bool startWithWindows = false;
- bool copyStarted = false;
- char wKillRingPath[MAX_PATH];
- char ccommand[4096];
- std::string exePath, exeFullPath, confPath, commandResult, command;
- int counter = 0, killRingPos = -1;
- HWND hWindowa, hWindowb, hWindowc, hWindowd, hWindowe, hButtonA1, hTextA1, hTextA2, hTextA3, hTextB1, hTextB2, hTextB3, hTextC1, hTextC2, hTextC3, hTextB;
- HWND hHotKeyA1, hHotKeyA2, hButtonPasteA, hButtonPasteB, hButtonPasteC, hButtonPasteD;
- HWND hwndEditWA, hwndButtonWA, hwndEditWB, hwndButtonWB, hwndEditWC, hwndButtonWC, hwndEditWD, hwndButtonWD;
- WORD wHotkeyA1, wHotkeyA2;
- UINT iSetResultA1, iSetResultA2;
- HMENU hMenubar, hMenu, hMenuB, hMenuC;
- INITCOMMONCONTROLSEX icex;
- NOTIFYICONDATA iconTray;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK WndProcB(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK WndProcC(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK WndProcD(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK WndProcE(HWND, UINT, WPARAM, LPARAM);
- PROCESS_INFORMATION CreateChildProcess(char szCmdline[], HANDLE hChildStdWr);
- std::string ReadFromPipe(PROCESS_INFORMATION piProcInfo, HANDLE hChildStdRd);
- void trayDrawIcon(HWND hwnd);
- void AddMenus(HWND);
- void resetwKillRing(HWND hwnd);
- void setConfiguration(HWND hwnd, HWND hotKeyHandle[]);
- void saveConfiguration(HWND hwnd);
- void toClipboard(const std::string& s);
- std::string getClipboardText();
- LPWSTR stringToLPWSTR(const std::string& instr);
- std::string lpwstrToString(LPWSTR input);
- std::string doubleBSlash(std::string path);
- std::string silentCmdResult(char* command);
- std::string execPath();
- std::string getEditText(HWND hwndEditW);
- bool fileExists(const char* fileName);
- bool isDir(std::string path);
- void displayExcludeList(HWND hwndEdit, std::string passedString, std::string passedPath);
- void registerWordHotKey(HWND hHotKey, int ID);
- int gCmdShow;
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
- {
- gCmdShow = nCmdShow;
- MSG msg;
- WNDCLASSW wc = { 0 };
- wc.lpszClassName = L"wKillRing";
- wc.hInstance = hInstance;
- wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wc.lpfnWndProc = WndProc;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- RegisterClassW(&wc);
- hWindowa = CreateWindowW(wc.lpszClassName, L"wKillRing", WS_OVERLAPPEDWINDOW, 200, 200, 372, 244, 0, 0, hInstance, 0);//WS_MINIMIZEBOX //WS_OVERLAPPEDWINDOW | WS_VISIBLE
- WNDCLASSW wcB = { 0 };
- wcB.lpszClassName = L"Edit_paste-A";
- wcB.hInstance = hInstance;
- wcB.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wcB.lpfnWndProc = WndProcB;
- wcB.hCursor = LoadCursor(0, IDC_ARROW);
- wcB.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- RegisterClassW(&wcB);
- hWindowb = CreateWindowW(wcB.lpszClassName, L"Edit paste-A", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
- ShowWindow(hWindowb, SW_HIDE);
- WNDCLASSW wcC = { 0 };
- wcC.lpszClassName = L"Edit_paste-B";
- wcC.hInstance = hInstance;
- wcC.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wcC.lpfnWndProc = WndProcC;
- wcC.hCursor = LoadCursor(0, IDC_ARROW);
- wcC.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- RegisterClassW(&wcC);
- hWindowc = CreateWindowW(wcC.lpszClassName, L"Edit paste-B", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
- ShowWindow(hWindowc, SW_HIDE);
- WNDCLASSW wcD = { 0 };
- wcD.lpszClassName = L"Edit_paste-C";
- wcD.hInstance = hInstance;
- wcD.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wcD.lpfnWndProc = WndProcD;
- wcD.hCursor = LoadCursor(0, IDC_ARROW);
- wcD.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- RegisterClassW(&wcD);
- hWindowd = CreateWindowW(wcD.lpszClassName, L"Edit paste-C", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
- ShowWindow(hWindowd, SW_HIDE);
- WNDCLASSW wcE = { 0 };
- wcE.lpszClassName = L"Edit_paste-D";
- wcE.hInstance = hInstance;
- wcE.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
- wcE.lpfnWndProc = WndProcE;
- wcE.hCursor = LoadCursor(0, IDC_ARROW);
- wcE.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- RegisterClassW(&wcE);
- hWindowe = CreateWindowW(wcE.lpszClassName, L"Edit paste-D", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
- ShowWindow(hWindowe, SW_HIDE);
- icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- icex.dwICC = ICC_HOTKEY_CLASS;
- InitCommonControlsEx(&icex);
- RegisterHotKey(NULL, 1, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x55);
- RegisterHotKey(NULL, 2, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x49);
- RegisterHotKey(NULL, 3, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x4F);
- RegisterHotKey(NULL, 4, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x50);
- RegisterHotKey(NULL, HOTKEYGENURL, MOD_CONTROL | MOD_NOREPEAT, 0x20);
- toClipboard("");
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (showWindowB)
- {
- ShowWindow(hWindowb, nCmdShow);
- }
- else if (!showWindowB)
- {
- ShowWindow(hWindowb, SW_HIDE);
- }
- if (showWindowC)
- {
- ShowWindow(hWindowc, nCmdShow);
- }
- else if (!showWindowC)
- {
- ShowWindow(hWindowc, SW_HIDE);
- }
- if (showWindowD)
- {
- ShowWindow(hWindowd, nCmdShow);
- }
- else if (!showWindowD)
- {
- ShowWindow(hWindowd, SW_HIDE);
- }
- if (showWindowE)
- {
- ShowWindow(hWindowe, nCmdShow);
- }
- else if (!showWindowE)
- {
- ShowWindow(hWindowe, SW_HIDE);
- }
- if (msg.message == WM_HOTKEY)
- {
- OutputDebugStringW(L"WM_HOTKEY received\n");
- switch (msg.wParam)
- {
- case HOTKEYPASTEA:
- toClipboard(getEditText(hwndEditWA));
- break;
- case HOTKEYPASTEB:
- toClipboard(getEditText(hwndEditWB));
- break;
- case HOTKEYPASTEC:
- toClipboard(getEditText(hwndEditWC));
- break;
- case HOTKEYPASTED:
- toClipboard(getEditText(hwndEditWD));
- break;
- case HOTKEYRINGLEFT:
- if (killRing.empty())
- {
- MessageBox(hWindowa, "Fill the clipboard first", "wKillRing", MB_ICONWARNING | MB_OK);
- }
- else
- {
- killRingPos--;
- if (killRingPos < 0)
- {
- killRingPos = killRing.size() - 1;
- }
- toClipboard(killRing.at(killRingPos));
- }
- break;
- case HOTKEYRINGRIGHT:
- if (killRing.empty())
- {
- MessageBox(hWindowa, "Fill the clipboard first", "wKillRing", MB_ICONWARNING | MB_OK);
- }
- else
- {
- killRingPos++;
- if (killRingPos > killRing.size() - 1)
- {
- killRingPos = 0;
- }
- toClipboard(killRing.at(killRingPos));
- }
- break;
- case HOTKEYGENURL:
- {
- std::string cmdNumber = getClipboardText();
- std::string url = "https://support.dbs.fr/Ticket/Display.html?id=";
- int intValue = 0;
- std::stringstream conve(cmdNumber);
- conve >> intValue;
- if ((intValue >= 100000) && (intValue <= 199999))
- {
- url.append(cmdNumber);
- ShellExecuteW(NULL, L"open", L"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", stringToLPWSTR(url), NULL, SW_SHOW);
- }
- }
- break;
- default:
- break;
- }
- }
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- trayDrawIcon(hWindowa);
- GetModuleFileName(NULL, wKillRingPath, MAX_PATH);
- exeFullPath = doubleBSlash(wKillRingPath);
- exePath = execPath();
- confPath = getenv("appdata");
- confPath += "\\wKillRing";
- if (isDir(confPath) != true)
- {
- command = "C:\\windows\\system32\\cmd.exe /c mkdir \"";
- command.append(confPath);
- command.append("\"");
- strcpy(ccommand, command.c_str());
- silentCmdResult(ccommand);
- }
- SetTimer(hwnd, ID_TIMERA, 1000, (TIMERPROC)NULL);
- switch (msg)
- {
- case WM_CREATE:
- {
- AddMenus(hwnd);
- hTextA1 = CreateWindowEx(0, WC_STATIC, ("Iterate to the left of the ring :"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 18, 17, 225, 19, hwnd, (HMENU)ID_TEXTA1, GetModuleHandle(NULL), 0);
- hHotKeyA1 = CreateWindowEx(0, HOTKEY_CLASS, (""), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 226, 15, 112, 23, hwnd, (HMENU)ID_HOTKEYA1, GetModuleHandle(NULL), 0);
- hTextA3 = CreateWindowEx(0, WC_STATIC, ("Iterate to the right of the ring :"), WS_VISIBLE | WS_CHILD | WS_GROUP | SS_LEFT, 18, 45, 225, 19, hwnd, (HMENU)ID_TEXTA3, GetModuleHandle(NULL), 0);
- hHotKeyA2 = CreateWindowEx(0, HOTKEY_CLASS, (""), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 226, 44, 112, 23, hwnd, (HMENU)ID_HOTKEYA1, GetModuleHandle(NULL), 0);
- hButtonA1 = CreateWindowEx(0, WC_BUTTON, ("Save changes"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 133, 75, 102, 23, hwnd, (HMENU)ID_BUTTONA1, GetModuleHandle(NULL), 0);
- hButtonPasteA = CreateWindowEx(0, WC_BUTTON, ("Edit paste-A"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 48, 112, 126, 23, hwnd, (HMENU)ID_BUTTONPASTEA, GetModuleHandle(NULL), 0);
- hButtonPasteB = CreateWindowEx(0, WC_BUTTON, ("Edit paste-B"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 180, 112, 126, 23, hwnd, (HMENU)ID_BUTTONPASTEB, GetModuleHandle(NULL), 0);
- hButtonPasteC = CreateWindowEx(0, WC_BUTTON, ("Edit paste-C"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 48, 145, 126, 23, hwnd, (HMENU)ID_BUTTONPASTEC, GetModuleHandle(NULL), 0);
- hButtonPasteD = CreateWindowEx(0, WC_BUTTON, ("Edit paste-D"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 180, 145, 126, 23, hwnd, (HMENU)ID_BUTTONPASTED, GetModuleHandle(NULL), 0);
- HWND hotKeyHandle[] = { hHotKeyA1, hHotKeyA2 };
- setConfiguration(hwnd, hotKeyHandle);
- break;
- }
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTONPASTEA)
- {
- showWindowB = true;
- SetActiveWindow(hWindowb);
- break;
- }
- else if (LOWORD(wParam) == ID_BUTTONPASTEB)
- {
- showWindowC = true;
- SetActiveWindow(hWindowc);
- break;
- }
- else if (LOWORD(wParam) == ID_BUTTONPASTEC)
- {
- showWindowD = true;
- SetActiveWindow(hWindowd);
- break;
- }
- else if (LOWORD(wParam) == ID_BUTTONPASTED)
- {
- showWindowE = true;
- SetActiveWindow(hWindowe);
- break;
- }
- else if (LOWORD(wParam) == ID_MENUB)
- {
- Shell_NotifyIcon(NIM_DELETE, &iconTray);
- DestroyWindow(hwnd);
- PostQuitMessage(0);
- break;
- }
- else if (LOWORD(wParam) == IDM_START_WITH_WINDOWS)
- {
- if (!startWithWindows)
- {
- command = "schtasks /Create /SC ONLOGON /TN \"Start-wKillRing\" /RL HIGHEST /F /TR \"'";
- command.append(exeFullPath);
- command.append("'\"");
- strcpy(ccommand, command.c_str());
- commandResult = silentCmdResult(ccommand);
- if (commandResult.find("SUC") != std::string::npos || commandResult.find("ussie") != std::string::npos)
- {
- MessageBoxA(NULL, "Startup task successfully created", "Start with Windows", MB_ICONINFORMATION | MB_OK);
- }
- else if (commandResult.find("SUC") == std::string::npos || commandResult.find("ussie") != std::string::npos)
- {
- MessageBoxA(NULL, "Could not create startup task\nPlease execute wKillRing as Administrator", "Start with Windows", MB_ICONWARNING | MB_OK);
- }
- ModifyMenuA(hMenu, IDM_START_WITH_WINDOWS, MF_BYCOMMAND | MF_CHECKED, IDM_START_WITH_WINDOWS, "Start with Windows");
- startWithWindows = true;
- }
- else
- {
- command = "schtasks /Delete /TN \"Start-wKillRing\" /F";
- strcpy(ccommand, command.c_str());
- commandResult = silentCmdResult(ccommand);
- if (commandResult.find("SUC") != std::string::npos || commandResult.find("ussie") != std::string::npos)
- {
- MessageBoxA(NULL, "Startup task successfully deleted", "Start with Windows", MB_ICONINFORMATION | MB_OK);
- }
- ModifyMenuA(hMenu, IDM_START_WITH_WINDOWS, MF_BYCOMMAND | MF_UNCHECKED, IDM_START_WITH_WINDOWS, "Start with Windows");
- startWithWindows = false;
- }
- break;
- }
- else if (LOWORD(wParam) == IDM_RESET)
- {
- resetwKillRing(hwnd);
- break;
- }
- else if (LOWORD(wParam) == IDM_ABOUT)
- {
- MessageBox(hwnd, "wKillRing is a tool that offers a killRing\n"
- "for copy and paste clipboard in Windows.\n"
- "\n"
- "You can change the binding to your\n"
- "liking to iterate through the ring,\n"
- "press CTRL + V to paste the selection.\n"
- "\n"
- "There is also 4 ready to paste text fields\n"
- "that you can push to the clipboard\n"
- "using CTRL + SHIFT + U, I , O or P,\n"
- "press CTRL + V to paste the selection.\n"
- "\n"
- "On 01/26/19 wKillRing uses a Ms-PL.\n"
- "Please contact me at maxime.p.jolly@gmail.com\n"
- "if you have any questions or suggestions.\n",
- "Informations", MB_ICONQUESTION);
- break;
- }
- else if (LOWORD(wParam) == ID_BUTTONA1)
- {
- saveConfiguration(hwnd);
- }
- break;
- case WM_HOTKEY:
- showWindowB = false;
- break;
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- if (MessageBox(NULL, "Are you sure you want to quit?", "wKillRing", MB_YESNOCANCEL) == IDYES)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- }
- break;
- case WM_TIMER:
- switch (wParam)
- {
- case ID_TIMERA:
- {
- std::string checkClipboard = getClipboardText();
- if (copyStarted && !checkClipboard.empty())
- {
- auto it = std::find(killRing.begin(), killRing.end(), checkClipboard);
- if (it == killRing.end())
- {
- killRing.push_back(getClipboardText());
- killRingPos++;
- }
- }
- else if (!copyStarted && !checkClipboard.empty())
- {
- killRing.push_back(checkClipboard);
- killRingPos++;
- copyStarted = true;
- }
- break;
- }
- default:
- break;
- }
- break;
- case WM_SYSCOMMAND:
- if ((wParam & 0xFFF0) == SC_MINIMIZE)
- {
- //trayDrawIcon(hWindowa);
- //SetWindowLong(hWindowa, GWL_STYLE, GetWindowLong(hWindowa, GWL_STYLE) & ~WS_MINIMIZEBOX);
- SetWindowLong(hWindowa, GWL_EXSTYLE, GetWindowLong(hWindowa, GWL_EXSTYLE) & ~WS_VISIBLE);
- //SetWindowLong(hWindowa, GWL_EXSTYLE, WS_EX_NOACTIVATE);
- UpdateWindow(hWindowa);
- trayDrawIcon(hWindowa);
- ShowWindow(hWindowa, SW_HIDE);
- }
- break;
- case WM_TRAY:
- switch (lParam)
- {
- //add function for reducing windows = hide hWindowa
- case WM_LBUTTONUP:
- SetWindowLong(hWindowa, GWL_EXSTYLE, WS_EX_TOOLWINDOW);//WS_EX_NOACTIVATE
- SetWindowLong(hWindowa, GWL_STYLE, GetWindowLong(hWindowa, GWL_STYLE) & ~WS_MAXIMIZEBOX);
- ShowWindow(hWindowa, SW_SHOW);
- break;
- case WM_RBUTTONUP:
- hMenuC = CreatePopupMenu();
- AppendMenu(hMenuC, MF_STRING, ID_MENUB, "Stop wKillRing");
- SetMenuDefaultItem(hMenuC, 0, TRUE);
- SetForegroundWindow(hWindowa);
- POINT pt;
- GetCursorPos(&pt);
- TrackPopupMenu(hMenuC, TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWindowa, NULL);
- DestroyMenu(hMenuC);
- hMenu = NULL;
- PostMessage(hWindowa, WM_NULL, 0, 0);
- break;
- }
- break;
- case WM_CLOSE:
- //trayDrawIcon(hWindowa);
- ShowWindow(hWindowa, SW_HIDE);
- return 1;
- break;
- case WM_DESTROY:
- //PostQuitMessage(0);
- break;
- default:
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- LRESULT CALLBACK WndProcB(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- std::string filePath = confPath;
- filePath.append("\\pasteA.txt");
- std::ifstream fileD(filePath);
- if (!fileD.good())
- {
- std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
- fileF << "Le magasin est ouvert de 13h a 17h" << std::endl;
- fileF << "sauf le mercredi, sur rdv";
- fileF.close();
- }
- std::string excCont;
- switch (msg)
- {
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CREATE:
- hwndEditWA = CreateWindowW(L"Edit", NULL, ES_MULTILINE | ES_WANTRETURN | WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS, 11, 10, 472, 145, hwnd, (HMENU)ID_EDITWA, GetModuleHandle(NULL), NULL); //ES_AUTOVSCROLL //ES_WANTRETURN
- hwndButtonWA = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWA, GetModuleHandle(NULL), NULL);
- displayExcludeList(hwndEditWA, excCont, filePath);
- break;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTONWA)
- {
- std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
- fileB << getEditText(hwndEditWA);
- fileB.close();
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CLOSE:
- showWindowB = false;
- SetActiveWindow(hWindowa);
- return 0;
- break;
- default:
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- LRESULT CALLBACK WndProcC(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- std::string filePath = confPath;
- filePath.append("\\pasteB.txt");
- std::ifstream fileD(filePath);
- if (!fileD.good())
- {
- std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
- fileF << "Pour rediriger vos mails Zimbra rendez-vous dans" << std::endl;
- fileF << "Préférences/ Mail/ Reception des mails/ Arrivé d'un mail : faire suivre une copie à :" << std::endl;
- fileF << "et ajoutez l'adresse mail désirée";
- fileF.close();
- }
- std::string excCont;
- switch (msg)
- {
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CREATE:
- hwndEditWB = CreateWindowW(L"Edit", NULL, ES_MULTILINE | ES_WANTRETURN | WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS, 11, 10, 472, 145, hwnd, (HMENU)ID_EDITWB, GetModuleHandle(NULL), NULL); //ES_AUTOVSCROLL //ES_WANTRETURN
- hwndButtonWB = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWB, GetModuleHandle(NULL), NULL);
- displayExcludeList(hwndEditWB, excCont, filePath);
- break;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTONWB)
- {
- std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
- fileB << getEditText(hwndEditWB);
- fileB.close();
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CLOSE:
- showWindowC = false;
- SetActiveWindow(hWindowa);
- return 0;
- break;
- default:
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- LRESULT CALLBACK WndProcD(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- std::string filePath = confPath;
- filePath.append("\\pasteC.txt");
- std::ifstream fileD(filePath);
- if (!fileD.good())
- {
- std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
- fileF << "Maleureusement cet article n'est plus disponible en magasin." << std::endl;
- fileF << "Une commande de réaprovisionement va bientôt être passée," << std::endl;
- fileF << "il faut alors compter un mois pour la récéption du matériel.";
- fileF.close();
- }
- std::string excCont;
- switch (msg)
- {
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CREATE:
- hwndEditWC = CreateWindowW(L"Edit", NULL, ES_MULTILINE | ES_WANTRETURN | WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS, 11, 10, 472, 145, hwnd, (HMENU)ID_EDITWC, GetModuleHandle(NULL), NULL); //ES_AUTOVSCROLL //ES_WANTRETURN
- hwndButtonWC = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWC, GetModuleHandle(NULL), NULL);
- displayExcludeList(hwndEditWC, excCont, filePath);
- break;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTONWC)
- {
- std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
- fileB << getEditText(hwndEditWC);
- fileB.close();
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CLOSE:
- showWindowD = false;
- SetActiveWindow(hWindowa);
- return 0;
- break;
- default:
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- LRESULT CALLBACK WndProcE(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- std::string filePath = confPath;
- filePath.append("\\pasteD.txt");
- std::ifstream fileD(filePath);
- if (!fileD.good())
- {
- std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
- fileF << "Have you tried turning it off & on again?";
- fileF.close();
- }
- std::string excCont;
- switch (msg)
- {
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- {
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CREATE:
- hwndEditWD = CreateWindowW(L"Edit", NULL, ES_MULTILINE | ES_WANTRETURN | WS_HSCROLL | WS_VSCROLL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPSIBLINGS, 11, 10, 472, 145, hwnd, (HMENU)ID_EDITWD, GetModuleHandle(NULL), NULL); //ES_AUTOVSCROLL //ES_WANTRETURN
- hwndButtonWD = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWD, GetModuleHandle(NULL), NULL);
- displayExcludeList(hwndEditWD, excCont, filePath);
- break;
- case WM_COMMAND:
- if (LOWORD(wParam) == ID_BUTTONWD)
- {
- std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
- fileB << getEditText(hwndEditWD);
- fileB.close();
- SendMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case WM_CLOSE:
- showWindowE = false;
- SetActiveWindow(hWindowa);
- return 0;
- break;
- default:
- break;
- }
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- void AddMenus(HWND hwnd)
- {
- hMenubar = CreateMenu();
- hMenu = CreateMenu();
- hMenuB = CreateMenu();
- AppendMenuW(hMenu, MF_STRING, IDM_START_WITH_WINDOWS, L"&Start with Windows");
- AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
- AppendMenuW(hMenu, MF_STRING, IDM_RESET, L"&Reset");
- AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&More");
- AppendMenuW(hMenuB, MF_STRING, IDM_ABOUT, L"About");
- AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenuB, L"&?");
- SetMenu(hwnd, hMenubar);
- }
- void toClipboard(const std::string& s)
- {
- OpenClipboard(0);
- EmptyClipboard();
- HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size() + 1);
- if (!hg)
- {
- CloseClipboard();
- return;
- }
- memcpy(GlobalLock(hg), s.c_str(), s.size() + 1);
- GlobalUnlock(hg);
- SetClipboardData(CF_TEXT, hg);
- CloseClipboard();
- GlobalFree(hg);
- }
- std::string getClipboardText()
- {
- std::string text = "";
- OpenClipboard(0);
- if (IsClipboardFormatAvailable(CF_TEXT))
- {
- HANDLE hData = GetClipboardData(CF_TEXT);
- char* pszText = static_cast<char*>(GlobalLock(hData));
- text = pszText;
- GlobalUnlock(hData);
- }
- CloseClipboard();
- return text;
- }
- void resetwKillRing(HWND hwnd)
- {
- std::string filePath = confPath;
- filePath.append("\\wKillRing.cfg");
- std::ofstream confFile(filePath, std::ios::out);
- SendMessage(hHotKeyA1, HKM_SETHOTKEY, MAKEWORD(0x43, HOTKEYF_ALT), 0);
- SendMessage(hHotKeyA2, HKM_SETHOTKEY, MAKEWORD(0x56, HOTKEYF_ALT), 0);
- wHotkeyA1 = (WORD)SendMessage(hHotKeyA1, HKM_GETHOTKEY, 0, 0);
- wHotkeyA2 = (WORD)SendMessage(hHotKeyA2, HKM_GETHOTKEY, 0, 0);
- iSetResultA1 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA1, 0);
- iSetResultA2 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA2, 0);
- confFile << "leftOfKillring=" << wHotkeyA1 << "\n";
- confFile << "rightOfKillring=" << wHotkeyA2 << "\n";
- confFile << "startWithWindows=" << "0" << "\n";
- confFile.close();
- }
- void setConfiguration(HWND hwnd, HWND hotKeyHandle[])
- {
- std::string filePath, item, hotKey;
- unsigned first, last;
- unsigned short dHotKey;
- int counter = 0, idCounter = 5;
- filePath = confPath;
- filePath.append("\\wKillRing.cfg");
- if (!fileExists(filePath.c_str()))
- {
- resetwKillRing(hwnd);
- }
- else
- {
- std::ifstream inFile(filePath);
- while (std::getline(inFile, item, '\n'))
- {
- first = item.find("=");
- last = item.find('\n');
- hotKey = item.substr(first, last - first);
- hotKey.erase(0, 1);
- if (item.find("startWithWindows") == std::string::npos)
- {
- dHotKey = (unsigned short)strtoul(hotKey.c_str(), NULL, 0);
- SendMessage(hotKeyHandle[counter], HKM_SETHOTKEY, (WORD)dHotKey, 0);
- SendMessage(hwnd, WM_SETHOTKEY, (WORD)dHotKey, 0);
- registerWordHotKey(hotKeyHandle[counter], idCounter);
- counter++;
- idCounter++;
- }
- else
- {
- startWithWindows = atoi(hotKey.c_str());
- }
- }
- inFile.close();
- }
- }
- void saveConfiguration(HWND hwnd)
- {
- std::string filePath = confPath;
- filePath.append("\\wKillRing.cfg");
- std::ofstream confFile(filePath, std::ios::out);
- UnregisterHotKey(NULL, 5);
- UnregisterHotKey(NULL, 6);
- wHotkeyA1 = (WORD)SendMessage(hHotKeyA1, HKM_GETHOTKEY, 0, 0);
- wHotkeyA2 = (WORD)SendMessage(hHotKeyA2, HKM_GETHOTKEY, 0, 0);
- iSetResultA1 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA1, 0);
- iSetResultA2 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA2, 0);
- registerWordHotKey(hHotKeyA1, 5);
- registerWordHotKey(hHotKeyA2, 6);
- confFile << "copyFirstBuffer=" << wHotkeyA1 << "\n";
- confFile << "pasteFirstBuffer=" << wHotkeyA2 << "\n";
- confFile << "startWithWindows=" << startWithWindows << "\n";
- confFile.close();
- }
- LPWSTR stringToLPWSTR(const std::string& instr)
- {
- int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), NULL, 0);
- LPWSTR widestr = new WCHAR[bufferlen + 1];
- ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), widestr, bufferlen);
- widestr[bufferlen] = 0;
- return widestr;
- }
- std::string lpwstrToString(LPWSTR input)
- {
- int cSize = WideCharToMultiByte(CP_ACP, 0, input, wcslen(input), NULL, 0, NULL, NULL);
- std::string output(static_cast<size_t>(cSize), '\0');
- WideCharToMultiByte(CP_ACP, 0, input, wcslen(input), reinterpret_cast<char*>(&output[0]), cSize, NULL, NULL);
- return output;
- }
- std::string doubleBSlash(std::string path)
- {
- std::string reWrite;
- int pLength = strlen(path.c_str());
- for (int i = 0; i < pLength; ++i)
- {
- if (path[i] == '\\')
- {
- reWrite.append("\\");
- }
- reWrite.push_back(path[i]);
- }
- return reWrite;
- }
- PROCESS_INFORMATION CreateChildProcess(char szCmdline[], HANDLE hChildStdWr)
- {
- PROCESS_INFORMATION piProcInfo;
- STARTUPINFO siStartInfo;
- bool bSuccess = FALSE;
- ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
- ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
- siStartInfo.cb = sizeof(STARTUPINFO);
- siStartInfo.hStdOutput = hChildStdWr;
- siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
- bSuccess = CreateProcess(NULL, szCmdline, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &siStartInfo, &piProcInfo);
- if (!bSuccess)
- {
- exit(1);
- }
- else
- {
- CloseHandle(hChildStdWr);
- }
- return piProcInfo;
- }
- std::string ReadFromPipe(PROCESS_INFORMATION piProcInfo, HANDLE hChildStdRd)
- {
- DWORD dwRead;
- CHAR chBuf[BUFSIZE];
- bool bSuccess = FALSE;
- std::string out = "";
- for (;;)
- {
- bSuccess = ReadFile(hChildStdRd, chBuf, BUFSIZE, &dwRead, NULL);
- if (!bSuccess || dwRead == 0)
- {
- break;
- }
- std::string s(chBuf, dwRead);
- out += s;
- }
- return out;
- }
- std::string silentCmdResult(char* command)
- {
- SECURITY_ATTRIBUTES sa;
- sa.nLength = sizeof(SECURITY_ATTRIBUTES);
- sa.bInheritHandle = TRUE;
- sa.lpSecurityDescriptor = NULL;
- std::string commandResult, check;
- pipeHandles.resize(pipeHandles.size() + 2);
- procInf.resize(procInf.size() + 1);
- for (int i = 0; i < 2; i++)
- {
- pipeCounter++;
- }
- if (!CreatePipe(&pipeHandles.at(pipeCounter - 1), &pipeHandles.at(pipeCounter), &sa, 0))
- {
- exit(1);
- }
- if (!SetHandleInformation(pipeHandles.at(pipeCounter - 1), HANDLE_FLAG_INHERIT, 0))
- {
- exit(1);
- }
- procInfCounter++;
- procInf.at(procInfCounter) = CreateChildProcess(command, pipeHandles.at(pipeCounter));
- commandResult = ReadFromPipe(procInf.at(procInfCounter), pipeHandles.at(pipeCounter - 1));
- CloseHandle(procInf.at(procInfCounter).hProcess);
- CloseHandle(procInf.at(procInfCounter).hThread);
- return commandResult;
- }
- std::string execPath()
- {
- char buffer[MAX_PATH];
- GetModuleFileName(NULL, buffer, MAX_PATH);
- std::string::size_type pos = std::string(buffer).find_last_of("\\/");
- return std::string(buffer).substr(0, pos);
- }
- bool fileExists(const char* fileName)
- {
- std::ifstream infile(fileName);
- return infile.good();
- }
- bool isDir(std::string path)
- {
- DWORD fileAt = GetFileAttributesA(path.c_str());
- if (fileAt == INVALID_FILE_ATTRIBUTES)
- {
- return false;
- }
- else if (fileAt & FILE_ATTRIBUTE_DIRECTORY)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void displayExcludeList(HWND hwndEdit, std::string passedString, std::string passedPath)
- {
- std::ifstream inFileB(passedPath);
- std::string reBuildString;
- std::stringstream ssA, ssB;
- ssA << passedString << std::endl;
- while (getline(inFileB, passedString, '\n'))
- {
- OutputDebugString(ssA.str().c_str());
- reBuildString = reBuildString + passedString + "\r\n";
- }
- ssB << reBuildString;
- SetWindowText(hwndEdit, ssB.str().c_str());
- inFileB.close();
- }
- void registerWordHotKey(HWND hHotKey, int ID)
- {
- BYTE loByte = 0, hiByte = 0;
- WORD wHotkey = 0;
- UINT fsMod = 0;
- wHotkey = (WORD)SendMessage(hHotKey, HKM_GETHOTKEY, 0, 0);
- loByte = LOBYTE(wHotkey);
- hiByte = HIBYTE(wHotkey);
- switch (hiByte)
- {
- case HOTKEYF_ALT:
- fsMod = MOD_ALT;
- break;
- case HOTKEYF_CONTROL:
- fsMod = MOD_CONTROL;
- break;
- case HOTKEYF_SHIFT:
- fsMod = MOD_SHIFT;
- break;
- case HOTKEYF_CONTROL + HOTKEYF_SHIFT:
- fsMod = MOD_CONTROL + MOD_SHIFT;
- break;
- case HOTKEYF_ALT + HOTKEYF_SHIFT:
- fsMod = MOD_ALT + MOD_SHIFT;
- break;
- case HOTKEYF_ALT + HOTKEYF_CONTROL:
- fsMod = MOD_ALT + MOD_CONTROL;
- break;
- default:
- break;
- }
- if (!RegisterHotKey(NULL, ID, fsMod | MOD_NOREPEAT, loByte))
- {
- OutputDebugStringW(L"registerHotKey NOK");
- }
- else
- {
- OutputDebugStringW(L"registerHotKey OK");
- }
- }
- std::string getEditText(HWND hwndEditW)
- {
- TCHAR buffy[1024];
- GetWindowTextW(hwndEditW, (LPWSTR)buffy, 1024);
- std::string paste = lpwstrToString((LPWSTR)buffy);
- return paste;
- }
- void trayDrawIcon(HWND hwnd)
- {
- iconTray.cbSize = sizeof(NOTIFYICONDATA);
- iconTray.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- iconTray.hWnd = hwnd;
- strcpy(iconTray.szTip, "wKillRing");
- iconTray.uCallbackMessage = WM_TRAY;
- iconTray.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
- iconTray.uID = 666;
- Shell_NotifyIcon(NIM_ADD, &iconTray);
- HMENU g_menu = CreatePopupMenu();
- AppendMenu(g_menu, MF_STRING, ID_MENUB, TEXT("Exit"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement