Utiliser SetWallpaper

Résolu
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 - 1 nov. 2007 à 16:27
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 - 3 nov. 2007 à 14:10
Bonjour,

Je n'arrive pas à utiliser SetWallpaper dans mon projet,

/* cf. http://msdn2.microsoft.com/en-us/library/bb776362.aspx
cf. http://msdn2.microsoft.com/en-us/library/bb776357.aspxhttp://msdn2.microsoft.com/en-us/library/bb776357.aspx
 */

lorsque j'utilise cette fonction avec DEV-C++ et que je compile le projet, DEV-C++ me dit:
[Linker error] undefined reference to `SetWallpaper'

Que faut-il que j'ajoute à mon projet pour que SetWallpaper fonctionne?
Sachant que j'ai déjà mis:
#include <shlobj.h>

Merci d'avance et à bientôt...


<hr />


Nico

21 réponses

mogwai93 Messages postés 362 Date d'inscription mardi 31 décembre 2002 Statut Membre Dernière intervention 4 novembre 2023
2 nov. 2007 à 13:57
pour ndubien :
ça fonctionne sous DevCpp
ca te change ton fond d'ecran
il fallait rajouter :


#include
et enlever les "&" and le coCreateInstance !

voici tout le code :

------------------
//Attention, ce code utilise un objet COM en C.
//Il ne compilera pas en C++
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0501
//_WIN32_IE doit être supérieur ou égal à 0x0400
#include <windows.h>
#include <wininet.h>
#include <shlobj.h>
#include


 




//Dans <shlguid.h> :
// {75048700-EF1F-11D0-9888-006097DEACF9}
DEFINE_GUID( CLSID_ActiveDesktop, 0x75048700L, 0xEF1F, 0x11D0, 0x98, 0x88, 0x00, 0x60, 0x97, 0xDE, 0xAC, 0xF9);


// {F490EB00-1240-11D1-9888-006097DEACF9}
DEFINE_GUID(IID_IActiveDesktop, 0xF490EB00L, 0x1240, 0x11D1, 0x98, 0x88, 0x00, 0x60, 0x97, 0xDE, 0xAC, 0xF9);


 




//Dans <shlobj.h> encore :
////////////////////////////////////////////
// Flags for IActiveDesktop::ApplyChanges()
#define AD_APPLY_SAVE 0x00000001
#define AD_APPLY_HTMLGEN 0x00000002
#define AD_APPLY_REFRESH 0x00000004
#define AD_APPLY_ALL (AD_APPLY_SAVE | AD_APPLY_HTMLGEN | AD_APPLY_REFRESH)
#define AD_APPLY_FORCE 0x00000008
#define AD_APPLY_BUFFERED_REFRESH 0x00000010
#define AD_APPLY_DYNAMICREFRESH 0x00000020


////////////////////////////////////////////
// Flags for IActiveDesktop::GetWallpaperOptions()
// IActiveDesktop::SetWallpaperOptions()
#define WPSTYLE_CENTER 0
#define WPSTYLE_TILE 1
#define WPSTYLE_STRETCH 2
#define WPSTYLE_MAX 3


 




//Dans <shlobj.h> également :
//
// Flags and structures used by IActiveDesktop
//


typedef struct _tagWALLPAPEROPT
{
DWORD dwSize; // size of this Structure.
DWORD dwStyle; // WPSTYLE_* mentioned above
}
WALLPAPEROPT;


typedef WALLPAPEROPT *LPWALLPAPEROPT;
typedef const WALLPAPEROPT *LPCWALLPAPEROPT;


typedef struct _tagCOMPONENTSOPT
{
DWORD dwSize; //Size of this structure
BOOL fEnableComponents; //Enable components?
BOOL fActiveDesktop; // Active desktop enabled ?
}
COMPONENTSOPT;


typedef COMPONENTSOPT *LPCOMPONENTSOPT;
typedef const COMPONENTSOPT *LPCCOMPONENTSOPT;


typedef struct _tagCOMPPOS
{
DWORD dwSize; //Size of this structure
int iLeft; //Left of top-left corner in screen co-ordinates.
int iTop; //Top of top-left corner in screen co-ordinates.
DWORD dwWidth; // Width in pixels.
DWORD dwHeight; // Height in pixels.
int izIndex; // Indicates the Z-order of the component.
BOOL fCanResize; // Is the component resizeable?
BOOL fCanResizeX; // Resizeable in X-direction?
BOOL fCanResizeY; // Resizeable in Y-direction?
int iPreferredLeftPercent; //Left of top-left corner as percent of screen width
int iPreferredTopPercent; //Top of top-left corner as percent of screen height
}
COMPPOS;


typedef COMPPOS *LPCOMPPOS;
typedef const COMPPOS *LPCCOMPPOS;


typedef struct _tagCOMPSTATEINFO
{
DWORD dwSize; // Size of this structure.
int iLeft; // Left of the top-left corner in screen co-ordinates.
int iTop; // Top of top-left corner in screen co-ordinates.
DWORD dwWidth; // Width in pixels.
DWORD dwHeight; // Height in pixels.
DWORD dwItemState; // State of the component (full-screen mode or split-screen or normal state.
}
COMPSTATEINFO;


typedef COMPSTATEINFO *LPCOMPSTATEINFO;
typedef const COMPSTATEINFO *LPCCOMPSTATEINFO;


typedef struct _tagCOMPONENT
{
DWORD dwSize; //Size of this structure
DWORD dwID; //Reserved: Set it always to zero.
int iComponentType; //One of COMP_TYPE_*
BOOL fChecked; // Is this component enabled?
BOOL fDirty; // Had the component been modified and not yet saved to disk?
BOOL fNoScroll; // Is the component scrollable?
COMPPOS cpPos; // Width, height etc.,
WCHAR wszFriendlyName[MAX_PATH]; // Friendly name of component.
WCHAR wszSource[INTERNET_MAX_URL_LENGTH]; //URL of the component.
WCHAR wszSubscribedURL[INTERNET_MAX_URL_LENGTH]; //Subscrined URL


//New fields are added below. Everything above here must exactly match the IE4COMPONENT Structure.
DWORD dwCurItemState; // Current state of the Component.
COMPSTATEINFO csiOriginal; // Original state of the component when it was first added.
COMPSTATEINFO csiRestored; // Restored state of the component.
}
COMPONENT;


typedef COMPONENT *LPCOMPONENT;
typedef const COMPONENT *LPCCOMPONENT;


 


 


 


 




//Dans <shlobj.h> :
#undef INTERFACE
#define INTERFACE IActiveDesktop


DECLARE_INTERFACE_( IActiveDesktop, IUnknown )
{
 // IUnknown methods
 STDMETHOD (QueryInterface)(THIS_ REFIID riid, void **ppv) PURE;
 STDMETHOD_(ULONG, AddRef) ( THIS ) PURE;
 STDMETHOD_(ULONG, Release) ( THIS ) PURE;


 // IActiveDesktop methods
 STDMETHOD (ApplyChanges)(THIS_ DWORD dwFlags) PURE;
 STDMETHOD (GetWallpaper)(THIS_ LPWSTR pwszWallpaper, UINT cchWallpaper, DWORD dwReserved) PURE;
 STDMETHOD (SetWallpaper)(THIS_ LPCWSTR pwszWallpaper, DWORD dwReserved) PURE;
 STDMETHOD (GetWallpaperOptions)(THIS_ LPWALLPAPEROPT pwpo, DWORD dwReserved) PURE;
 STDMETHOD (SetWallpaperOptions)(THIS_ LPCWALLPAPEROPT pwpo, DWORD dwReserved) PURE;
 STDMETHOD (GetPattern)(THIS_ LPWSTR pwszPattern, UINT cchPattern, DWORD dwReserved) PURE;
 STDMETHOD (SetPattern)(THIS_ LPCWSTR pwszPattern, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItemOptions)(THIS_ LPCOMPONENTSOPT pco, DWORD dwReserved) PURE;
 STDMETHOD (SetDesktopItemOptions)(THIS_ LPCCOMPONENTSOPT pco, DWORD dwReserved) PURE;
 STDMETHOD (AddDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (AddDesktopItemWithUI)(THIS_ HWND hwnd, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (ModifyDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwFlags) PURE;
 STDMETHOD (RemoveDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItemCount)(THIS_ LPINT lpiCount, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItem)(THIS_ int nComponent, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItemByID)(THIS_ ULONG_PTR dwID, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (GenerateDesktopItemHtml)(THIS_ LPCWSTR pwszFileName, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (AddUrl)(THIS_ HWND hwnd, LPCWSTR pszSource, LPCOMPONENT pcomp, DWORD dwFlags) PURE;
 STDMETHOD (GetDesktopItemBySource)(THIS_ LPCWSTR pwszSource, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
};


 


 


int __stdcall SetWallPaper(char* FilePath, BYTE bCenter)
{
    IActiveDesktop* paDesktop;




    WALLPAPEROPT wpOpt;
    WCHAR wFilePath[MAX_PATH+4];
    if(!FilePath) return 1;
    CoInitialize(0);
    ZeroMemory(&wpOpt, sizeof(WALLPAPEROPT));
    if((CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&paDesktop)) != S_OK) return 1;
    MultiByteToWideChar(CP_ACP, 0, FilePath, -1, wFilePath, MAX_PATH);
    //paDesktop->lpVtbl->SetWallpaper(paDesktop, wFilePath, 0);
    paDesktop->SetWallpaper(wFilePath, 0);
    wpOpt.dwSize = sizeof(WALLPAPEROPT);
if(bCenter)
{
wpOpt.dwStyle = WPSTYLE_CENTER;
}else wpOpt.dwStyle=WPSTYLE_STRETCH ;
    //paDesktop->lpVtbl->SetWallpaperOptions(paDesktop, &wpOpt,0);
    //paDesktop->lpVtbl->ApplyChanges(paDesktop, AD_APPLY_ALL);
    //paDesktop->lpVtbl->Release(paDesktop);
    paDesktop->SetWallpaperOptions(&wpOpt,0);
    paDesktop->ApplyChanges(AD_APPLY_ALL);
    paDesktop->Release();
    CoUninitialize();
    return 0;
}


 


int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
 if (SetWallPaper("C:\\test.jpg", 0))
 MessageBox(0, "error", 0, 64);
 return 0;
}

---------------------
3
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
2 nov. 2007 à 14:18
3
cs_juju12 Messages postés 966 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 4 mars 2010 4
1 nov. 2007 à 17:13
Essaie d'inclure wininet.h avant shlobj.h, je vois pas trop le rapport mais apparemment il en a besoin (j'ai essayé de compiler avec et sans, ca marche seulement s'il est inclus).
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
1 nov. 2007 à 17:35
Salut juju12,
et bien mon problème c'est que j'ai déjà essayé avec WinInet.h et ça n'a pas marché pour autant....
Lorsque vous dites "j'ai essayé de compiler avec et sans, ca marche seulement s'il est inclus", avec quel compilateur avez-vous essayé? DEV-C++?
Car avec moi ça ne veut pas marcher!
A+
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_juju12 Messages postés 966 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 4 mars 2010 4
1 nov. 2007 à 20:18
Non c'était avec VS2005; j'ai essayé de voir s'il fallait une lib spéciale mais le SDK est muet là-dessus; ce qui est bizarre aussi c'est que j'ai référencé kernel32.lib seulement et ca compilait, enfin je vais encore fouiller un peu...
0
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
1 nov. 2007 à 20:22
Ta linker avec shell32.lib?

Neo_Fr
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
1 nov. 2007 à 21:03
Avec DEV-C++, ça ne marche ni avec kernel32.lib ni avec shell32.lib...
Encore merci pour votre aide.
0
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
1 nov. 2007 à 21:05
Comment ca marche pas?
Tu pourrais nous poster ton code stp?

Neo_Fr
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
1 nov. 2007 à 22:51
Et bien voici le code sur lequel j'essai d'utiliser SetWallpaper:
#include <windows.h>
#include <wininet.h>
#include <shlobj.h>



int main() {
    SetWallpaper("a.bmp",0);
    return 0;
}

Il s'agit commme vous pouvez le voir du code le plus simple possible:
les #pragma ne sont pas mis dans le code car DEV-C++ ne sait pas s'en servir tel quel,
il lui les faut dans les options du projet (ce qui est fait dans mon projet):
lib/libshell32.a
lib/libkernel32.a
Pour information, j'ai essayé de compiler ce code en C et en C++ (API Win32) mais dans les 2 cas, le même message d'erreur apparaît:
[Linker error] undefined reference to `SetWallpaper'
A+, j'espère vous avoir renseigné suffisement...
0
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
2 nov. 2007 à 01:35
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0501
#include <windows.h>
#include <wininet.h>
#include <shlobj.h>

