Change Wallpaper Application

  • Thread starter Nikos 'paranic' Parastatidis
  • Start date
N

Nikos 'paranic' Parastatidis

Hi there group

im new here and totaly noob at cpp

i would like to ask how can i complete the folowing code in order to make an
application to change the wallpaper of a windows xp machine.

eg. changedesktop.exe c:\images\background.bmp

also i have to inform you that i have disabled command prompt on the winxp
machine witch makes me think that i dont need a console application as i see
from the new project menu on visual studio.net
the following code uses IActiveDekstop API from microsoft

http://msdn.microsoft.com/library/d...ence/ifaces/iactivedesktop/iactivedesktop.asp


long changeWallpaper(char *strPicPath, DWORD flags)
{
WCHAR tempstr[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, strPicPath, -1, tempstr, sizeof(tempstr) );

HRESULT hr;
IActiveDesktop *pActiveDesktop;

CoInitialize(NULL);
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL,
CLSCTX_INPROC_SERVER,IID_IActiveDesktop, (void**)&pActiveDesktop);
if(hr == S_OK )
{ pActiveDesktop->SetWallpaper(tempstr, 0);
WALLPAPEROPT wpo;
wpo.dwSize = sizeof(WALLPAPEROPT);
wpo.dwStyle = flags;
pActiveDesktop->SetWallpaperOptions(&wpo,0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
pActiveDesktop->Release();
return TRUE;
}
else return FALSE;
}

i wonder i someone can complete the rest of the code so i can compile it on
Visial Studio .NET


Thanks in advance
Nikos
 
P

Pete C.

Nikos said:
Hi there group

im new here and totaly noob at cpp

i would like to ask how can i complete the folowing code in order to
make an application to change the wallpaper of a windows xp machine.

Please ask further questions about Windows in a Windows group. Only standard
C++ is topical here. Nevertheless, this should work:

#include <windows.h>
#include <iostream>

long changeWallpaper(char *strPicPath, DWORD flags)
{
WCHAR tempstr[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, strPicPath, -1, tempstr, sizeof(tempstr) );

HRESULT hr;
IActiveDesktop *pActiveDesktop;

CoInitialize(NULL);
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL,
CLSCTX_INPROC_SERVER,IID_IActiveDesktop, (void**)&pActiveDesktop);
if(hr == S_OK )
{ pActiveDesktop->SetWallpaper(tempstr, 0);
WALLPAPEROPT wpo;
wpo.dwSize = sizeof(WALLPAPEROPT);
wpo.dwStyle = flags;
pActiveDesktop->SetWallpaperOptions(&wpo,0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
pActiveDesktop->Release();
return TRUE;
}
else return FALSE;
}

int main(int argc, char* argv[])
{
if(argc == 2)
{
if(!changeWallpaper(argv[1], *INSERT CORRECT FLAGS HERE*))
std::cout << "Error changing wallpaper" << std::endl;
}
else
{
std::cout << "usage: changewallpaper <image path>" << std::endl;
}
return 0;
}

You'll need to consult MSDN to find the correct flags to put in.

- Pete
 
P

Prateek R Karandikar

Hi there group
im new here and totaly noob at cpp

i would like to ask how can i complete the folowing code in order to make an
application to change the wallpaper of a windows xp machine.

eg. changedesktop.exe c:\images\background.bmp

also i have to inform you that i have disabled command prompt on the winxp
machine witch makes me think that i dont need a console application as i see
from the new project menu on visual studio.net
the following code uses IActiveDekstop API from microsoft

http://msdn.microsoft.com/library/d...ence/ifaces/iactivedesktop/iactivedesktop.asp

<code>
i wonder i someone can complete the rest of the code so i can compile it on
Visial Studio .NET


Thanks in advance
Nikos

"wallpaper" ??? "new project menu"??? etc etc Standard C++ has no such things.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
J

John Carson

Nikos 'paranic' Parastatidis said:
Hi there group

im new here and totaly noob at cpp

i would like to ask how can i complete the folowing code in order to
make an application to change the wallpaper of a windows xp machine.

For future reference, the following three groups should meet most of your
VC++/User Interface/Windows Graphics needs:

microsoft.public.vc.language
microsoft.public.win32.programmer.ui
microsoft.public.win32.programmer.gdi

Numerous other Microsoft groups can be found by connecting direct to the MS
news server at

msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top