troels_y 0 Newbie Poster

im about to make a program, that changes the desktop background at morning, day and night...

right now i uses a bat file, but it pops up all the time.. and that does not look nice..

i want it to be done through the c++ program

(need the help before 1. September)

if there needs any info just tell me

this is the code for the c++ program (with bat files)

#include <stdio.h>
#include <time.h>
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
FreeConsole();

 //start var
  string log1;
  string log2;
  string log3;
  string log4;
  string log5;
  string mellemrum = "\n";
  
  log1 = "var WindowStyle_Hidden = 0";
  log2 = "var objShell = WScript.CreateObject(\"WScript.Shell\")";
  log3 = "var result = objShell.Run(\"gul.bat\", WindowStyle_Hidden)";
  log4 = "var result = objShell.Run(\"blaa.bat\", WindowStyle_Hidden)";
  log5 = "var result = objShell.Run(\"roed.bat\", WindowStyle_Hidden)";
  
  
  int i = 0;
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [80];
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  strftime (buffer,80,"%H:%M",timeinfo);
  // buffer is the time
  //atoi(&buffer); 
  // i (int) are 17:30 = 17
  // i (int) are 13:21 = 13
  // i (int) are 16:11 = 16
  
  //stop var
  
  // cmd  
  if (i >= 5 && i <= 7)       // gul
  {                           // gul
  ofstream myfile;
  myfile.open ("gul.js");
  myfile << log1;
  myfile << mellemrum;
  myfile << log2;
  myfile << mellemrum;
  myfile << log3;
  myfile.close();
  system("start gul.js");    // gul
  Sleep (2000);
  system("del gul.js");
  }                           // gul
  else 
  {
  }
  
  
  if (i >= 8 && i <= 17) // blaa
  {                           // blaa
  ofstream myfile;
  myfile.open ("blaa.js");
  myfile << log1;
  myfile << mellemrum;
  myfile << log2;
  myfile << mellemrum;
  myfile << log4;
  myfile.close();
  system("start blaa.js");
  Sleep (2000);
  system("del blaa.js");
  }                           // blaa
  else
  {
  }
  
  
  
  if (i >=1 && i <=4)   // roed
  {                           // roed
  ofstream myfile;
  myfile.open ("roed.js");
  myfile << log1;
  myfile << mellemrum;
  myfile << log2;
  myfile << mellemrum;
  myfile << log4;
  myfile.close();
  system("start roed.js");
  Sleep (2000);
  system("del roed.js");
  }                           // roed
  else 
  {
  }
  
  
  if (i >=21 && i <=24)   // roed
  {                           // roed
  ofstream myfile;
  myfile.open ("roed.js");
  myfile << log1;
  myfile << mellemrum;
  myfile << log2;
  myfile << mellemrum;
  myfile << log4;
  myfile.close();
  system("start roed.js");
  Sleep (2000);
  system("del roed.js");
  }                           // roed
  else 
  {
  }
  
  if (i >=18 && i <=20)  // gul
  {                           // gul
  ofstream myfile;
  myfile.open ("gul.js");
  myfile << log1;
  myfile << mellemrum;
  myfile << log2;
  myfile << mellemrum;
  myfile << log3;
  myfile.close();
  system("start gul.js");    // gul
  Sleep (2000);
  system("del gul.js");
  }                           // gul 
  else
  {
  }

  //Sleep(900000);
  Sleep(10000);
  
  
  system("start fixer.exe");
  


  
  //cmd end
  
  return 0;
}

i think it should look something like this... :/

#include <stdio.h>
#include <time.h>
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;

int main ()
{
FreeConsole();

 //start var
  int i = 0;
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [80];
  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  strftime (buffer,80,"%H:%M",timeinfo);

  i = atoi (buffer);

  
  //stop var
  
  // cmd  
  if (i >= 5 && i <= 7)       // gul
  {                           // gul
  HKEY hKey;
  
  char buffer[60];
  unsigned long size = sizeof(buffer);

  RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel\\Desktop\\", 0, KEY_SET_VALUE, &hKey);
  RegSetValueEx(hKey, "Wallpaper", 0,REG_SZ,(LPBYTE)buffer,size);
  RegCloseKey(hKey);
  }                           // gul
  else 
  {
  }
  
  
  if (i >= 8 && i <= 17) // blaa
  {                           // blaa
  HKEY hKey;
  
  char buffer[60];
  unsigned long size = sizeof(buffer);

  RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel\\Desktop\\", 0, KEY_SET_VALUE, &hKey);
  RegSetValueEx(hKey, "Wallpaper", 0,REG_SZ,(LPBYTE)buffer,size);
  RegCloseKey(hKey);
  }                           // blaa
  else
  {
  }
  
  if (i >=1 && i <=4)   // roed
  {                           // roed
  HKEY hKey;
  
  char buffer[60];
  unsigned long size = sizeof(buffer);

  RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel\\Desktop\\", 0, KEY_SET_VALUE, &hKey);
  RegSetValueEx(hKey, "Wallpaper", 0,REG_SZ,(LPBYTE)buffer,size);
  RegCloseKey(hKey);
  }                           // roed
  else 
  {
  }
  
  
  if (i >=21 && i <=24)   // roed
  {                           // roed
  HKEY hKey;
  
  char buffer[60];
  unsigned long size = sizeof(buffer);

  RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel\\Desktop\\", 0, KEY_SET_VALUE, &hKey);
  RegSetValueEx(hKey, "Wallpaper", 0,REG_SZ,(LPBYTE)buffer,size);
  RegCloseKey(hKey);
  }                           // roed
  else 
  {
  }
  
  
  if (i >=18 && i <=20)  // gul
  {                           // gul
  HKEY hKey;
  
  char buffer[60];
  unsigned long size = sizeof(buffer);

  RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel\\Desktop\\", 0, KEY_SET_VALUE, &hKey);
  RegSetValueEx(hKey, "Wallpaper", 0,REG_SZ,(LPBYTE)buffer,size);
  RegCloseKey(hKey);
  }                           // gul 
  else
  {
  }

  //Sleep(900000);
  Sleep(10000);
  
  
  system("start fixer.exe");
  

  //cmd end
  
  return 0;
}

for the bat files

echo off
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\blaa.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 2
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 0
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
exit
echo off
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\roed.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 2
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 0
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
exit
echo off
REG ADD "HKCU\Control Panel\Desktop" /V Wallpaper /T REG_SZ /F /D "C:\gul.bmp"
REG ADD "HKCU\Control Panel\Desktop" /V WallpaperStyle /T REG_SZ /F /D 2
REG ADD "HKCU\Control Panel\Desktop" /V TileWallpaper /T REG_SZ /F /D 0
%SystemRoot%\System32\RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters
exit