int __stdcall SetWallPaper(char* FilePath, BYTE bCenter)
{
IActiveDesktop* paDesktop;
WALLPAPEROPT wpOpt;
WCHAR wFilePath[MAX_PATH+4];
if(!FilePath) return 1;
CoInitialize(0);
ZeroMemory(&wpOpt, sizeof(WALLPAPEROPT));
if((CoCreateInstance(&CLSID_ActiveDesktop, 0, CLSCTX_INPROC_SERVER, &IID_IActiveDesktop, (LPVOID*)&paDesktop)) != S_OK) return 1;
MultiByteToWideChar(CP_ACP, 0, FilePath, -1, wFilePath, MAX_PATH);
paDesktop->lpVtbl->SetWallpaper(paDesktop, wFilePath, 0);
wpOpt.dwSize = sizeof(WALLPAPEROPT);
if(bCenter)
{
wpOpt.dwStyle = WPSTYLE_CENTER;
}else wpOpt.dwStyle=WPSTYLE_STRETCH ;
paDesktop->lpVtbl->SetWallpaperOptions(paDesktop, &wpOpt,0);
paDesktop->lpVtbl->ApplyChanges(paDesktop, AD_APPLY_ALL);
paDesktop->lpVtbl->Release(paDesktop);
CoUninitialize();
return 0;
}

#pragma comment(linker, "/entry:_WinMain")
int WINAPI _WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
if(SetWallPaper("C:\\test.jpg", 0)) MessageBox(0, "error", 0, 0);
return 0;
}

En C, compiler avec VS sa marche nikel

Pour DevCpp, Essaye de mettre a jour les headers on sait jamais:
http://www.mingw.org/

Neo_Fr
0
mogwai93 Messages postés 362 Date d'inscription mardi 31 décembre 2002 Statut Membre Dernière intervention 4 novembre 2023
2 nov. 2007 à 09:09
MingW ne reconnait pas IActiveDesktop, ni CLSID_ActiveDesktop, ni IID_IActiveDesktop

je ne sais pas si ça peut aider ndubien :
il y a bien ce lien qui parlait de ce probleme :
http://www.developpez.net/forums/archive/index.php/t-172254.html


mais en testant je tombe sur :


undefined reference to `IID_IActiveDesktop'
undefined reference to `CLSID_ActiveDesktop'

mais apres ??? pb d'edition de liens ? (mais comme on a redefini  IActiveDesktop et ses "copains"...
0
cs_juju12 Messages postés 966 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 4 mars 2010 4
2 nov. 2007 à 11:16
Essaye ole32.lib aussi...
0
mogwai93 Messages postés 362 Date d'inscription mardi 31 décembre 2002 Statut Membre Dernière intervention 4 novembre 2023
2 nov. 2007 à 12:03
libole32.a dans le cas de MingW


