SHARE
TWEET

Untitled

a guest Aug 24th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. HWND hwndNextViewer;
  9. HWND hwnd;
  10. vector<char *> msgs;
  11.  
  12. LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  13.  
  14. namespace Clip {
  15.  
  16.  
  17.     void OnClipBoardChange() {
  18.        
  19.         //Hook ClipBoard
  20.         if (OpenClipboard(hwnd)) {
  21.             HANDLE clipBoardHandle = GetClipboardData(CF_TEXT);
  22.             msgs.push_back((char *)clipBoardHandle);
  23.             for (std::vector<char *>::iterator it = msgs.begin(); it != msgs.end(); it++){
  24.                 cout << *it;
  25.             }
  26.         }
  27.  
  28.         CloseClipboard();
  29.     }
  30.  
  31. }
  32.  
  33. int main()
  34. {
  35.     HINSTANCE hInstance = GetModuleHandle(NULL);
  36.  
  37.     HWND hwnd;
  38.     MSG Msg;
  39.     const char lpcszClassName[] = "messageClass";
  40.     WNDCLASSEX  WindowClassEx;
  41.  
  42.     ZeroMemory(&WindowClassEx, sizeof(WNDCLASSEX));
  43.     WindowClassEx.cbSize = sizeof(WNDCLASSEX);
  44.     WindowClassEx.lpfnWndProc = WindowProc;
  45.     WindowClassEx.hInstance = hInstance;
  46.     WindowClassEx.lpszClassName = lpcszClassName;
  47.  
  48.     if (RegisterClassEx(&WindowClassEx) != 0)
  49.     {
  50.         hwnd = CreateWindowEx(0, lpcszClassName, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
  51.         if (!hwnd)
  52.         {
  53.             cout << "CreateWindowEx failed: " << GetLastError() << "\n";
  54.         }
  55.     }
  56.     else
  57.     {
  58.         cout << "RegisterClassEx failed: " << GetLastError() << "\n";
  59.     }
  60.  
  61.     ShowWindow(hwnd, true);
  62.     while (GetMessage(&Msg, NULL, 0, 0) > 0)
  63.     {
  64.         TranslateMessage(&Msg);
  65.         DispatchMessage(&Msg);
  66.     }
  67.     return (int)Msg.wParam;
  68. }
  69.  
  70.  
  71.  
  72. LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  73. {
  74.     switch (uMsg)
  75.     {
  76.     case WM_CREATE:
  77.         // Add the window to the clipboard viewer chain.
  78.         hwndNextViewer = SetClipboardViewer(hWnd);
  79.         break;
  80.     case WM_DRAWCLIPBOARD:
  81.         Clip::OnClipBoardChange();
  82.         break;
  83.     case WM_CHANGECBCHAIN:
  84.         // If the next window is closing, repair the chain.
  85.         if ((HWND)wParam == hwndNextViewer)
  86.             hwndNextViewer = (HWND)lParam;
  87.  
  88.         // Otherwise, pass the message to the next link.
  89.         else if (hwndNextViewer != NULL)
  90.             SendMessage(hwndNextViewer, uMsg, wParam, lParam);
  91.         break;
  92.     case WM_DESTROY:
  93.         ChangeClipboardChain(hWnd, hwndNextViewer);
  94.         PostQuitMessage(0);
  95.         break;
  96.     default:
  97.         return DefWindowProc(hWnd, uMsg, wParam, lParam);
  98.  
  99.     }
  100.  
  101.     return 0;
  102. }
RAW Paste Data
Top