Help with simple desktop background generator

I am a beginner in c++, but I wanted to try making a simple bitmap desktop background generator using this library (as an exercise for myself): http://www.partow.net/programming/bitmap/index.html#simpleexample02

I learned how to do essentially everything as I went so pardon my inexperience

I want to know the following:

Is this a feasible idea?
Am I going about it in the correct way?
Is there a method of directly applying the bitmap to the background instead of saving it to the memory and pointing to it?
And lastly,
Why is my code updating the background to solid black instead of the specified bitmap?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <windows.h>
#include <iostream>
#include <shlobj.h>
#include <time.h>
#include <cstdlib>
#include <string>
#include <sstream>
#include "bitmap_image.hpp"

using namespace std;

bool setBackground();

int main()
{
    while(true)
    {
        //sets bg
        if(setBackground()) cout << "Applied Background"<<endl;
        else {
            DWORD DWLastError = GetLastError();
            cout << "\nError: " << std::hex << DWLastError;
        }
        //deletes residual bitmap
        if(remove("output.bmp")) cout << "Removed file"<<endl;
        else {
            DWORD DWLastError = GetLastError();
            cout << "\nError: " << std::hex << DWLastError;
        }
    }

    cin.get();
    return EXIT_SUCCESS;
}

bitmap_image drawFrame()
{
    bitmap_image frame(1920,1080);

    // set background to orange
    frame.set_all_channels(255, 150, 50);

    image_drawer draw(frame);

    draw.pen_width(3);
    draw.pen_color(255, 0, 0);
    draw.circle(frame.width() / 2, frame.height() / 2, 50);

    frame.save_image("output.bmp");
}

bool setBackground()
{
  //Returns true on success, false otherwise.
  stringstream filePath;
  filePath << "output.bmp";
  return SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (PVOID)filePath.str().c_str(),
                            SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);

}
Topic archived. No new replies allowed.