si ca peut aider ndubien :
avec le code de Neo_Fr et avec le code du lien que j'ai donné précédement :
------------------------------


//Dans <shlguid.h> :
// {75048700-EF1F-11D0-9888-006097DEACF9}
DEFINE_GUID( CLSID_ActiveDesktop, 0x75048700L, 0xEF1F, 0x11D0, 0x98, 0x88, 0x00, 0x60, 0x97, 0xDE, 0xAC, 0xF9);


// {F490EB00-1240-11D1-9888-006097DEACF9}
DEFINE_GUID(IID_IActiveDesktop, 0xF490EB00L, 0x1240, 0x11D1, 0x98, 0x88, 0x00, 0x60, 0x97, 0xDE, 0xAC, 0xF9);


 


//Dans <shlobj.h> encore :
////////////////////////////////////////////
// Flags for IActiveDesktop::ApplyChanges()
#define AD_APPLY_SAVE 0x00000001
#define AD_APPLY_HTMLGEN 0x00000002
#define AD_APPLY_REFRESH 0x00000004
#define AD_APPLY_ALL (AD_APPLY_SAVE | AD_APPLY_HTMLGEN | AD_APPLY_REFRESH)
#define AD_APPLY_FORCE 0x00000008
#define AD_APPLY_BUFFERED_REFRESH 0x00000010
#define AD_APPLY_DYNAMICREFRESH 0x00000020


