Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "framework.h"
- #include "WinnerX.h"
- #include <windows.h>
- #include <iostream>
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_CLIPBOARDUPDATE:
- {
- std::wcout << std::endl << L"WM_CLIPBOARDUPDATE" << std::endl;
- if (!IsClipboardFormatAvailable(CF_TEXT))
- {
- break;
- }
- Sleep(1); // necessary for OpenClipboard
- if (!OpenClipboard(hWnd))
- {
- std::wcout << L"Error: " << GetLastError() << std::endl;
- break;
- }
- auto clipboardObject = GetClipboardData(CF_TEXT);
- if (clipboardObject == nullptr)
- {
- std::wcout << L"Error: " << GetLastError() << std::endl;
- break;
- }
- auto copyiedText = (char*)GlobalLock(clipboardObject);
- if (copyiedText != nullptr)
- {
- std::wcout << L"Copyied: " << copyiedText << std::endl;
- GlobalUnlock(copyiedText);
- }
- CloseClipboard();
- }
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
- #define MAX_LOADSTRING 100
- WCHAR szTitle[MAX_LOADSTRING];
- WCHAR szWindowClass[MAX_LOADSTRING];
- int main()
- {
- auto appModule = GetModuleHandle(nullptr);
- LoadStringW(appModule, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadStringW(appModule, IDC_WINNERX, szWindowClass, MAX_LOADSTRING);
- auto wcex = WNDCLASSEXW{};
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.lpfnWndProc = WndProc;
- wcex.hInstance = appModule;
- wcex.lpszClassName = szWindowClass;
- if (!RegisterClassExW(&wcex))
- {
- std::wcout << L"Error: " << GetLastError() << std::endl;
- return false;
- }
- auto hWnd = CreateWindowEx(0, szWindowClass, szTitle, 0, 0, 0, 0, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
- if (!hWnd)
- {
- std::wcout << L"Error: " << GetLastError() << std::endl;
- return false;
- }
- if (!AddClipboardFormatListener(hWnd))
- {
- std::wcout << L"Error: " << GetLastError() << std::endl;
- return false;
- }
- auto msg = MSG();
- while (GetMessage(&msg, nullptr, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- RemoveClipboardFormatListener(hWnd);
- return (int)msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment