diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c9a181 --- /dev/null +++ b/.gitignore @@ -0,0 +1,242 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +[Xx]64/ +[Xx]86/ +[Bb]uild/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml + +# TODO: Un-comment the next line if you do not want to checkin +# your web deploy settings because they may include unencrypted +# passwords +#*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directory +AppPackages/ +BundleArtifacts/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# LightSwitch generated files +GeneratedArtifacts/ +ModelManifest.xml + +# Paket dependency manager +.paket/paket.exe + +# FAKE - F# Make +.fake/ diff --git a/Winclipper/ClipsMenu.cpp b/Winclipper/ClipsMenu.cpp new file mode 100644 index 0000000..aef1fc7 --- /dev/null +++ b/Winclipper/ClipsMenu.cpp @@ -0,0 +1,78 @@ +#include "stdafx.h" +#include "ClipsMenu.h" + +int ShowClipsMenu(HWND hWnd, HWND curWin) +{ + if (hWnd != NULL && curWin != NULL) + { + SetForegroundWindow(hWnd); + + LPPOINT cPos = new POINT; + if (!GetCursorPos(cPos)) + { + return ERROR; + } + + HMENU menu = CreatePopupMenu(); + AppendMenu(menu, MF_STRING, 999, L"TEST"); + if (TrackPopupMenu( + menu, + TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD, + (*cPos).x, + (*cPos).y, + 0, + hWnd, + NULL + )) + { + + SetForegroundWindow(curWin); + Sleep(10); + if (!OpenClipboard(curWin)) + return FALSE; + HANDLE psClipboardData = GetClipboardData(CF_UNICODETEXT); + if (psClipboardData != NULL) + { + wchar_t * data = reinterpret_cast(GlobalLock(psClipboardData)); + wchar_t * derefData = _wcsdup(data); + + SendPasteInput(); + + GlobalUnlock(psClipboardData); + } + CloseClipboard(); + } + SetForegroundWindow(curWin); + PostMessage(hWnd, WM_NULL, 0, 0); + } +} + +void SendPasteInput(void) +{ + INPUT inputCtrlKey; + INPUT inputVKey; + + inputCtrlKey.type = INPUT_KEYBOARD; + inputCtrlKey.ki.wVk = VK_CONTROL; + inputCtrlKey.ki.wScan = 0; + inputCtrlKey.ki.time = 1; + inputCtrlKey.ki.dwFlags = 0; + inputCtrlKey.ki.dwExtraInfo = 0; + + inputVKey.type = INPUT_KEYBOARD; + inputVKey.ki.wVk = 0x56; + inputVKey.ki.wScan = 0; + inputVKey.ki.time = 2; + inputVKey.ki.dwFlags = 0; + inputVKey.ki.dwExtraInfo = 0; + + INPUT ip[] = { inputCtrlKey, inputVKey }; + + SendInput(2, ip, sizeof(INPUT)); + + ip[0].ki.dwFlags = KEYEVENTF_KEYUP; + ip[1].ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(2, ip, sizeof(INPUT)); + + return; +} diff --git a/Winclipper/ClipsMenu.h b/Winclipper/ClipsMenu.h new file mode 100644 index 0000000..8e21517 --- /dev/null +++ b/Winclipper/ClipsMenu.h @@ -0,0 +1,12 @@ +#pragma once + +#define CANCELED_SELECTION 1 // user selected nothing, pressed esc, or clicked outside the window +#define SELECTED_PASTE_ITEM 2 // user selected one of the clips, and it was pasted +#define SELECTED_SETTINGS 99 // user selected the Settings option + // ERROR is returned in any other situation + +// Forward declarations of functions included in this code module: +BOOL AddToClips(HWND); +BOOL MoveToFrontOfClips(HWND); +int ShowClipsMenu(HWND, HWND); +void SendPasteInput(void); \ No newline at end of file diff --git a/Winclipper/Winclipper.cpp b/Winclipper/Winclipper.cpp new file mode 100644 index 0000000..8bbd8c6 --- /dev/null +++ b/Winclipper/Winclipper.cpp @@ -0,0 +1,219 @@ +// Winclipper.cpp : Defines the entry point for the application. +// +#include "stdafx.h" +#include "resource.h" +#include "Winclipper.h" +#include "ClipsMenu.h" + +int APIENTRY wWinMain(_In_ HINSTANCE hInstance, + _In_opt_ HINSTANCE hPrevInstance, + _In_ LPWSTR lpCmdLine, + _In_ int nCmdShow) +{ + UNREFERENCED_PARAMETER(hPrevInstance); + UNREFERENCED_PARAMETER(lpCmdLine); + + // TODO: Place code here. + + // Initialize global strings + LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + LoadStringW(hInstance, IDC_WINCLIPPER, szWindowClass, MAX_LOADSTRING); + MyRegisterClass(hInstance); + + // Perform application initialization: + if (!InitInstance (hInstance, nCmdShow)) + { + return FALSE; + } + + HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINCLIPPER)); + + MSG msg; + + // Main message loop: + while (GetMessage(&msg, nullptr, 0, 0)) + { + if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + return (int) msg.wParam; +} + + + +// +// FUNCTION: MyRegisterClass() +// +// PURPOSE: Registers the window class. +// +ATOM MyRegisterClass(HINSTANCE hInstance) +{ + WNDCLASSEXW wcex; + + wcex.cbSize = sizeof(WNDCLASSEX); + + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINCLIPPER)); + wcex.hCursor = LoadCursor(nullptr, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINCLIPPER); + wcex.lpszClassName = szWindowClass; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + + return RegisterClassExW(&wcex); +} + +// +// FUNCTION: InitInstance(HINSTANCE, int) +// +// PURPOSE: Saves instance handle and creates main window +// +// COMMENTS: +// +// In this function, we save the instance handle in a global variable and +// create and display the main program window. +// +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) +{ + hInst = hInstance; // Store instance handle in our global variable + + HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr); + + if (!hWnd) + { + return FALSE; + } + + HGDIOBJ hfDefault; + HWND hEdit; + + hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", L"", + WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL, + 0, 0, 100, 100, hWnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL); + if (hEdit == NULL) + MessageBox(hWnd, L"Could not create edit box.", L"Error", MB_OK | MB_ICONERROR); + + hfDefault = GetStockObject(DEVICE_DEFAULT_FONT); + SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0)); + + AddClipboardFormatListener(hWnd); + RegisterHotKey(hWnd, ID_REG_HOTKEY, MOD_ALT | MOD_NOREPEAT, 0x56); + + ShowWindow(hWnd, SW_HIDE); + UpdateWindow(hWnd); + + return TRUE; +} + +// +// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) +// +// PURPOSE: Processes messages for the main window. +// +// WM_COMMAND - process the application menu +// WM_PAINT - Paint the main window +// WM_DESTROY - post a quit message and return +// +// +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_COMMAND: + { + int wmId = LOWORD(wParam); + // Parse the menu selections: + switch (wmId) + { + case IDM_ABOUT: + DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); + break; + case IDM_EXIT: + DestroyWindow(hWnd); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + } + break; + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdc = BeginPaint(hWnd, &ps); + // TODO: Add any drawing code that uses hdc here... + EndPaint(hWnd, &ps); + } + break; + case WM_CLIPBOARDUPDATE: + { + if (!OpenClipboard(hWnd)) + return FALSE; + HANDLE psClipboardData = GetClipboardData(CF_UNICODETEXT); + if (psClipboardData != NULL) + { + wchar_t * data = reinterpret_cast(GlobalLock(psClipboardData)); + wchar_t * derefData = _wcsdup(data); + + SetDlgItemText(hWnd, IDC_MAIN_EDIT, derefData); + GlobalUnlock(psClipboardData); + } + CloseClipboard(); + UpdateWindow(hWnd); + } + break; + case WM_HOTKEY: + { + HWND curWin = GetForegroundWindow(); + ShowClipsMenu(hWnd, curWin); + + SetDlgItemText(hWnd, IDC_MAIN_EDIT, L"Test"); + } + break; + case WM_SIZE: + { + HWND hEdit; + RECT rcClient; + + GetClientRect(hWnd, &rcClient); + + hEdit = GetDlgItem(hWnd, IDC_MAIN_EDIT); + SetWindowPos(hEdit, NULL, 0, 0, rcClient.right, rcClient.bottom, SWP_NOZORDER); + } + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + +// Message handler for about box. +INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(lParam); + switch (message) + { + case WM_INITDIALOG: + return (INT_PTR)TRUE; + + case WM_COMMAND: + if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) + { + EndDialog(hDlg, LOWORD(wParam)); + return (INT_PTR)TRUE; + } + break; + } + return (INT_PTR)FALSE; +} diff --git a/Winclipper/Winclipper.h b/Winclipper/Winclipper.h new file mode 100644 index 0000000..466ca02 --- /dev/null +++ b/Winclipper/Winclipper.h @@ -0,0 +1,19 @@ +#pragma once +#pragma comment(linker,"\"/manifestdependency:type='win32' \ +name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ +processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") + +#define MAX_LOADSTRING 100 +#define ID_REG_HOTKEY 100 +#define IDC_MAIN_EDIT 201 + +// Global Variables: +HINSTANCE hInst; // current instance +WCHAR szTitle[MAX_LOADSTRING]; // The title bar text +WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name + +// Forward declarations of functions included in this code module: +ATOM MyRegisterClass(HINSTANCE hInstance); +BOOL InitInstance(HINSTANCE, int); +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); \ No newline at end of file diff --git a/Winclipper/Winclipper.ico b/Winclipper/Winclipper.ico new file mode 100644 index 0000000..b3ec03b Binary files /dev/null and b/Winclipper/Winclipper.ico differ diff --git a/Winclipper/Winclipper.rc b/Winclipper/Winclipper.rc new file mode 100644 index 0000000..abcb504 Binary files /dev/null and b/Winclipper/Winclipper.rc differ diff --git a/Winclipper/Winclipper.sln b/Winclipper/Winclipper.sln new file mode 100644 index 0000000..a7e4446 --- /dev/null +++ b/Winclipper/Winclipper.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Winclipper", "Winclipper.vcxproj", "{8A9A600A-8ED3-48CE-925C-DBC70BE4385D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Debug|x64.ActiveCfg = Debug|x64 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Debug|x64.Build.0 = Debug|x64 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Debug|x86.ActiveCfg = Debug|Win32 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Debug|x86.Build.0 = Debug|Win32 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Release|x64.ActiveCfg = Release|x64 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Release|x64.Build.0 = Release|x64 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Release|x86.ActiveCfg = Release|Win32 + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Winclipper/Winclipper.vcxproj b/Winclipper/Winclipper.vcxproj new file mode 100644 index 0000000..2e49e5e --- /dev/null +++ b/Winclipper/Winclipper.vcxproj @@ -0,0 +1,177 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {8A9A600A-8ED3-48CE-925C-DBC70BE4385D} + Win32Proj + Winclipper + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + PerMonitorHighDPIAware + + + + + Use + Level3 + Disabled + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Winclipper/Winclipper.vcxproj.filters b/Winclipper/Winclipper.vcxproj.filters new file mode 100644 index 0000000..59327cc --- /dev/null +++ b/Winclipper/Winclipper.vcxproj.filters @@ -0,0 +1,61 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + + + Resource Files + + + + + Resource Files + + + Resource Files + + + \ No newline at end of file diff --git a/Winclipper/resource.h b/Winclipper/resource.h new file mode 100644 index 0000000..333f14c Binary files /dev/null and b/Winclipper/resource.h differ diff --git a/Winclipper/small.ico b/Winclipper/small.ico new file mode 100644 index 0000000..b3ec03b Binary files /dev/null and b/Winclipper/small.ico differ diff --git a/Winclipper/stdafx.cpp b/Winclipper/stdafx.cpp new file mode 100644 index 0000000..1ac1cf3 --- /dev/null +++ b/Winclipper/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// Winclipper.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Winclipper/stdafx.h b/Winclipper/stdafx.h new file mode 100644 index 0000000..bb80440 --- /dev/null +++ b/Winclipper/stdafx.h @@ -0,0 +1,21 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include + +// C RunTime Header Files +#include +#include +#include +#include + + +// TODO: reference additional headers your program requires here diff --git a/Winclipper/targetver.h b/Winclipper/targetver.h new file mode 100644 index 0000000..87c0086 --- /dev/null +++ b/Winclipper/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include