I saw someone at school who had a program that was supposed to change the background, and log you out (so the change would take effect) but it only worked on his computer, and he "lost" the source code.
I have been looking online for a while for code that would do that, so I could experiment with it.
I found this code (C++)
#include <windows.h>
int main()
{
SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, (PVOID)"image.jpg", SPIF_UPDATEINIFILE );
}
which sort of worked..
It worked twice with an image that was located in the same folder, and I tested two images, and after the second one it just stopped working.
I can't for the life of me figure out why it stopped working (I have tried multiple file extensions, so I know that isn't the issue).
I am working in Dev-C++, if that makes a difference to anyone.
Also, I would like to be able to modify the code to use a url instead of a local image...would that be possible?
Thanks!
Edit: If I change image.jpg to image.bmp it changes every time..But that means that it would only work with *.bmp? I had it working with a jpeg before.
#include <windows.h>
int main()
{
int i;
for(i=0;;i++)
{
Sleep(800);
if(i%2==0)
{
const wchar_t *filenm = L"C:\\Pictures\\image1.jpg"; //ADDRESS of first image
bool isWallSet=SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0,(void*)filenm,SPIF_UPDATEINIFILE);
}
else
{
const wchar_t *filenm = L"C:\\Pictures\\image2.jpg"; //ADDRESS of second image
bool isWallSet=SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0,(void*)filenm,SPIF_UPDATEINIFILE);
}
}
return 0;
}
Related
I am looking to change the Windows desktop background wallpaper in C++ using the Windows API.
I have read the following posts on this topic:
How to change desktop background using VC++
SystemParametersInfo sets wallpaper completly black (using SPI_SETDESKWALLPAPER)
Problem:
When I execute the code, the desktop background changes to completely black like in the post above (yes, I did try the suggested fix in that post. No luck.)
Code:
#include <windows.h>
int main() {
std::string s = "C:\\picture.jpg";
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID*)s.c_str(), SPIF_SENDCHANGE);
return 0;
}
I have also tried just (void*) instead of (PVOID*) above and an L in front of the string. Nothing works so far.
SOLVED:
Changing SystemParametersInfo to SystemParametersInfoA (as suggested in the comment and answer) did the trick.
I believe you should use a wchar_t as input for SystemParametersInfo() instead of a string and also use SystemParametersInfoW().
The following code worked for me:
#include <windows.h>
#include <iostream>
int main() {
const wchar_t *path = L"C:\\image.png";
int result;
result = SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void *)path, SPIF_UPDATEINIFILE);
std::cout << result;
return 0;
}
Where result should return true if it manages to change the background.
I have been coding for a few years now, but in 2016 I took a couple years off. Now I decided to come back, so I wanted to play around with some reverse engineering.
I played around with a game called Black Ops 1: Zombies. I found the memory addresses, then I went into C++ to code a simple cheat for unlimited ammo (This is offline), but it didn't work, so tried using ReadProcessMemory instead to see if it gives the correct ammo. The console started printing out "0". I thought there might been something with the code so I looked up some of my older source code, and the code was the same, tried installing VS 2015 instead in case the compiler is the problem, still nothing, tried GNCC compiler, still nothing. Tried using it on my second computer and it worked. I tried disabling Anti-Virus and windows defender but still nothing.
Here is the source code if it means anything:
#include <iostream>
#include <Windows.h>
using namespace std;
DWORD Address = 0x180A6C8;
DWORD pID;
int points;
int main()
{
while (true)
{
HWND hWnd = FindWindowA(0, ("Call of Duty®: BlackOps"));
GetWindowThreadProcessId(hWnd, &pID);
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pID);
ReadProcessMemory(pHandle, (LPVOID)Address, &points, sizeof(points), 0);
cout << points << endl;
Sleep(100);
}
}
A.) Can you read the Address in Cheat Engine etc
B.) Does it require a base address (e.g "client.dll")? If so get the module base address of the required module.
This is my first time ever asking something here, so I apologize if I do anything wrong.
I have a problem with a program I am trying to write.
What I want to do is have the user pick a folder and the program prints all the documents (mostly a mix of pdf and word files) without any more user interaction.
And to make matters worse, the system I am working in is severely restricted, so my testing possibilities are limited.
Basically, what I want is to do some sort of equivalent of right-click printing in code. Or copy a file to the printer queue.
If anyone could point me in the right direction I would be very grateful. Google isn't much help. I tried executing the print command, but it doesn't do what I want it to.
My current attempt:
void folderFrame::onOpen(wxCommandEvent &event)
{
int listLength;
wxArrayString fileList;
wxString pFolder, pCommand;
chooseFolder = new wxDirDialog(this, _("Please choose folder from which to print:"), "", wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST, wxDefaultPosition, wxDefaultSize,"");
if (chooseFolder->ShowModal() == wxID_OK) //User chooses folder
{
int pResult;
pFolder = chooseFolder->GetPath();
wxDir::GetAllFiles(pFolder, &fileList, "", wxDIR_FILES); //Get all files in folder
listLength = fileList.GetCount(); //Get number of files
for(int i = 0; i < listLength; i++) //For each file...
{
pCommand = _T("print /d:\\\\app065\\300408_P18 "); //Make command to execute
pCommand.append(fileList[i]);
theText->AppendText(fileList[i]); //The text ctrl is to check what commands I actually execute
theText->AppendText("\n"); //And to check if the system return errors
theText->AppendText(pCommand);
theText->AppendText("\n");
pResult = wxExecute(pCommand, wxEXEC_SYNC | wxEXEC_SHOW_CONSOLE | wxEXEC_NOEVENTS, NULL, NULL); //Print!!!!
theText->AppendText(wxString::Format(wxT("%i\n"), pResult));
}
}
}
print .... prints only one file.
copy only returns 0 (success error code, but nothing happens)
So, here I am stuck. Any help getting forward would be greatly appreciated.
/Mike
This actually isn't really hard, since your path hints at Windows. The second parameter of ShellExecute can be "print".
I am doing my work but suddenly while reading data from file, i suddenly faced text in other form i also carried a small test to check whether is it my code fault or Visual Studio 2012 gone mad. I also debug but values in "line[]" coming correct. But i found small test is still giving me same thing:
here is my small code test:
file: input.txt
{
value := (rate * dollar) + (rate1 * dollar1);
totalvalue := value / 2;
t1 = ivariable > 10 && ivariable < 100
{
value := (rate * dollar) + (rate1 * dollar1);
totalvalue := value / 2;
}
}
code:
#include <sstream>
#include <fstream>
using namespace std;
void main(){
const int si = 1500;
string line[si];
ifstream infile;
infile.open("input.txt");
cout<<"Reading"<<endl;
// infile>>data;
// cout<<data<<endl;
int a=0;
int size=0;
// string line[1500];
// for (int i=0;i<10;i++){
while(!infile.eof()){
getline(infile,line[a],'\n');
cout<<line[a]<<endl;
a++;
}
}
and the output:
Any idea please share......
Looks like you have copied down some text from pdf either from Adobe or Nitro and pasted in notepad as a .txt. Never do such thing always try to either by write your self or use Notepad editor. I also faced such thing while doing compiler. My teacher gave me inputs in pdf file and i copied. Sorry for late reply i was reading Light comments and me a laugh that he such you.... Good Luck!
Your input.txt is encoded in Unicode, but your console is not set to render Unicode.
Save your file as plain ASCII.
UPDATE: I could solve the problem. Question can be closed! (If you wonder how: check solution)
I got a little problem. I recently decided to buy a Macbook Air since we have to work with POSIX based functions such as pthread_create, fork etc (parallel programming). It's my first laptop with MacOS on it.
I installed Xcode on it and started a new c++ project. I then wrote my program and tried to run it. There were no errors and the build succeeded but when i tried to run it i got SIGABRT errors at the strangest places. I didn't know why that happened so i copied the code in an eclipse project on my windows desktop and it worked just fine. Can you help me with this? What could be the issue? Did I maybe forget to install something?
#include <iostream>
#include <unistd.h>
#include <fstream>
#include <vector>
#include <map>
#include <iterator>
#include <cstdlib>
int main(int argc, const char * argv[])
{
const char* sequenceFile=argv[1];
const char* patternFile=argv[2];
std::ifstream file;
file.open(sequenceFile,std::ifstream::in);
std::vector<std::string> k;
std::string line;
if(file.is_open()){
while(std::getline(file,line)){
k.push_back(line);
}
}
int lengseq=atoi(k.at(0).c_str()); //for example SIGABRT here
std::string sequence = k.at(1);
file.close();
file.open(patternFile,std::ifstream::in);
k.clear();
if(file.is_open()){
while(std::getline(file,line)){
k.push_back(line);
}
}
std::map<std::string,int> patterns;
for(unsigned i=1;i<k.size()-1;){
patterns[k.at(i+1)]=atoi(k.at(i).c_str());
i+=2;
}
//serial
bool seqCheck = false;
typedef std::vector<std::pair<std::string, int> > my_vector;
my_vector patternOccurences;
typedef std::map<std::string,int>::iterator it_type;
for(it_type iterator=patterns.begin();iterator!=patterns.end();iterator++){
for(int i = 1;i<lengseq;i++){
if(i+iterator->second-1<=lengseq){
for(int j=0;j<iterator->second;j++){
if(sequence.at(j+i-1)==iterator->first.at(j)){
seqCheck=true;
}
else{
seqCheck=false;
break;
}
}
if(seqCheck==true){
patternOccurences.push_back(std::make_pair(iterator->first,i));
}
}
}
}
for(unsigned i =0;i<patternOccurences.size();i++){
std::cout<<"Pattern: "<<patternOccurences.at(i).first<<" at index "<<patternOccurences.at(i).second-1<<std::endl;
}
return 0;
}
That was the code i was using. I'm sorry for the mess in the code. And in case you're wondering I did indeed set the command line arguments so that's not the issue.
EDIT: It seems like the files the files cant be opened. I added:
else{
std::cerr<<"Couldn't open file!";
return 0;
}
after if(file.is_open()) and it jumps straight in there. I set the filename (command line arguments with project->scheme->edit scheme and then added as arguments and i have the textfiles in the project directory. What could be the issue?
SOLUTION: The problem was that i had to type the entire path to the textfiles. I was used to have the textfiles in the project directory and then i didnt have to type the path while i was working with eclipse on my windows desktop (probably because of the workspace). Thanks to all who helped. Ill remember to type the path from now on when I'm working with Xcode. ;)
Thank you in advance and I hope you can help me.
Kazoooie