Advertisement
Combreal

wKillringUrl.cpp

Jun 16th, 2020 (edited)
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.17 KB | None | 0 0
  1. #include <windows.h>
  2. #include <dwmapi.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <sstream>
  6. #include <string>
  7. #include "resource.h"
  8. #include <commctrl.h>
  9. #include <vector>
  10. #include <algorithm>
  11. #pragma warning(disable : 4800)
  12. #pragma comment( lib, "comctl32.lib" )
  13. #define WM_TRAY (WM_USER + 100)
  14.  
  15. int pipeCounter = -1, procInfCounter = -1;
  16. std::vector<HANDLE>pipeHandles;
  17. std::vector<PROCESS_INFORMATION>procInf;
  18. std::vector<std::string>killRing;
  19. bool showWindowB = false;
  20. bool showWindowC = false;
  21. bool showWindowD = false;
  22. bool showWindowE = false;
  23. bool startWithWindows = false;
  24. bool copyStarted = false;
  25. char wKillRingPath[MAX_PATH];
  26. char ccommand[4096];
  27. std::string exePath, exeFullPath, confPath, commandResult, command;
  28. int counter = 0, killRingPos = -1;
  29. HWND hWindowa, hWindowb, hWindowc, hWindowd, hWindowe, hButtonA1, hTextA1, hTextA2, hTextA3, hTextB1, hTextB2, hTextB3, hTextC1, hTextC2, hTextC3, hTextB;
  30. HWND hHotKeyA1, hHotKeyA2, hButtonPasteA, hButtonPasteB, hButtonPasteC, hButtonPasteD;
  31. HWND hwndEditWA, hwndButtonWA, hwndEditWB, hwndButtonWB, hwndEditWC, hwndButtonWC, hwndEditWD, hwndButtonWD;
  32. WORD wHotkeyA1, wHotkeyA2;
  33. UINT iSetResultA1, iSetResultA2;
  34. HMENU hMenubar, hMenu, hMenuB, hMenuC;
  35. INITCOMMONCONTROLSEX icex;
  36. NOTIFYICONDATA iconTray;
  37. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  38. LRESULT CALLBACK WndProcB(HWND, UINT, WPARAM, LPARAM);
  39. LRESULT CALLBACK WndProcC(HWND, UINT, WPARAM, LPARAM);
  40. LRESULT CALLBACK WndProcD(HWND, UINT, WPARAM, LPARAM);
  41. LRESULT CALLBACK WndProcE(HWND, UINT, WPARAM, LPARAM);
  42. PROCESS_INFORMATION CreateChildProcess(char szCmdline[], HANDLE hChildStdWr);
  43. std::string ReadFromPipe(PROCESS_INFORMATION piProcInfo, HANDLE hChildStdRd);
  44. void trayDrawIcon(HWND hwnd);
  45. void AddMenus(HWND);
  46. void resetwKillRing(HWND hwnd);
  47. void setConfiguration(HWND hwnd, HWND hotKeyHandle[]);
  48. void saveConfiguration(HWND hwnd);
  49. void toClipboard(const std::string& s);
  50. std::string getClipboardText();
  51. LPWSTR stringToLPWSTR(const std::string& instr);
  52. std::string lpwstrToString(LPWSTR input);
  53. std::string doubleBSlash(std::string path);
  54. std::string silentCmdResult(char* command);
  55. std::string execPath();
  56. std::string getEditText(HWND hwndEditW);
  57. bool fileExists(const char* fileName);
  58. bool isDir(std::string path);
  59. void displayExcludeList(HWND hwndEdit, std::string passedString, std::string passedPath);
  60. void registerWordHotKey(HWND hHotKey, int ID);
  61. int gCmdShow;
  62.  
  63. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow)
  64. {
  65.     gCmdShow = nCmdShow;
  66.     MSG  msg;
  67.     WNDCLASSW wc = { 0 };
  68.     wc.lpszClassName = L"wKillRing";
  69.     wc.hInstance = hInstance;
  70.     wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  71.     wc.lpfnWndProc = WndProc;
  72.     wc.hCursor = LoadCursor(0, IDC_ARROW);
  73.     wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  74.     RegisterClassW(&wc);
  75.     hWindowa = CreateWindowW(wc.lpszClassName, L"wKillRing", WS_OVERLAPPEDWINDOW, 200, 200, 372, 244, 0, 0, hInstance, 0);//WS_MINIMIZEBOX //WS_OVERLAPPEDWINDOW | WS_VISIBLE
  76.  
  77.     WNDCLASSW wcB = { 0 };
  78.     wcB.lpszClassName = L"Edit_paste-A";
  79.     wcB.hInstance = hInstance;
  80.     wcB.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  81.     wcB.lpfnWndProc = WndProcB;
  82.     wcB.hCursor = LoadCursor(0, IDC_ARROW);
  83.     wcB.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  84.     RegisterClassW(&wcB);
  85.     hWindowb = CreateWindowW(wcB.lpszClassName, L"Edit paste-A", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
  86.     ShowWindow(hWindowb, SW_HIDE);
  87.  
  88.     WNDCLASSW wcC = { 0 };
  89.     wcC.lpszClassName = L"Edit_paste-B";
  90.     wcC.hInstance = hInstance;
  91.     wcC.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  92.     wcC.lpfnWndProc = WndProcC;
  93.     wcC.hCursor = LoadCursor(0, IDC_ARROW);
  94.     wcC.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  95.     RegisterClassW(&wcC);
  96.     hWindowc = CreateWindowW(wcC.lpszClassName, L"Edit paste-B", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
  97.     ShowWindow(hWindowc, SW_HIDE);
  98.  
  99.     WNDCLASSW wcD = { 0 };
  100.     wcD.lpszClassName = L"Edit_paste-C";
  101.     wcD.hInstance = hInstance;
  102.     wcD.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  103.     wcD.lpfnWndProc = WndProcD;
  104.     wcD.hCursor = LoadCursor(0, IDC_ARROW);
  105.     wcD.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  106.     RegisterClassW(&wcD);
  107.     hWindowd = CreateWindowW(wcD.lpszClassName, L"Edit paste-C", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
  108.     ShowWindow(hWindowd, SW_HIDE);
  109.  
  110.     WNDCLASSW wcE = { 0 };
  111.     wcE.lpszClassName = L"Edit_paste-D";
  112.     wcE.hInstance = hInstance;
  113.     wcE.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  114.     wcE.lpfnWndProc = WndProcE;
  115.     wcE.hCursor = LoadCursor(0, IDC_ARROW);
  116.     wcE.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  117.     RegisterClassW(&wcE);
  118.     hWindowe = CreateWindowW(wcE.lpszClassName, L"Edit paste-D", WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, 360, 234, 500, 212, 0, 0, hInstance, 0);
  119.     ShowWindow(hWindowe, SW_HIDE);
  120.  
  121.     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  122.     icex.dwICC = ICC_HOTKEY_CLASS;
  123.     InitCommonControlsEx(&icex);
  124.     RegisterHotKey(NULL, 1, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x55);
  125.     RegisterHotKey(NULL, 2, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x49);
  126.     RegisterHotKey(NULL, 3, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x4F);
  127.     RegisterHotKey(NULL, 4, MOD_CONTROL | MOD_SHIFT | MOD_NOREPEAT, 0x50);
  128.     RegisterHotKey(NULL, HOTKEYGENURL, MOD_CONTROL | MOD_NOREPEAT, 0x20);
  129.     toClipboard("");
  130.  
  131.     while (GetMessage(&msg, NULL, 0, 0))
  132.     {
  133.         TranslateMessage(&msg);
  134.         DispatchMessage(&msg);
  135.  
  136.         if (showWindowB)
  137.         {
  138.             ShowWindow(hWindowb, nCmdShow);
  139.         }
  140.         else if (!showWindowB)
  141.         {
  142.             ShowWindow(hWindowb, SW_HIDE);
  143.         }
  144.         if (showWindowC)
  145.         {
  146.             ShowWindow(hWindowc, nCmdShow);
  147.         }
  148.         else if (!showWindowC)
  149.         {
  150.             ShowWindow(hWindowc, SW_HIDE);
  151.         }
  152.         if (showWindowD)
  153.         {
  154.             ShowWindow(hWindowd, nCmdShow);
  155.         }
  156.         else if (!showWindowD)
  157.         {
  158.             ShowWindow(hWindowd, SW_HIDE);
  159.         }
  160.         if (showWindowE)
  161.         {
  162.             ShowWindow(hWindowe, nCmdShow);
  163.         }
  164.         else if (!showWindowE)
  165.         {
  166.             ShowWindow(hWindowe, SW_HIDE);
  167.         }
  168.         if (msg.message == WM_HOTKEY)
  169.         {
  170.             OutputDebugStringW(L"WM_HOTKEY received\n");
  171.             switch (msg.wParam)
  172.             {
  173.             case HOTKEYPASTEA:
  174.                 toClipboard(getEditText(hwndEditWA));
  175.                 break;
  176.             case HOTKEYPASTEB:
  177.                 toClipboard(getEditText(hwndEditWB));
  178.                 break;
  179.             case HOTKEYPASTEC:
  180.                 toClipboard(getEditText(hwndEditWC));
  181.                 break;
  182.             case HOTKEYPASTED:
  183.                 toClipboard(getEditText(hwndEditWD));
  184.                 break;
  185.             case HOTKEYRINGLEFT:
  186.                 if (killRing.empty())
  187.                 {
  188.                     MessageBox(hWindowa, "Fill the clipboard first", "wKillRing", MB_ICONWARNING | MB_OK);
  189.                 }
  190.                 else
  191.                 {
  192.                     killRingPos--;
  193.                     if (killRingPos < 0)
  194.                     {
  195.                         killRingPos = killRing.size() - 1;
  196.                     }
  197.                     toClipboard(killRing.at(killRingPos));
  198.                 }
  199.                 break;
  200.             case HOTKEYRINGRIGHT:
  201.                 if (killRing.empty())
  202.                 {
  203.                     MessageBox(hWindowa, "Fill the clipboard first", "wKillRing", MB_ICONWARNING | MB_OK);
  204.                 }
  205.                 else
  206.                 {
  207.                     killRingPos++;
  208.                     if (killRingPos > killRing.size() - 1)
  209.                     {
  210.                         killRingPos = 0;
  211.                     }
  212.                     toClipboard(killRing.at(killRingPos));
  213.                 }
  214.                 break;
  215.             case HOTKEYGENURL:
  216.             {
  217.                 std::string cmdNumber = getClipboardText();
  218.                 std::string url = "https://support.dbs.fr/Ticket/Display.html?id=";
  219.                 int intValue = 0;
  220.                 std::stringstream conve(cmdNumber);
  221.                 conve >> intValue;
  222.                 if ((intValue >= 100000) && (intValue <= 199999))
  223.                 {
  224.                     url.append(cmdNumber);
  225.                     ShellExecuteW(NULL, L"open", L"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", stringToLPWSTR(url), NULL, SW_SHOW);
  226.                 }
  227.             }
  228.                 break;
  229.             default:
  230.                 break;
  231.             }
  232.         }
  233.     }
  234.     return (int)msg.wParam;
  235. }
  236.  
  237. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  238. {
  239.     trayDrawIcon(hWindowa);
  240.     GetModuleFileName(NULL, wKillRingPath, MAX_PATH);
  241.     exeFullPath = doubleBSlash(wKillRingPath);
  242.     exePath = execPath();
  243.     confPath = getenv("appdata");
  244.     confPath += "\\wKillRing";
  245.     if (isDir(confPath) != true)
  246.     {
  247.         command = "C:\\windows\\system32\\cmd.exe /c mkdir \"";
  248.         command.append(confPath);
  249.         command.append("\"");
  250.         strcpy(ccommand, command.c_str());
  251.         silentCmdResult(ccommand);
  252.     }
  253.     SetTimer(hwnd, ID_TIMERA, 1000, (TIMERPROC)NULL);
  254.     switch (msg)
  255.     {
  256.     case WM_CREATE:
  257.     {
  258.         AddMenus(hwnd);
  259.  
  260.         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);
  261.         hHotKeyA1 = CreateWindowEx(0, HOTKEY_CLASS, (""), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 226, 15, 112, 23, hwnd, (HMENU)ID_HOTKEYA1, GetModuleHandle(NULL), 0);
  262.         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);
  263.         hHotKeyA2 = CreateWindowEx(0, HOTKEY_CLASS, (""), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 226, 44, 112, 23, hwnd, (HMENU)ID_HOTKEYA1, GetModuleHandle(NULL), 0);
  264.         hButtonA1 = CreateWindowEx(0, WC_BUTTON, ("Save changes"), WS_VISIBLE | WS_CHILD | WS_TABSTOP, 133, 75, 102, 23, hwnd, (HMENU)ID_BUTTONA1, GetModuleHandle(NULL), 0);
  265.  
  266.         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);
  267.         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);
  268.         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);
  269.         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);
  270.  
  271.         HWND hotKeyHandle[] = { hHotKeyA1, hHotKeyA2 };
  272.         setConfiguration(hwnd, hotKeyHandle);
  273.         break;
  274.     }
  275.     case WM_COMMAND:
  276.         if (LOWORD(wParam) == ID_BUTTONPASTEA)
  277.         {
  278.             showWindowB = true;
  279.             SetActiveWindow(hWindowb);
  280.             break;
  281.         }
  282.         else if (LOWORD(wParam) == ID_BUTTONPASTEB)
  283.         {
  284.             showWindowC = true;
  285.             SetActiveWindow(hWindowc);
  286.             break;
  287.         }
  288.         else if (LOWORD(wParam) == ID_BUTTONPASTEC)
  289.         {
  290.             showWindowD = true;
  291.             SetActiveWindow(hWindowd);
  292.             break;
  293.         }
  294.         else if (LOWORD(wParam) == ID_BUTTONPASTED)
  295.         {
  296.             showWindowE = true;
  297.             SetActiveWindow(hWindowe);
  298.             break;
  299.         }
  300.         else if (LOWORD(wParam) == ID_MENUB)
  301.         {
  302.             Shell_NotifyIcon(NIM_DELETE, &iconTray);
  303.             DestroyWindow(hwnd);
  304.             PostQuitMessage(0);
  305.             break;
  306.         }
  307.         else if (LOWORD(wParam) == IDM_START_WITH_WINDOWS)
  308.         {
  309.             if (!startWithWindows)
  310.             {
  311.                 command = "schtasks /Create /SC ONLOGON /TN \"Start-wKillRing\" /RL HIGHEST /F /TR \"'";
  312.                 command.append(exeFullPath);
  313.                 command.append("'\"");
  314.                 strcpy(ccommand, command.c_str());
  315.                 commandResult = silentCmdResult(ccommand);
  316.                 if (commandResult.find("SUC") != std::string::npos || commandResult.find("ussie") != std::string::npos)
  317.                 {
  318.                     MessageBoxA(NULL, "Startup task successfully created", "Start with Windows", MB_ICONINFORMATION | MB_OK);
  319.                 }
  320.                 else if (commandResult.find("SUC") == std::string::npos || commandResult.find("ussie") != std::string::npos)
  321.                 {
  322.                     MessageBoxA(NULL, "Could not create startup task\nPlease execute wKillRing as Administrator", "Start with Windows", MB_ICONWARNING | MB_OK);
  323.                 }
  324.                 ModifyMenuA(hMenu, IDM_START_WITH_WINDOWS, MF_BYCOMMAND | MF_CHECKED, IDM_START_WITH_WINDOWS, "Start with Windows");
  325.                 startWithWindows = true;
  326.             }
  327.             else
  328.             {
  329.                 command = "schtasks /Delete /TN \"Start-wKillRing\" /F";
  330.                 strcpy(ccommand, command.c_str());
  331.                 commandResult = silentCmdResult(ccommand);
  332.                 if (commandResult.find("SUC") != std::string::npos || commandResult.find("ussie") != std::string::npos)
  333.                 {
  334.                     MessageBoxA(NULL, "Startup task successfully deleted", "Start with Windows", MB_ICONINFORMATION | MB_OK);
  335.                 }
  336.                 ModifyMenuA(hMenu, IDM_START_WITH_WINDOWS, MF_BYCOMMAND | MF_UNCHECKED, IDM_START_WITH_WINDOWS, "Start with Windows");
  337.                 startWithWindows = false;
  338.             }
  339.             break;
  340.         }
  341.         else if (LOWORD(wParam) == IDM_RESET)
  342.         {
  343.             resetwKillRing(hwnd);
  344.             break;
  345.         }
  346.         else if (LOWORD(wParam) == IDM_ABOUT)
  347.         {
  348.             MessageBox(hwnd, "wKillRing is a tool that offers a killRing\n"
  349.                 "for copy and paste clipboard in Windows.\n"
  350.                 "\n"
  351.                 "You can change the binding to your\n"
  352.                 "liking to iterate through the ring,\n"
  353.                 "press CTRL + V to paste the selection.\n"
  354.                 "\n"
  355.                 "There is also 4 ready to paste text fields\n"
  356.                 "that you can push to the clipboard\n"
  357.                 "using CTRL + SHIFT + U, I , O or P,\n"
  358.                 "press CTRL + V to paste the selection.\n"
  359.                 "\n"
  360.                 "On 01/26/19  wKillRing uses a Ms-PL.\n"
  361.                 "Please contact me at maxime.p.jolly@gmail.com\n"
  362.                 "if you have any questions or suggestions.\n",
  363.                 "Informations", MB_ICONQUESTION);
  364.             break;
  365.         }
  366.         else if (LOWORD(wParam) == ID_BUTTONA1)
  367.         {
  368.             saveConfiguration(hwnd);
  369.         }
  370.         break;
  371.     case WM_HOTKEY:
  372.         showWindowB = false;
  373.         break;
  374.     case WM_KEYDOWN:
  375.         if (wParam == VK_ESCAPE)
  376.         {
  377.             if (MessageBox(NULL, "Are you sure you want to quit?", "wKillRing", MB_YESNOCANCEL) == IDYES)
  378.             {
  379.                 SendMessage(hwnd, WM_CLOSE, 0, 0);
  380.             }
  381.         }
  382.         break;
  383.     case WM_TIMER:
  384.         switch (wParam)
  385.         {
  386.         case ID_TIMERA:
  387.         {
  388.             std::string checkClipboard = getClipboardText();
  389.             if (copyStarted && !checkClipboard.empty())
  390.             {
  391.                 auto it = std::find(killRing.begin(), killRing.end(), checkClipboard);
  392.                 if (it == killRing.end())
  393.                 {
  394.                     killRing.push_back(getClipboardText());
  395.                     killRingPos++;
  396.                 }
  397.             }
  398.             else if (!copyStarted && !checkClipboard.empty())
  399.             {
  400.                 killRing.push_back(checkClipboard);
  401.                 killRingPos++;
  402.                 copyStarted = true;
  403.             }
  404.             break;
  405.         }
  406.         default:
  407.             break;
  408.         }
  409.         break;
  410.     case WM_SYSCOMMAND:
  411.         if ((wParam & 0xFFF0) == SC_MINIMIZE)
  412.         {
  413.             //trayDrawIcon(hWindowa);
  414.             //SetWindowLong(hWindowa, GWL_STYLE, GetWindowLong(hWindowa, GWL_STYLE) & ~WS_MINIMIZEBOX);
  415.             SetWindowLong(hWindowa, GWL_EXSTYLE, GetWindowLong(hWindowa, GWL_EXSTYLE) & ~WS_VISIBLE);
  416.             //SetWindowLong(hWindowa, GWL_EXSTYLE, WS_EX_NOACTIVATE);
  417.             UpdateWindow(hWindowa);
  418.             trayDrawIcon(hWindowa);
  419.             ShowWindow(hWindowa, SW_HIDE);
  420.         }
  421.         break;
  422.     case WM_TRAY:
  423.         switch (lParam)
  424.         {
  425.             //add function for reducing windows = hide hWindowa
  426.         case WM_LBUTTONUP:
  427.             SetWindowLong(hWindowa, GWL_EXSTYLE, WS_EX_TOOLWINDOW);//WS_EX_NOACTIVATE
  428.             SetWindowLong(hWindowa, GWL_STYLE, GetWindowLong(hWindowa, GWL_STYLE) & ~WS_MAXIMIZEBOX);
  429.             ShowWindow(hWindowa, SW_SHOW);
  430.             break;
  431.         case WM_RBUTTONUP:
  432.             hMenuC = CreatePopupMenu();
  433.             AppendMenu(hMenuC, MF_STRING, ID_MENUB, "Stop wKillRing");
  434.             SetMenuDefaultItem(hMenuC, 0, TRUE);
  435.             SetForegroundWindow(hWindowa);
  436.             POINT pt;
  437.             GetCursorPos(&pt);
  438.             TrackPopupMenu(hMenuC, TPM_RIGHTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWindowa, NULL);
  439.             DestroyMenu(hMenuC);
  440.             hMenu = NULL;
  441.             PostMessage(hWindowa, WM_NULL, 0, 0);
  442.             break;
  443.         }
  444.         break;
  445.     case WM_CLOSE:
  446.         //trayDrawIcon(hWindowa);
  447.         ShowWindow(hWindowa, SW_HIDE);
  448.         return 1;
  449.         break;
  450.     case WM_DESTROY:
  451.         //PostQuitMessage(0);
  452.         break;
  453.     default:
  454.         break;
  455.     }
  456.     return DefWindowProcW(hwnd, msg, wParam, lParam);
  457. }
  458.  
  459. LRESULT CALLBACK WndProcB(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  460. {
  461.     std::string filePath = confPath;
  462.     filePath.append("\\pasteA.txt");
  463.     std::ifstream fileD(filePath);
  464.     if (!fileD.good())
  465.     {
  466.         std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
  467.         fileF << "Le magasin est ouvert de 13h a 17h" << std::endl;
  468.         fileF << "sauf le mercredi, sur rdv";
  469.         fileF.close();
  470.     }
  471.     std::string excCont;
  472.     switch (msg)
  473.     {
  474.     case WM_KEYDOWN:
  475.         if (wParam == VK_ESCAPE)
  476.         {
  477.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  478.         }
  479.         break;
  480.     case WM_CREATE:
  481.         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
  482.         hwndButtonWA = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWA, GetModuleHandle(NULL), NULL);
  483.         displayExcludeList(hwndEditWA, excCont, filePath);
  484.         break;
  485.     case WM_COMMAND:
  486.         if (LOWORD(wParam) == ID_BUTTONWA)
  487.         {
  488.             std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
  489.             fileB << getEditText(hwndEditWA);
  490.             fileB.close();
  491.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  492.         }
  493.         break;
  494.     case WM_CLOSE:
  495.         showWindowB = false;
  496.         SetActiveWindow(hWindowa);
  497.         return 0;
  498.         break;
  499.     default:
  500.         break;
  501.     }
  502.     return DefWindowProcW(hwnd, msg, wParam, lParam);
  503. }
  504.  
  505. LRESULT CALLBACK WndProcC(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  506. {
  507.     std::string filePath = confPath;
  508.     filePath.append("\\pasteB.txt");
  509.     std::ifstream fileD(filePath);
  510.     if (!fileD.good())
  511.     {
  512.         std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
  513.         fileF << "Pour rediriger vos mails Zimbra rendez-vous dans" << std::endl;
  514.         fileF << "Préférences/ Mail/ Reception des mails/ Arrivé d'un mail : faire suivre une copie à :" << std::endl;
  515.         fileF << "et ajoutez l'adresse mail désirée";
  516.         fileF.close();
  517.     }
  518.     std::string excCont;
  519.     switch (msg)
  520.     {
  521.     case WM_KEYDOWN:
  522.         if (wParam == VK_ESCAPE)
  523.         {
  524.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  525.         }
  526.         break;
  527.     case WM_CREATE:
  528.         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
  529.         hwndButtonWB = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWB, GetModuleHandle(NULL), NULL);
  530.         displayExcludeList(hwndEditWB, excCont, filePath);
  531.         break;
  532.     case WM_COMMAND:
  533.         if (LOWORD(wParam) == ID_BUTTONWB)
  534.         {
  535.             std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
  536.             fileB << getEditText(hwndEditWB);
  537.             fileB.close();
  538.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  539.         }
  540.         break;
  541.     case WM_CLOSE:
  542.         showWindowC = false;
  543.         SetActiveWindow(hWindowa);
  544.         return 0;
  545.         break;
  546.     default:
  547.         break;
  548.     }
  549.     return DefWindowProcW(hwnd, msg, wParam, lParam);
  550. }
  551.  
  552. LRESULT CALLBACK WndProcD(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  553. {
  554.     std::string filePath = confPath;
  555.     filePath.append("\\pasteC.txt");
  556.     std::ifstream fileD(filePath);
  557.     if (!fileD.good())
  558.     {
  559.         std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
  560.         fileF << "Maleureusement cet article n'est plus disponible en magasin." << std::endl;
  561.         fileF << "Une commande de réaprovisionement va bientôt être passée," << std::endl;
  562.         fileF << "il faut alors compter un mois pour la récéption du matériel.";
  563.         fileF.close();
  564.     }
  565.     std::string excCont;
  566.     switch (msg)
  567.     {
  568.     case WM_KEYDOWN:
  569.         if (wParam == VK_ESCAPE)
  570.         {
  571.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  572.         }
  573.         break;
  574.     case WM_CREATE:
  575.         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
  576.         hwndButtonWC = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWC, GetModuleHandle(NULL), NULL);
  577.         displayExcludeList(hwndEditWC, excCont, filePath);
  578.         break;
  579.     case WM_COMMAND:
  580.         if (LOWORD(wParam) == ID_BUTTONWC)
  581.         {
  582.             std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
  583.             fileB << getEditText(hwndEditWC);
  584.             fileB.close();
  585.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  586.         }
  587.         break;
  588.     case WM_CLOSE:
  589.         showWindowD = false;
  590.         SetActiveWindow(hWindowa);
  591.         return 0;
  592.         break;
  593.     default:
  594.         break;
  595.     }
  596.     return DefWindowProcW(hwnd, msg, wParam, lParam);
  597. }
  598.  
  599. LRESULT CALLBACK WndProcE(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  600. {
  601.     std::string filePath = confPath;
  602.     filePath.append("\\pasteD.txt");
  603.     std::ifstream fileD(filePath);
  604.     if (!fileD.good())
  605.     {
  606.         std::ofstream fileF(filePath, std::ios::out | std::ios::trunc);
  607.         fileF << "Have you tried turning it off & on again?";
  608.         fileF.close();
  609.     }
  610.     std::string excCont;
  611.     switch (msg)
  612.     {
  613.     case WM_KEYDOWN:
  614.         if (wParam == VK_ESCAPE)
  615.         {
  616.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  617.         }
  618.         break;
  619.     case WM_CREATE:
  620.         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
  621.         hwndButtonWD = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS, 195, 158, 95, 21, hwnd, (HMENU)ID_BUTTONWD, GetModuleHandle(NULL), NULL);
  622.         displayExcludeList(hwndEditWD, excCont, filePath);
  623.         break;
  624.     case WM_COMMAND:
  625.         if (LOWORD(wParam) == ID_BUTTONWD)
  626.         {
  627.             std::ofstream fileB(filePath, std::ios::out | std::ios::trunc);
  628.             fileB << getEditText(hwndEditWD);
  629.             fileB.close();
  630.             SendMessage(hwnd, WM_CLOSE, 0, 0);
  631.         }
  632.         break;
  633.     case WM_CLOSE:
  634.         showWindowE = false;
  635.         SetActiveWindow(hWindowa);
  636.         return 0;
  637.         break;
  638.     default:
  639.         break;
  640.     }
  641.     return DefWindowProcW(hwnd, msg, wParam, lParam);
  642. }
  643.  
  644. void AddMenus(HWND hwnd)
  645. {
  646.     hMenubar = CreateMenu();
  647.     hMenu = CreateMenu();
  648.     hMenuB = CreateMenu();
  649.     AppendMenuW(hMenu, MF_STRING, IDM_START_WITH_WINDOWS, L"&Start with Windows");
  650.     AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
  651.     AppendMenuW(hMenu, MF_STRING, IDM_RESET, L"&Reset");
  652.     AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&More");
  653.     AppendMenuW(hMenuB, MF_STRING, IDM_ABOUT, L"About");
  654.     AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenuB, L"&?");
  655.     SetMenu(hwnd, hMenubar);
  656. }
  657.  
  658. void toClipboard(const std::string& s)
  659. {
  660.     OpenClipboard(0);
  661.     EmptyClipboard();
  662.     HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size() + 1);
  663.     if (!hg)
  664.     {
  665.         CloseClipboard();
  666.         return;
  667.     }
  668.     memcpy(GlobalLock(hg), s.c_str(), s.size() + 1);
  669.     GlobalUnlock(hg);
  670.     SetClipboardData(CF_TEXT, hg);
  671.     CloseClipboard();
  672.     GlobalFree(hg);
  673. }
  674.  
  675. std::string getClipboardText()
  676. {
  677.     std::string text = "";
  678.     OpenClipboard(0);
  679.     if (IsClipboardFormatAvailable(CF_TEXT))
  680.     {
  681.         HANDLE hData = GetClipboardData(CF_TEXT);
  682.         char* pszText = static_cast<char*>(GlobalLock(hData));
  683.         text = pszText;
  684.         GlobalUnlock(hData);
  685.     }
  686.     CloseClipboard();
  687.     return text;
  688. }
  689.  
  690. void resetwKillRing(HWND hwnd)
  691. {
  692.     std::string filePath = confPath;
  693.     filePath.append("\\wKillRing.cfg");
  694.     std::ofstream confFile(filePath, std::ios::out);
  695.     SendMessage(hHotKeyA1, HKM_SETHOTKEY, MAKEWORD(0x43, HOTKEYF_ALT), 0);
  696.     SendMessage(hHotKeyA2, HKM_SETHOTKEY, MAKEWORD(0x56, HOTKEYF_ALT), 0);
  697.     wHotkeyA1 = (WORD)SendMessage(hHotKeyA1, HKM_GETHOTKEY, 0, 0);
  698.     wHotkeyA2 = (WORD)SendMessage(hHotKeyA2, HKM_GETHOTKEY, 0, 0);
  699.     iSetResultA1 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA1, 0);
  700.     iSetResultA2 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA2, 0);
  701.     confFile << "leftOfKillring=" << wHotkeyA1 << "\n";
  702.     confFile << "rightOfKillring=" << wHotkeyA2 << "\n";
  703.     confFile << "startWithWindows=" << "0" << "\n";
  704.     confFile.close();
  705. }
  706.  
  707. void setConfiguration(HWND hwnd, HWND hotKeyHandle[])
  708. {
  709.     std::string filePath, item, hotKey;
  710.     unsigned first, last;
  711.     unsigned short dHotKey;
  712.     int counter = 0, idCounter = 5;
  713.     filePath = confPath;
  714.     filePath.append("\\wKillRing.cfg");
  715.     if (!fileExists(filePath.c_str()))
  716.     {
  717.         resetwKillRing(hwnd);
  718.     }
  719.     else
  720.     {
  721.         std::ifstream inFile(filePath);
  722.         while (std::getline(inFile, item, '\n'))
  723.         {
  724.             first = item.find("=");
  725.             last = item.find('\n');
  726.             hotKey = item.substr(first, last - first);
  727.             hotKey.erase(0, 1);
  728.             if (item.find("startWithWindows") == std::string::npos)
  729.             {
  730.                 dHotKey = (unsigned short)strtoul(hotKey.c_str(), NULL, 0);
  731.                 SendMessage(hotKeyHandle[counter], HKM_SETHOTKEY, (WORD)dHotKey, 0);
  732.                 SendMessage(hwnd, WM_SETHOTKEY, (WORD)dHotKey, 0);
  733.                 registerWordHotKey(hotKeyHandle[counter], idCounter);
  734.                 counter++;
  735.                 idCounter++;
  736.             }
  737.             else
  738.             {
  739.                 startWithWindows = atoi(hotKey.c_str());
  740.             }
  741.         }
  742.         inFile.close();
  743.     }
  744. }
  745.  
  746. void saveConfiguration(HWND hwnd)
  747. {
  748.     std::string filePath = confPath;
  749.     filePath.append("\\wKillRing.cfg");
  750.     std::ofstream confFile(filePath, std::ios::out);
  751.     UnregisterHotKey(NULL, 5);
  752.     UnregisterHotKey(NULL, 6);
  753.     wHotkeyA1 = (WORD)SendMessage(hHotKeyA1, HKM_GETHOTKEY, 0, 0);
  754.     wHotkeyA2 = (WORD)SendMessage(hHotKeyA2, HKM_GETHOTKEY, 0, 0);
  755.     iSetResultA1 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA1, 0);
  756.     iSetResultA2 = SendMessage(hwnd, WM_SETHOTKEY, wHotkeyA2, 0);
  757.     registerWordHotKey(hHotKeyA1, 5);
  758.     registerWordHotKey(hHotKeyA2, 6);
  759.     confFile << "copyFirstBuffer=" << wHotkeyA1 << "\n";
  760.     confFile << "pasteFirstBuffer=" << wHotkeyA2 << "\n";
  761.     confFile << "startWithWindows=" << startWithWindows << "\n";
  762.     confFile.close();
  763. }
  764.  
  765. LPWSTR stringToLPWSTR(const std::string& instr)
  766. {
  767.     int bufferlen = ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), NULL, 0);
  768.     LPWSTR widestr = new WCHAR[bufferlen + 1];
  769.     ::MultiByteToWideChar(CP_ACP, 0, instr.c_str(), instr.size(), widestr, bufferlen);
  770.     widestr[bufferlen] = 0;
  771.     return widestr;
  772. }
  773.  
  774. std::string lpwstrToString(LPWSTR input)
  775. {
  776.     int cSize = WideCharToMultiByte(CP_ACP, 0, input, wcslen(input), NULL, 0, NULL, NULL);
  777.     std::string output(static_cast<size_t>(cSize), '\0');
  778.     WideCharToMultiByte(CP_ACP, 0, input, wcslen(input), reinterpret_cast<char*>(&output[0]), cSize, NULL, NULL);
  779.     return output;
  780. }
  781.  
  782. std::string doubleBSlash(std::string path)
  783. {
  784.     std::string reWrite;
  785.     int pLength = strlen(path.c_str());
  786.     for (int i = 0; i < pLength; ++i)
  787.     {
  788.         if (path[i] == '\\')
  789.         {
  790.             reWrite.append("\\");
  791.         }
  792.         reWrite.push_back(path[i]);
  793.     }
  794.     return reWrite;
  795. }
  796.  
  797. PROCESS_INFORMATION CreateChildProcess(char szCmdline[], HANDLE hChildStdWr)
  798. {
  799.     PROCESS_INFORMATION piProcInfo;
  800.     STARTUPINFO siStartInfo;
  801.     bool bSuccess = FALSE;
  802.     ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
  803.     ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
  804.     siStartInfo.cb = sizeof(STARTUPINFO);
  805.     siStartInfo.hStdOutput = hChildStdWr;
  806.     siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
  807.     bSuccess = CreateProcess(NULL, szCmdline, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &siStartInfo, &piProcInfo);
  808.     if (!bSuccess)
  809.     {
  810.         exit(1);
  811.     }
  812.     else
  813.     {
  814.         CloseHandle(hChildStdWr);
  815.     }
  816.     return piProcInfo;
  817. }
  818.  
  819. std::string ReadFromPipe(PROCESS_INFORMATION piProcInfo, HANDLE hChildStdRd)
  820. {
  821.     DWORD dwRead;
  822.     CHAR chBuf[BUFSIZE];
  823.     bool bSuccess = FALSE;
  824.     std::string out = "";
  825.     for (;;)
  826.     {
  827.         bSuccess = ReadFile(hChildStdRd, chBuf, BUFSIZE, &dwRead, NULL);
  828.         if (!bSuccess || dwRead == 0)
  829.         {
  830.             break;
  831.         }
  832.         std::string s(chBuf, dwRead);
  833.         out += s;
  834.     }
  835.     return out;
  836. }
  837.  
  838. std::string silentCmdResult(char* command)
  839. {
  840.     SECURITY_ATTRIBUTES sa;
  841.     sa.nLength = sizeof(SECURITY_ATTRIBUTES);
  842.     sa.bInheritHandle = TRUE;
  843.     sa.lpSecurityDescriptor = NULL;
  844.     std::string commandResult, check;
  845.     pipeHandles.resize(pipeHandles.size() + 2);
  846.     procInf.resize(procInf.size() + 1);
  847.     for (int i = 0; i < 2; i++)
  848.     {
  849.         pipeCounter++;
  850.     }
  851.     if (!CreatePipe(&pipeHandles.at(pipeCounter - 1), &pipeHandles.at(pipeCounter), &sa, 0))
  852.     {
  853.         exit(1);
  854.     }
  855.     if (!SetHandleInformation(pipeHandles.at(pipeCounter - 1), HANDLE_FLAG_INHERIT, 0))
  856.     {
  857.         exit(1);
  858.     }
  859.     procInfCounter++;
  860.     procInf.at(procInfCounter) = CreateChildProcess(command, pipeHandles.at(pipeCounter));
  861.     commandResult = ReadFromPipe(procInf.at(procInfCounter), pipeHandles.at(pipeCounter - 1));
  862.     CloseHandle(procInf.at(procInfCounter).hProcess);
  863.     CloseHandle(procInf.at(procInfCounter).hThread);
  864.     return commandResult;
  865. }
  866.  
  867. std::string execPath()
  868. {
  869.     char buffer[MAX_PATH];
  870.     GetModuleFileName(NULL, buffer, MAX_PATH);
  871.     std::string::size_type pos = std::string(buffer).find_last_of("\\/");
  872.     return std::string(buffer).substr(0, pos);
  873. }
  874.  
  875. bool fileExists(const char* fileName)
  876. {
  877.     std::ifstream infile(fileName);
  878.     return infile.good();
  879. }
  880.  
  881. bool isDir(std::string path)
  882. {
  883.     DWORD fileAt = GetFileAttributesA(path.c_str());
  884.     if (fileAt == INVALID_FILE_ATTRIBUTES)
  885.     {
  886.         return false;
  887.     }
  888.     else if (fileAt & FILE_ATTRIBUTE_DIRECTORY)
  889.     {
  890.         return true;
  891.     }
  892.     else
  893.     {
  894.         return false;
  895.     }
  896. }
  897.  
  898. void displayExcludeList(HWND hwndEdit, std::string passedString, std::string passedPath)
  899. {
  900.     std::ifstream inFileB(passedPath);
  901.     std::string reBuildString;
  902.     std::stringstream ssA, ssB;
  903.     ssA << passedString << std::endl;
  904.     while (getline(inFileB, passedString, '\n'))
  905.     {
  906.         OutputDebugString(ssA.str().c_str());
  907.         reBuildString = reBuildString + passedString + "\r\n";
  908.     }
  909.     ssB << reBuildString;
  910.     SetWindowText(hwndEdit, ssB.str().c_str());
  911.     inFileB.close();
  912. }
  913.  
  914. void registerWordHotKey(HWND hHotKey, int ID)
  915. {
  916.     BYTE loByte = 0, hiByte = 0;
  917.     WORD wHotkey = 0;
  918.     UINT fsMod = 0;
  919.     wHotkey = (WORD)SendMessage(hHotKey, HKM_GETHOTKEY, 0, 0);
  920.     loByte = LOBYTE(wHotkey);
  921.     hiByte = HIBYTE(wHotkey);
  922.     switch (hiByte)
  923.     {
  924.     case HOTKEYF_ALT:
  925.         fsMod = MOD_ALT;
  926.         break;
  927.     case HOTKEYF_CONTROL:
  928.         fsMod = MOD_CONTROL;
  929.         break;
  930.     case HOTKEYF_SHIFT:
  931.         fsMod = MOD_SHIFT;
  932.         break;
  933.     case HOTKEYF_CONTROL + HOTKEYF_SHIFT:
  934.         fsMod = MOD_CONTROL + MOD_SHIFT;
  935.         break;
  936.     case HOTKEYF_ALT + HOTKEYF_SHIFT:
  937.         fsMod = MOD_ALT + MOD_SHIFT;
  938.         break;
  939.     case HOTKEYF_ALT + HOTKEYF_CONTROL:
  940.         fsMod = MOD_ALT + MOD_CONTROL;
  941.         break;
  942.     default:
  943.         break;
  944.     }
  945.     if (!RegisterHotKey(NULL, ID, fsMod | MOD_NOREPEAT, loByte))
  946.     {
  947.         OutputDebugStringW(L"registerHotKey NOK");
  948.     }
  949.     else
  950.     {
  951.         OutputDebugStringW(L"registerHotKey OK");
  952.     }
  953. }
  954.  
  955. std::string getEditText(HWND hwndEditW)
  956. {
  957.     TCHAR buffy[1024];
  958.     GetWindowTextW(hwndEditW, (LPWSTR)buffy, 1024);
  959.     std::string paste = lpwstrToString((LPWSTR)buffy);
  960.     return paste;
  961. }
  962.  
  963. void trayDrawIcon(HWND hwnd)
  964. {
  965.     iconTray.cbSize = sizeof(NOTIFYICONDATA);
  966.     iconTray.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  967.     iconTray.hWnd = hwnd;
  968.     strcpy(iconTray.szTip, "wKillRing");
  969.     iconTray.uCallbackMessage = WM_TRAY;
  970.     iconTray.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  971.     iconTray.uID = 666;
  972.     Shell_NotifyIcon(NIM_ADD, &iconTray);
  973.     HMENU g_menu = CreatePopupMenu();
  974.     AppendMenu(g_menu, MF_STRING, ID_MENUB, TEXT("Exit"));
  975. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement