Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Note: Loading image resources and processing keyboard input is
- // not required, that's just how I demoed it. After FindWindowA,
- // just make a loop where you draw whatever you want at any interval
- // - don't worry, Windows won't try to draw over you.
- // Does not work with Wallpaper Engine running.
- // Edited 06-Jun-2019 for Windows 10 compatibility
- #define WIN32_LEAN_AND_MEAN
- #include <Windows.h>
- #include <assert.h>
- #include "resource.h"
- BOOL CALLBACK WorkerEnumProc(HWND hWnd, LPARAM lParam);
- DWORD __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
- PSZ pszCmdLine, int nCmdShow) {
- HANDLE hDC, hMemDC;
- HGDIOBJ hOldBitmap;
- HWND hWndDesktop;
- HBITMAP hBitmapImage;
- BITMAP bmImage;
- SHORT sShiftLast = 0xFFFF, sShiftCur;
- int iOldMode, iScreenW, iScreenH;
- hBitmapImage = LoadImageA(hInstance, MAKEINTRESOURCEA(IDB_RAW),
- IMAGE_BITMAP, 0, 0, 0);
- assert(hBitmapImage);
- GetObject(hBitmapImage, sizeof(BITMAP), &bmImage);
- iScreenW = GetSystemMetrics(SM_CXSCREEN);
- iScreenH = GetSystemMetrics(SM_CYSCREEN);
- hWndProgman = FindWindowA("Progman", NULL);
- if (!hWndProgman) {
- MessageBoxA(NULL, "Unable to find program manager window",
- "Error", MB_ICONERROR);
- ExitProcess(1);
- }
- if ((GetVersion() & 0x0000FFFF) == 0x0206) {
- // Windows 8.1+
- OutputDebugStringA("Windows 8.1 or later detected\r\n");
- SendMessage(hWndProgman, 0x052C, 0, 0);
- EnumWindows(WorkerEnumProc, (LPARAM)&hWndDesktop);
- } else {
- // Any earlier version
- OutputDebugStringA("Windows 8 or earlier detected\r\n");
- hWndDesktop = hWndProgman;
- }
- if (!hWndDesktop) {
- MessageBoxA(NULL, "Unable to find desktop window",
- "Error", MB_ICONERROR);
- ExitProcess(1);
- }
- // my loop. put whatever you want in yours.
- // all you need is to GetDC(hWndDesktop), draw, and ReleaseDC(hWndDesktop, hDC) each time
- while (!(GetAsyncKeyState(VK_END) & 0x8000)) {
- sShiftCur = GetAsyncKeyState(VK_SHIFT) & 0x8000;
- if (sShiftCur != sShiftLast) {
- hBitmapImage = LoadImageA(hInstance,
- MAKEINTRESOURCEA(sShiftCur ? IDB_ACTIVATED : IDB_RAW),
- IMAGE_BITMAP, 0, 0, 0);
- assert(hBitmapImage);
- GetObject(hBitmapImage, sizeof(BITMAP), &bmImage);
- sShiftLast = sShiftCur;
- hDC = GetDC(hWndDesktop);
- hMemDC = CreateCompatibleDC(hDC);
- hOldBitmap = SelectObject(hMemDC, hBitmapImage);
- iOldMode = SetStretchBltMode(hDC, HALFTONE);
- StretchBlt(hDC, 0, 0, iScreenW, iScreenH, hMemDC, 0, 0,
- bmImage.bmWidth, bmImage.bmHeight, SRCCOPY);
- SetStretchBltMode(hDC, iOldMode);
- SelectObject(hMemDC, hOldBitmap);
- ReleaseDC(hWndDesktop, hDC);
- }
- Sleep(50);
- }
- return 0;
- }
- BOOL CALLBACK WorkerEnumProc(HWND hWnd, LPARAM lParam) {
- HWND hWndDefView;
- hWndDefView = FindWindowExA(hWnd, NULL, "SHELLDLL_DefView",
- NULL);
- if (hWndDefView) {
- *(HWND*)lParam = FindWindowExA(NULL, hWnd, "WorkerW",
- NULL);
- return FALSE;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement