Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <Windows.h>
- #include <iostream>
- #include <vector>
- using namespace std;
- HWND hwndNextViewer;
- HWND hwnd;
- vector<char *> msgs;
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- namespace Clip {
- void OnClipBoardChange() {
- //Hook ClipBoard
- if (OpenClipboard(hwnd)) {
- HANDLE clipBoardHandle = GetClipboardData(CF_TEXT);
- msgs.push_back((char *)clipBoardHandle);
- for (std::vector<char *>::iterator it = msgs.begin(); it != msgs.end(); it++){
- cout << *it;
- }
- }
- CloseClipboard();
- }
- }
- int main()
- {
- HINSTANCE hInstance = GetModuleHandle(NULL);
- HWND hwnd;
- MSG Msg;
- const char lpcszClassName[] = "messageClass";
- WNDCLASSEX WindowClassEx;
- ZeroMemory(&WindowClassEx, sizeof(WNDCLASSEX));
- WindowClassEx.cbSize = sizeof(WNDCLASSEX);
- WindowClassEx.lpfnWndProc = WindowProc;
- WindowClassEx.hInstance = hInstance;
- WindowClassEx.lpszClassName = lpcszClassName;
- if (RegisterClassEx(&WindowClassEx) != 0)
- {
- hwnd = CreateWindowEx(0, lpcszClassName, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
- if (!hwnd)
- {
- cout << "CreateWindowEx failed: " << GetLastError() << "\n";
- }
- }
- else
- {
- cout << "RegisterClassEx failed: " << GetLastError() << "\n";
- }
- ShowWindow(hwnd, true);
- while (GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return (int)Msg.wParam;
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_CREATE:
- // Add the window to the clipboard viewer chain.
- hwndNextViewer = SetClipboardViewer(hWnd);
- break;
- case WM_DRAWCLIPBOARD:
- Clip::OnClipBoardChange();
- break;
- case WM_CHANGECBCHAIN:
- // If the next window is closing, repair the chain.
- if ((HWND)wParam == hwndNextViewer)
- hwndNextViewer = (HWND)lParam;
- // Otherwise, pass the message to the next link.
- else if (hwndNextViewer != NULL)
- SendMessage(hwndNextViewer, uMsg, wParam, lParam);
- break;
- case WM_DESTROY:
- ChangeClipboardChain(hWnd, hwndNextViewer);
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement