mogwai93
Messages postés362Date d'inscriptionmardi 31 décembre 2002StatutMembreDerniè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
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 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 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;
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 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).
ndubien
Messages postés557Date d'inscriptiondimanche 25 septembre 2005StatutMembreDernière intervention10 mai 20144 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+
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_juju12
Messages postés966Date d'inscriptionsamedi 3 avril 2004StatutMembreDernière intervention 4 mars 20104 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...
ndubien
Messages postés557Date d'inscriptiondimanche 25 septembre 2005StatutMembreDernière intervention10 mai 20144 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...
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 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 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;
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;
ndubien
Messages postés557Date d'inscriptiondimanche 25 septembre 2005StatutMembreDernière intervention10 mai 20144 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...
ndubien
Messages postés557Date d'inscriptiondimanche 25 septembre 2005StatutMembreDernière intervention10 mai 20144 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>
#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
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
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)
mogwai93
Messages postés362Date d'inscriptionmardi 31 décembre 2002StatutMembreDerniè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)
ndubien
Messages postés557Date d'inscriptiondimanche 25 septembre 2005StatutMembreDernière intervention10 mai 20144 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?