Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // stripes.cpp : Defines the entry point for the console application.
- //
- //
- // Magick++ demo to generate a simple text button
- //
- // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2003
- //
- #define _CRT_SECURE_NO_WARNINGS
- #include <Magick++.h>
- #include <string>
- #include <sstream>
- #include <iostream>
- #include "wtypes.h"
- #include "windows.h"
- #include "wininet.h"
- #include "shlobj.h"
- #include <sys/stat.h>
- using namespace std;
- using namespace Magick;
- void SetWallpaper(LPCWSTR);
- void GetDesktopResolution(int&, int&);
- bool exists (const std::string& name);
- bool exists (const char* name);
- int main( int argc, char ** argv)
- {
- // Initialize ImageMagick install location for Windows
- InitializeMagick(*argv);
- const char * image_name = "button_out.gif";
- try {
- int width, height;
- GetDesktopResolution(width, height);
- Image image;
- image.size(Geometry(width,height));
- // Set draw options
- //image.strokeColor("red");
- Color c;
- int lasti = 0;
- for(int i=rand() % 20; ; i+=rand() % 20) {
- stringstream s;
- //s<<"hsl("<<((int)rand() % 3)*255<<", 255, 127.5)";
- s<<"hsl(59, 255, "<<((int)rand() % 2)*130<<")";
- c = Color(s.str().c_str());
- image.fillColor(Color(c));
- image.draw( DrawableRectangle(lasti,0, i,height) );
- if(i>width)
- break;
- lasti = i;
- }
- //image.fillColor(Color("green"));
- //image.strokeWidth(0);
- //image.draw( DrawableRectangle(200,200, 270,170) );
- bool written = false;
- try {
- image.write(image_name);
- written = true;
- }
- catch( exception &error_ )
- {
- cout << "Image::write exception: " << error_.what() << endl;
- system("Pause");
- return 1;
- }
- if(written)
- SetWallpaper((LPCWSTR)image_name);
- //SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, (PVOID)"button_out.gif", SPIF_UPDATEINIFILE );
- image.display();
- // Display on screen
- // button.display();
- }
- catch( exception &error_ )
- {
- cout << "Caught exception: " << error_.what() << endl;
- system("Pause");
- return 1;
- }
- /*
- */
- system("Pause");
- return 0;
- }
- bool exists (const std::string& name) {
- struct stat buffer;
- return (stat (name.c_str(), &buffer) == 0);
- }
- bool exists(const char* name) {
- struct stat buffer;
- return (stat (name, &buffer) == 0);
- }
- // Get the horizontal and vertical screen sizes in pixel
- void GetDesktopResolution(int& horizontal, int& vertical)
- {
- RECT desktop;
- // Get a handle to the desktop window
- const HWND hDesktop = GetDesktopWindow();
- // Get the size of screen to the variable desktop
- GetWindowRect(hDesktop, &desktop);
- // The top left corner will have coordinates (0,0)
- // and the bottom right corner will have coordinates
- // (horizontal, vertical)
- horizontal = desktop.right;
- vertical = desktop.bottom;
- }
- void SetWallpaper(LPCWSTR file){
- if(!exists((const char* )file)) {
- wcout << "The file "<<file<<" does not exist!" << endl;
- return;
- }
- CoInitializeEx(0,COINIT_APARTMENTTHREADED);
- IActiveDesktop* desktop;
- HRESULT status = CoCreateInstance(CLSID_ActiveDesktop,NULL,CLSCTX_INPROC_SERVER,IID_IActiveDesktop,(void**)&desktop);
- WALLPAPEROPT wOption;
- ZeroMemory(&wOption, sizeof(WALLPAPEROPT));
- wOption.dwSize=sizeof(WALLPAPEROPT);
- wOption.dwStyle = WPSTYLE_CENTER;
- status = desktop->SetWallpaper(file,0);
- wcout <<"0x"<<hex<< (unsigned int)status << endl;
- status = desktop->SetWallpaperOptions(&wOption,0);
- wcout <<"0x"<<hex<< (unsigned int) status << endl;
- status = desktop->ApplyChanges(AD_APPLY_ALL);
- wcout <<"0x"<<hex<< (unsigned int) status << endl;
- desktop->Release();
- CoUninitialize();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement