SHARE
TWEET

Generate striped image and set is as background

Darker666 Nov 22nd, 2014 140 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // stripes.cpp : Defines the entry point for the console application.
  2. //
  3. //
  4. // Magick++ demo to generate a simple text button
  5. //
  6. // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2003
  7. //
  8. #define _CRT_SECURE_NO_WARNINGS
  9. #include <Magick++.h>
  10. #include <string>
  11. #include <sstream>
  12. #include <iostream>
  13.  
  14. #include "wtypes.h"
  15. #include "windows.h"
  16. #include "wininet.h"
  17. #include "shlobj.h"
  18.  
  19. #include <sys/stat.h>
  20.  
  21. using namespace std;
  22.  
  23. using namespace Magick;
  24.  
  25. void  SetWallpaper(LPCWSTR);
  26. void GetDesktopResolution(int&, int&);
  27.  
  28. bool exists (const std::string& name);
  29. bool exists (const char* name);
  30.  
  31. int main( int argc, char ** argv)
  32. {
  33.  
  34.   // Initialize ImageMagick install location for Windows
  35.   InitializeMagick(*argv);
  36.  
  37.   const char * image_name = "button_out.gif";
  38.  
  39.   try {
  40.         int width, height;
  41.  
  42.         GetDesktopResolution(width, height);
  43.  
  44.     Image image;
  45.         image.size(Geometry(width,height));
  46.         // Set draw options
  47.         //image.strokeColor("red");
  48.         Color c;
  49.         int lasti = 0;
  50.         for(int i=rand() % 20; ; i+=rand() % 20) {
  51.                 stringstream s;
  52.                 //s<<"hsl("<<((int)rand() % 3)*255<<", 255,  127.5)";
  53.                 s<<"hsl(59, 255,  "<<((int)rand() % 2)*130<<")";
  54.                 c = Color(s.str().c_str());
  55.  
  56.                 image.fillColor(Color(c));
  57.                 image.draw( DrawableRectangle(lasti,0, i,height) );
  58.                 if(i>width)
  59.                         break;
  60.  
  61.                 lasti = i;
  62.         }
  63.  
  64.         //image.fillColor(Color("green"));
  65.  
  66.         //image.strokeWidth(0);
  67.  
  68.         //image.draw( DrawableRectangle(200,200, 270,170) );
  69.         bool written = false;
  70.         try {
  71.       image.write(image_name);
  72.           written = true;
  73.         }
  74.     catch( exception &error_ )
  75.     {
  76.       cout << "Image::write exception: " << error_.what() << endl;
  77.           system("Pause");
  78.       return 1;
  79.     }
  80.         if(written)
  81.           SetWallpaper((LPCWSTR)image_name);
  82.           //SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, (PVOID)"button_out.gif", SPIF_UPDATEINIFILE );
  83.  
  84.         image.display();
  85.  
  86.     // Display on screen
  87.     // button.display();
  88.        
  89.  
  90.   }
  91.   catch( exception &error_ )
  92.     {
  93.       cout << "Caught exception: " << error_.what() << endl;
  94.           system("Pause");
  95.       return 1;
  96.     }
  97.   /*
  98.   */
  99.   system("Pause");
  100.   return 0;
  101. }
  102.  
  103. bool exists (const std::string& name) {
  104.   struct stat buffer;  
  105.   return (stat (name.c_str(), &buffer) == 0);
  106. }
  107. bool exists(const char* name) {
  108.   struct stat buffer;  
  109.   return (stat (name, &buffer) == 0);
  110. }
  111.  
  112. // Get the horizontal and vertical screen sizes in pixel
  113. void GetDesktopResolution(int& horizontal, int& vertical)
  114. {
  115.    RECT desktop;
  116.    // Get a handle to the desktop window
  117.    const HWND hDesktop = GetDesktopWindow();
  118.    // Get the size of screen to the variable desktop
  119.    GetWindowRect(hDesktop, &desktop);
  120.    // The top left corner will have coordinates (0,0)
  121.    // and the bottom right corner will have coordinates
  122.    // (horizontal, vertical)
  123.    horizontal = desktop.right;
  124.    vertical = desktop.bottom;
  125. }
  126.  
  127. void  SetWallpaper(LPCWSTR file){
  128.         if(!exists((const char* )file)) {
  129.      wcout << "The file "<<file<<" does not exist!" << endl;  
  130.          return;
  131.         }
  132.     CoInitializeEx(0,COINIT_APARTMENTTHREADED);
  133.     IActiveDesktop* desktop;
  134.     HRESULT status = CoCreateInstance(CLSID_ActiveDesktop,NULL,CLSCTX_INPROC_SERVER,IID_IActiveDesktop,(void**)&desktop);
  135.     WALLPAPEROPT wOption;
  136.     ZeroMemory(&wOption, sizeof(WALLPAPEROPT));
  137.     wOption.dwSize=sizeof(WALLPAPEROPT);
  138.     wOption.dwStyle = WPSTYLE_CENTER;
  139.     status = desktop->SetWallpaper(file,0);
  140.     wcout <<"0x"<<hex<< (unsigned int)status << endl;
  141.     status = desktop->SetWallpaperOptions(&wOption,0);
  142.     wcout <<"0x"<<hex<< (unsigned int) status << endl;
  143.     status = desktop->ApplyChanges(AD_APPLY_ALL);
  144.     wcout <<"0x"<<hex<< (unsigned int) status << endl;
  145.     desktop->Release();
  146.     CoUninitialize();
  147. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top