electroduck

Wallpaper test

Jan 1st, 2019
779
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define WIN32_LEAN_AND_MEAN
  2. #include <Windows.h>
  3. #include <assert.h>
  4. #include "resource.h"
  5.  
  6. static const char SZ_CLASSNAME[] = "DEXTOP";
  7.  
  8. static BOOL s_bActivated = FALSE;
  9. static HBITMAP s_hCurBitmap = NULL;
  10. static HINSTANCE s_hInstance;
  11. static BITMAP s_bmCurBitmap;
  12.  
  13. DWORD __stdcall STWinProc(HWND hWnd, UINT uMsg, WPARAM wParam,
  14.         LPARAM lParam) {
  15.     switch (uMsg) {
  16.     case WM_CREATE:
  17.         s_hCurBitmap = LoadImageA(s_hInstance,
  18.             MAKEINTRESOURCEA(IDB_ALMONDS_RAW),
  19.             IMAGE_BITMAP, 0, 0, 0);
  20.         assert(s_hCurBitmap);
  21.         GetObject(s_hCurBitmap, sizeof(BITMAP), &s_bmCurBitmap);
  22.         return 0;
  23.  
  24.     case WM_LBUTTONDOWN:
  25.         s_bActivated = !s_bActivated;
  26.         if (s_bActivated) s_hCurBitmap = LoadImageA(s_hInstance,
  27.                 MAKEINTRESOURCEA(IDB_ALMONDS_ACTIVATED),
  28.                 IMAGE_BITMAP, 0, 0, 0);
  29.         else s_hCurBitmap = LoadImageA(s_hInstance,
  30.                 MAKEINTRESOURCEA(IDB_ALMONDS_RAW),
  31.                 IMAGE_BITMAP, 0, 0, 0);
  32.         assert(s_hCurBitmap);
  33.         GetObject(s_hCurBitmap, sizeof(BITMAP), &s_bmCurBitmap);
  34.         InvalidateRect(hWnd, NULL, FALSE);
  35.         return 0;
  36.  
  37.     case WM_PAINT:
  38.     {
  39.         HANDLE hDC, hMemDC;
  40.         HGDIOBJ hOldBitmap;
  41.         PAINTSTRUCT ps;
  42.         int iOldMode;
  43.         RECT rectClient;
  44.  
  45.         assert(GetClientRect(hWnd, &rectClient));
  46.         hDC = BeginPaint(hWnd, &ps);
  47.         hMemDC = CreateCompatibleDC(hDC);
  48.         hOldBitmap = SelectObject(hMemDC, s_hCurBitmap);
  49.         iOldMode = SetStretchBltMode(hDC, HALFTONE);
  50.         StretchBlt(hDC, rectClient.left, rectClient.top,
  51.             rectClient.right - rectClient.left,
  52.             rectClient.bottom - rectClient.top, hMemDC, 0, 0,
  53.             s_bmCurBitmap.bmWidth, s_bmCurBitmap.bmHeight,
  54.             SRCCOPY);
  55.         SetStretchBltMode(hDC, iOldMode);
  56.         SelectObject(hMemDC, hOldBitmap);
  57.         DeleteDC(hMemDC);
  58.         EndPaint(hWnd, &ps);
  59.  
  60.         return 0;
  61.     }
  62.  
  63.     case WM_SIZE:
  64.         InvalidateRect(hWnd, NULL, FALSE);
  65.         return 0;
  66.  
  67.     case WM_CLOSE:
  68.         DestroyWindow(hWnd);
  69.         return 0;
  70.  
  71.     case WM_DESTROY:
  72.         ExitProcess(0);
  73.         return 0;
  74.     }
  75.  
  76.     return DefWindowProc(hWnd, uMsg, wParam, lParam);
  77. }
  78.  
  79. DWORD __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
  80.         PSZ pszCmdLine, int nCmdShow) {
  81.     HANDLE hWnd;
  82.     MSG msg;
  83.     WNDCLASSEXA wcxa = {
  84.         sizeof(WNDCLASSEXA),
  85.         0,
  86.         STWinProc,
  87.         0, 0,
  88.         hInstance,
  89.         LoadIconA(NULL, MAKEINTRESOURCEA(IDI_APPLICATION)),
  90.         LoadCursorA(NULL, MAKEINTRESOURCEA(IDC_ARROW)),
  91.         GetSysColorBrush(COLOR_BACKGROUND),
  92.         NULL, SZ_CLASSNAME, NULL
  93.     };
  94.  
  95.     s_hInstance = hInstance;
  96.     assert(RegisterClassExA(&wcxa));
  97.     hWnd = CreateWindowA(SZ_CLASSNAME, "Background",
  98.         WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 200, 200, NULL, NULL,
  99.         hInstance, 0);
  100.    
  101.     ShowWindow(hWnd, SW_SHOW);
  102.  
  103.     while (GetMessage(&msg, 0, 0, 0)) {
  104.         TranslateMessage(&msg);
  105.         DispatchMessage(&msg);
  106.     }
  107. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×