Help Au secours

NAVIE Messages postés 23 Date d'inscription samedi 1 janvier 2005 Statut Membre Dernière intervention 23 avril 2006 - 8 nov. 2005 à 19:40
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019 - 9 nov. 2005 à 00:40
Bonjour,
j'écris ce message pour un problème que j'ai avec un de mes programmes.
Je compile avec DevCpp Version 4.9.9.2 et j'ai crée deux fichiers sources: l'un s'appelle "main.cpp" et l'autre "MoteurCentral.h".

Voici leurs codes:


MoteurCentral.h:

#pragma once

#include <windows.h>
#include <mmsystem.h>
#include <vector>
using namespace std;

#ifndef MoteurCentral

#define MoteurCentral

class MoteurCentral
{
protected:
HINSTANCE m_hInstance;
HWND m_hHwnd;
TCHAR m_szWindowClass[32];
TCHAR m_szTitre[32];
WORD m_wIcon, m_wSmallIcon;
int m_iLongueur, m_iLargeur;
int m_iDelai;

public:
MoteurCentral(HINSTANCE hInstance, LPTSTR szWindowClass, LPTSTR szTitre,
WORD wIcon, WORD wSmallIcon,
int iLongueur = GetSystemMetrics(SM_CXSCREEN),
int iLargeur = GetSystemMetrics(SM_CYSCREEN));
virtual ~MoteurCentral();

BOOL Initialisation(int iCmdShow);
LRESULT HandleEvent(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

HINSTANCE GetInstance() {return m_hInstance;};
HWND GetHwnd() {return m_hHwnd;};
LPTSTR GetTitre() {return m_szTitre;};
WORD GetIcon() {return m_wIcon;};
WORD GetSmallIcon() {return m_wSmallIcon;};
int GetLongueur() {return m_iLongueur;};
int GetLargeur() {return m_iLargeur;};
int GetDelai() {return m_iDelai;};
int GetNombreAction() {return (1000/m_iDelai);};
int GetLongueurEcriture() {return m_iLongueur-
(GetSystemMetrics(SM_CYFIXEDFRAME)*2);};
int GetLargeurEcriture() {return m_iLargeur-
(GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics(SM_CYCAPTION));};


void SetInstance(HINSTANCE hInstance) {m_hInstance=hInstance;};
void SetHwnd(HWND hwnd) {m_hHwnd=hwnd;};
void SetTitre(LPTSTR szTitre) {
if((lstrlen(szTitre)>0)&&(lstrlen(szTitre)<31)){
lstrcpy(m_szTitre,szTitre);}};
void SetIcon(WORD wIcon) {m_wIcon=wIcon;};
void SetSmallIcon(WORD wSmallIcon) {m_wSmallIcon=wSmallIcon;};
void SetLongueur(int iLongueur) {m_iLongueur=iLongueur;};
void SetLargeur(int iLargeur) {m_iLargeur=iLargeur;};
void SetDelai(int iDelai) {m_iDelai=iDelai;};
void SetNombreAction(int iNombre) {m_iDelai=1000/iNombre;};
void SetLongueurEcriture(int iLongueur){m_iLongueur=iLongueur+
(GetSystemMetrics(SM_CYFIXEDFRAME)*2);};
void SetLargeurEcriture(int iLargeur) {m_iLargeur=iLargeur+
(GetSystemMetrics(SM_CYFIXEDFRAME) * 2 +
GetSystemMetrics(SM_CYCAPTION));};

};

#endif


main.cpp:

#include <windows.h>
using namespace std;

#include "MoteurCentral.h"


LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}

Et voici le message d'erreur que j'ai:

4 C:\BASE DE DONNEES\TPE\main.cpp In file included from main.cpp
24 C:\BASE DE DONNEES\TPE\MoteurCentral.h expected `)' before "hInstance"
28 C:\BASE DE DONNEES\TPE\MoteurCentral.h expected class-name before '(' token
13 C:\BASE DE DONNEES\TPE\MoteurCentral.h an anonymous union cannot have function members
66 C:\BASE DE DONNEES\TPE\MoteurCentral.h abstract declarator `' used as declaration
66 C:\BASE DE DONNEES\TPE\MoteurCentral.h namespace-scope anonymous aggregates must be static
C:\BASE DE DONNEES\TPE\Makefile.win [Build Error] [main.o] Error 1

Pouvez-vous me dire quel est la cause responsable de cet échec?

Merci d'avance pour qui compte m'aidera.

NAVI

2 réponses

MrdJack Messages postés 146 Date d'inscription jeudi 22 avril 2004 Statut Membre Dernière intervention 8 mars 2008 2
8 nov. 2005 à 20:04
j'ai beau chercher partout dans le fichier main.cpp mais je ne voit pas
où tu utilise la classe MoteurCentral, il ne suffit pas de déclarer le
include pour que ca marche, il faut créer un objet du type
MoteurCentral comme ceci

MoteurCentral MonMoteurCentral;

et l'utiliser comme ceci :
MonMoteurCentral.GetInstance();

MonMoteurCentral.SetLongueur(123456789);


la premiere erreur dit qu'il y a un probleme dans le fichier MoteurCentral.h.

pour la deuxieme erreur, je ne suis pas sur que l'on puisse passer des parametres à la fonction créatrice de l'objet.



bonnne continuation



@++
0
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
9 nov. 2005 à 00:40
On peut faire un constructeur (même nom) en plusieurs versions (surcharge) avec différents nbr et type de variables, le compilo déterminera lequel appeler selon la signature de la fonction.

ciao...
http://dev.winsysdev.com
BruNews, MVP VC++
0
Rejoignez-nous