////////////////////////////////////////////
// Flags for IActiveDesktop::GetWallpaperOptions()
// IActiveDesktop::SetWallpaperOptions()
#define WPSTYLE_CENTER 0
#define WPSTYLE_TILE 1
#define WPSTYLE_STRETCH 2
#define WPSTYLE_MAX 3


 




//Dans <shlobj.h> également :
//
// Flags and structures used by IActiveDesktop
//


typedef struct _tagWALLPAPEROPT
{
DWORD dwSize; // size of this Structure.
DWORD dwStyle; // WPSTYLE_* mentioned above
}
WALLPAPEROPT;


typedef WALLPAPEROPT *LPWALLPAPEROPT;
typedef const WALLPAPEROPT *LPCWALLPAPEROPT;


typedef struct _tagCOMPONENTSOPT
{
DWORD dwSize; //Size of this structure
BOOL fEnableComponents; //Enable components?
BOOL fActiveDesktop; // Active desktop enabled ?
}
COMPONENTSOPT;


typedef COMPONENTSOPT *LPCOMPONENTSOPT;
typedef const COMPONENTSOPT *LPCCOMPONENTSOPT;


typedef struct _tagCOMPPOS
{
DWORD dwSize; //Size of this structure
int iLeft; //Left of top-left corner in screen co-ordinates.
int iTop; //Top of top-left corner in screen co-ordinates.
DWORD dwWidth; // Width in pixels.
DWORD dwHeight; // Height in pixels.
int izIndex; // Indicates the Z-order of the component.
BOOL fCanResize; // Is the component resizeable?
BOOL fCanResizeX; // Resizeable in X-direction?
BOOL fCanResizeY; // Resizeable in Y-direction?
int iPreferredLeftPercent; //Left of top-left corner as percent of screen width
int iPreferredTopPercent; //Top of top-left corner as percent of screen height
}
COMPPOS;


typedef COMPPOS *LPCOMPPOS;
typedef const COMPPOS *LPCCOMPPOS;


typedef struct _tagCOMPSTATEINFO
{
DWORD dwSize; // Size of this structure.
int iLeft; // Left of the top-left corner in screen co-ordinates.
int iTop; // Top of top-left corner in screen co-ordinates.
DWORD dwWidth; // Width in pixels.
DWORD dwHeight; // Height in pixels.
DWORD dwItemState; // State of the component (full-screen mode or split-screen or normal state.
}
COMPSTATEINFO;


typedef COMPSTATEINFO *LPCOMPSTATEINFO;
typedef const COMPSTATEINFO *LPCCOMPSTATEINFO;


typedef struct _tagCOMPONENT
{
DWORD dwSize; //Size of this structure
DWORD dwID; //Reserved: Set it always to zero.
int iComponentType; //One of COMP_TYPE_*
BOOL fChecked; // Is this component enabled?
BOOL fDirty; // Had the component been modified and not yet saved to disk?
BOOL fNoScroll; // Is the component scrollable?
COMPPOS cpPos; // Width, height etc.,
WCHAR wszFriendlyName[MAX_PATH]; // Friendly name of component.
WCHAR wszSource[INTERNET_MAX_URL_LENGTH]; //URL of the component.
WCHAR wszSubscribedURL[INTERNET_MAX_URL_LENGTH]; //Subscrined URL


//New fields are added below. Everything above here must exactly match the IE4COMPONENT Structure.
DWORD dwCurItemState; // Current state of the Component.
COMPSTATEINFO csiOriginal; // Original state of the component when it was first added.
COMPSTATEINFO csiRestored; // Restored state of the component.
}
COMPONENT;


typedef COMPONENT *LPCOMPONENT;
typedef const COMPONENT *LPCCOMPONENT;




//Dans <shlobj.h> :
#undef INTERFACE
#define INTERFACE IActiveDesktop


DECLARE_INTERFACE_( IActiveDesktop, IUnknown )
{
 // IUnknown methods
 STDMETHOD (QueryInterface)(THIS_ REFIID riid, void **ppv) PURE;
 STDMETHOD_(ULONG, AddRef) ( THIS ) PURE;
 STDMETHOD_(ULONG, Release) ( THIS ) PURE;


 // IActiveDesktop methods
 STDMETHOD (ApplyChanges)(THIS_ DWORD dwFlags) PURE;
 STDMETHOD (GetWallpaper)(THIS_ LPWSTR pwszWallpaper, UINT cchWallpaper, DWORD dwReserved) PURE;
 STDMETHOD (SetWallpaper)(THIS_ LPCWSTR pwszWallpaper, DWORD dwReserved) PURE;
 STDMETHOD (GetWallpaperOptions)(THIS_ LPWALLPAPEROPT pwpo, DWORD dwReserved) PURE;
 STDMETHOD (SetWallpaperOptions)(THIS_ LPCWALLPAPEROPT pwpo, DWORD dwReserved) PURE;
 STDMETHOD (GetPattern)(THIS_ LPWSTR pwszPattern, UINT cchPattern, DWORD dwReserved) PURE;
 STDMETHOD (SetPattern)(THIS_ LPCWSTR pwszPattern, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItemOptions)(THIS_ LPCOMPONENTSOPT pco, DWORD dwReserved) PURE;
 STDMETHOD (SetDesktopItemOptions)(THIS_ LPCCOMPONENTSOPT pco, DWORD dwReserved) PURE;
 STDMETHOD (AddDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (AddDesktopItemWithUI)(THIS_ HWND hwnd, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (ModifyDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwFlags) PURE;
 STDMETHOD (RemoveDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItemCount)(THIS_ LPINT lpiCount, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItem)(THIS_ int nComponent, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (GetDesktopItemByID)(THIS_ ULONG_PTR dwID, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (GenerateDesktopItemHtml)(THIS_ LPCWSTR pwszFileName, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
 STDMETHOD (AddUrl)(THIS_ HWND hwnd, LPCWSTR pszSource, LPCOMPONENT pcomp, DWORD dwFlags) PURE;
 STDMETHOD (GetDesktopItemBySource)(THIS_ LPCWSTR pwszSource, LPCOMPONENT pcomp, DWORD dwReserved) PURE;
};


------------------------------


 


il reste à remplacer
1)
    paDesktop->lpVtbl->SetWallpaper(paDesktop, wFilePath, 0);
par
    paDesktop->SetWallpaper(wFilePath, 0);


et
    paDesktop->lpVtbl->SetWallpaperOptions(paDesktop, &wpOpt,0);
    paDesktop->lpVtbl->ApplyChanges(paDesktop, AD_APPLY_ALL);
    paDesktop->lpVtbl->Release(paDesktop);
par
    paDesktop->SetWallpaperOptions(&wpOpt,0);
    paDesktop->ApplyChanges(AD_APPLY_ALL);
    paDesktop->Release();

MingW donne cette erreur 
 C:\test\main.cpp invalid initialization of reference of type 'const CLSID&' from expression of type 'const GUID*'
 C:\Dev-Cpp\include\objbase.h in passing argument 1 of `HRESULT CoCreateInstance(const CLSID&, IUnknown*, DWORD, const IID&, void**)' 

il semble ne pas aimer cette ligne :
    if((CoCreateInstance(&CLSID_ActiveDesktop, 0, CLSCTX_INPROC_SERVER, &IID_IActiveDesktop, (LPVOID*)&paDesktop)) != S_OK) return 1;
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
2 nov. 2007 à 12:20
Salut,





Réponse à Neo_FR,
j'ai essayé votre code voici le log le compilation:

Compilateur: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Exécution de  make clean
rm -f main.o  test.exe
gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"    -fexpensive-optimizations -O3
main.c: In function `SetWallPaper':
main.c:9: error: `IActiveDesktop' undeclared (first use in this function)
main.c:9: error: (Each undeclared identifier is reported only once
main.c:9: error: for each function it appears in.)
main.c:9: error: `paDesktop' undeclared (first use in this function)
main.c:10: error: `WALLPAPEROPT' undeclared (first use in this function)
main.c:10: error: syntax error before "wpOpt"
main.c:14: error: `wpOpt' undeclared (first use in this function)
main.c:15: error: `CLSID_ActiveDesktop' undeclared (first use in this function)
main.c:15: error: `IID_IActiveDesktop' undeclared (first use in this function)
main.c:21: error: `WPSTYLE_CENTER' undeclared (first use in this function)
main.c:22: error: `WPSTYLE_STRETCH' undeclared (first use in this function)
main.c:24: error: `AD_APPLY_ALL' undeclared (first use in this function)
make.exe: *** [main.o] Error 1
Exécution terminée

Réponse à Juju12:
ole32 est déjà utilisé dans mon projet

Réponse à mogwai93:
Je vais analyser votre réponse...

A+ et encore merci...
0
Neo_Fr Messages postés 653 Date d'inscription mardi 6 décembre 2005 Statut Membre Dernière intervention 10 novembre 2014 2
2 nov. 2007 à 12:46
Au pire si tu tient absolument a rester sous Devcpp, tu peux faire une dll en C que tu compile avec VS

Neo_Fr
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
2 nov. 2007 à 14:00
Bonjour mogwai93,
je viens d'effectuer les remplacements que vous m'avez dis ce qui me donne le code suivant:
avec les libs suivantes (celles que l'ont m'a suggéré dans les réponses précédentes):
lib/libshell32.a
lib/libkernel32.a
lib/libole32.a
et obtiens le code suivant:
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0501
#include <windows.h>
#include <wininet.h>
#include <shlobj.h>
#include <objbase.h>



int __stdcall SetWallPaper(char* FilePath, BYTE bCenter)
{
    IActiveDesktop* paDesktop;
    WALLPAPEROPT wpOpt;
    WCHAR wFilePath[MAX_PATH+4];
    if(!FilePath) return 1;
    CoInitialize(0);
    ZeroMemory(&wpOpt, sizeof(WALLPAPEROPT));
    if((CoCreateInstance(&CLSID_ActiveDesktop, 0, CLSCTX_INPROC_SERVER, &IID_IActiveDesktop, (LPVOID*)&paDesktop)) != S_OK) return 1;
    MultiByteToWideChar(CP_ACP, 0, FilePath, -1, wFilePath, MAX_PATH);
    paDesktop->SetWallpaper(wFilePath, 0);
    wpOpt.dwSize = sizeof(WALLPAPEROPT);
if(bCenter)
{
wpOpt.dwStyle = WPSTYLE_CENTER;
}else wpOpt.dwStyle=WPSTYLE_STRETCH ;
    paDesktop->SetWallpaperOptions(&wpOpt,0);
    paDesktop->ApplyChanges(AD_APPLY_ALL);
    paDesktop->Release();
    CoUninitialize();
    return 0;
}



#pragma comment(linker, "/entry:_WinMain")
int WINAPI _WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
if(SetWallPaper("C:\\test.jpg", 0)) MessageBox(0, "error", 0, 0);
  return 0;
}
et les erreurs suivantes en compilant en C:
Compilateur: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Exécution de  make clean
rm -f main.o  test.exe


gcc.exe -c main.c -o main.o -I"C:/Dev-Cpp/include"    -fexpensive-optimizations -O3



main.c: In function `SetWallPaper':
main.c:10: error: `IActiveDesktop' undeclared (first use in this function)
main.c:10: error: (Each undeclared identifier is reported only once
main.c:10: error: for each function it appears in.)
main.c:10: error: `paDesktop' undeclared (first use in this function)
main.c:11: error: `WALLPAPEROPT' undeclared (first use in this function)
main.c:11: error: syntax error before "wpOpt"
main.c:15: error: `wpOpt' undeclared (first use in this function)
main.c:16: error: `CLSID_ActiveDesktop' undeclared (first use in this function)
main.c:16: error: `IID_IActiveDesktop' undeclared (first use in this function)
main.c:22: error: `WPSTYLE_CENTER' undeclared (first use in this function)
main.c:23: error: `WPSTYLE_STRETCH' undeclared (first use in this function)
main.c:25: error: `AD_APPLY_ALL' undeclared (first use in this function)



make.exe: *** [main.o] Error 1





Exécution terminée


et en C++:
Compilateur: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Exécution de  make clean
rm -f main.o  test2.exe



g++.exe -c main.c -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"    -fexpensive-optimizations -O3



main.c: In function `int SetWallPaper(char*, BYTE)':
main.c:10: error: `IActiveDesktop' undeclared (first use this function)
main.c:10: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.c:10: error: `paDesktop' undeclared (first use this function)
main.c:11: error: `WALLPAPEROPT' undeclared (first use this function)
main.c:11: error: expected `;' before "wpOpt"



main.c:15: error: `wpOpt' undeclared (first use this function)



main.c:16: error: `CLSID_ActiveDesktop' undeclared (first use this function)
main.c:16: error: `IID_IActiveDesktop' undeclared (first use this function)
main.c:22: error: `WPSTYLE_CENTER' undeclared (first use this function)
main.c:23: error: `WPSTYLE_STRETCH' undeclared (first use this function)
main.c:25: error: `AD_APPLY_ALL' undeclared (first use this function)



make.exe: *** [main.o] Error 1




Exécution terminée



Merci quand même pour votre aide!
A+
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
2 nov. 2007 à 14:02
Pour information: Ma réponse précédente répond à la réponse de mogwai93 postée le 02/11/2007 à 12:03:05
0
mogwai93 Messages postés 362 Date d'inscription mardi 31 décembre 2002 Statut Membre Dernière intervention 4 novembre 2023
2 nov. 2007 à 14:04
prends mon code de 13h57
et tu n'as besoin que de lib/libole32.a (enfin pour mon code)
compilé avec le compilo c++
j'obtiens un exe de 7ko (6 656 octets)
0
ndubien Messages postés 557 Date d'inscription dimanche 25 septembre 2005 Statut Membre Dernière intervention 10 mai 2014 4
2 nov. 2007 à 14:11
Ma question va sans doute paraître bête, mais lorsque tu met
//Dans <shlobj.h>
faut-il que j'y mette dans mon main.c?
Si non, pourrais-tu me renvoyer le code de main (sans les trucs de shlobj.h)
ou bien faut t'il que j'y ajoute à shlobj?

Désolé pour la question et encore merci
0
mogwai93 Messages postés 362 Date d'inscription mardi 31 décembre 2002 Statut Membre Dernière intervention 4 novembre 2023
2 nov. 2007 à 14:41
j'ai testé le code qui se trouve entre "--------"
tu fais copier coller de la totalité
et tu colles dans main.c
0
Rejoignez-nous