IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Logiciel de dessin sans les mfc mais ma fenetre ne reçoit pas les messages WM :cry:


Sujet :

C++

  1. #1
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut Logiciel de dessin sans les mfc mais ma fenetre ne reçoit pas les messages WM :cry:
    Bonjour,

    comme je l'ai précisé dans le titre, je souhaite réaliser une application de dessin, un SKETCHER avec les MFCs, je l'ai réalisé grace à un bouquain, le mien, je le nomme Drawer.

    J'ai trouvé sur le net, une (autre) application structuré comme les mfc, sans les mfc(ce que je souhaitai!) mais qui ne possede pas d'objet Application..


    Dans mon application, j'ai un objet Programme contenant le hinstance, un objet TMainFrame contenant l'objets Drawer (qui est sensé être l'objet doc et view mais pour le moment je simplifie) dans lequel je souhaite dessiner et normalement les objet de barre d'outil...


    Mes soucis:
    - les messages n'arrivent pas jusqu'à la fenetre de dessin comme dans le logiciel paint.
    - si je force l'envoie de message de TMainFrame, mon application bug un peu...

    Je pense avoir besoin d'une brillante explication, d'une lumière, d'un petit cour

    merci de vous attardez sur ma demande

    je vous joins mes sources.

  2. #2
    Rédacteur
    Avatar de 3DArchi
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    7 634
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 7 634
    Points : 13 017
    Points
    13 017
    Par défaut
    Salut,
    Peux-tu détailler ton problème ? Car là, c'est un peu brut de fonderie.

  3. #3
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut
    j'ai un fichier Window.h de la GNU qui m'offre quelque fonctionnalité de base pour mes controles..
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
     
    #ifndef WINDOW_CONTROL_H
    #define WINDOW_CONTROL_H
     
    class Window
    {
    public:
    	Window(){}
    	virtual ~Window() {};
    	virtual void init(HWND hSelf, HWND parent){_hSelf= hSelf;_hParent=parent;}
    	virtual void destroy() = 0;
    	virtual void display(bool toShow = true) const {::ShowWindow(_hSelf, toShow?SW_SHOW:SW_HIDE);};
    	virtual void reSizeTo(RECT & rc) // should NEVER be const !!!
    	{ 	::MoveWindow(_hSelf, rc.left, rc.top, rc.right, rc.bottom, TRUE);
    		redraw();
    	};
     
    	virtual void reSizeToWH(RECT & rc) // should NEVER be const !!!
    	{ 	::MoveWindow(_hSelf, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
    		redraw();
    	};
     
    	virtual void redraw(bool forceUpdate = false) const
    	{	::InvalidateRect(_hSelf, NULL, TRUE);
    		if (forceUpdate)	::UpdateWindow(_hSelf);
    	};
     
        virtual void getClientRect(RECT & rc)		const	{	::GetClientRect		(_hSelf, &rc);	};
    	virtual void getWindowRect(RECT & rc)		const	{	::GetWindowRect	(_hSelf, &rc);	};
    	virtual int getWidth()	const {	RECT rc;	GetClientRect(_hSelf, &rc);	return (rc.right - rc.left);	};
    	virtual int getHeight() const {	RECT rc;	GetClientRect(_hSelf, &rc);
    	if (::IsWindowVisible(_hSelf) == TRUE)	return (rc.bottom - rc.top);	return 0;	};
     
    	virtual bool isVisible	()	const	{ 	return (::IsWindowVisible(_hSelf)?true:false);	};
    	inline HWND getHSelf	()	const	{	return _hSelf;	};	//assert(_hSelf);
    	inline HWND getHParent	()	const	{	return _hParent;};
    	void getFocus() const {		::SetFocus(_hSelf);	};
    protected:
     
    	HWND _hParent;
    	HWND _hSelf;
    };
     
    #endif //WINDOW_CONTROL_H
    une class programme permettant le démarrage de mon programme...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    #ifndef PROGRAMME_H
    #define PROGRAMME_H
    class TMainFrame;
    class Programme
    {
    public:
     
    	~Programme(){}
    	Programme();
    	WPARAM Run();
    	BOOL Init(HINSTANCE hInst,int nCmdShow);
    	void SetCmdShow(int nCmdShow){_nCmdShow=nCmdShow;};
    	inline HINSTANCE GetHInst() const {return _hInst;};
    	inline TMainFrame* GetMainFrame(){return _pMainFrame;}
    	inline TCHAR* GetAppTitle(){return _szTitle;}
    private:
    	TMainFrame* _pMainFrame;
    	int _nCmdShow;
    	HINSTANCE _hInst;
    	HINSTANCE _hPrevInst;
    	LPSTR _lpCmdLine;
    	TCHAR _szTitle[MAX_LOADSTRING];
    	TCHAR _szWindowClass[MAX_LOADSTRING];
    	HACCEL _hAccelTable;
     
    };
    #endif
    et son fichier cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
     
     
    #include "stdafx.h"
     
    Programme::Programme()
    {
    	this->_hInst=NULL;
    	this->_hAccelTable=NULL;
    	this->_hPrevInst=NULL;
    	this->_lpCmdLine=NULL;
    	this->_pMainFrame=NULL;
    	this->_nCmdShow=NULL;
    	LoadString(_hInst, IDS_APP_TITLE, _szTitle, MAX_LOADSTRING);
    	LoadString(_hInst, IDS_DRAWER, _szWindowClass, MAX_LOADSTRING);
     
    }
    BOOL Programme::Init(HINSTANCE hInst,int nCmdShow)
    {
    	_hInst = hInst;
    	if (!_hInst){::MessageBox(NULL, TEXT("_hInst == NULL"), TEXT("class Window"), MB_OK);throw int(1999);}
     
    	this->_pMainFrame = new TMainFrame();	// création fenêtre principale
    	if(!this->_pMainFrame->Create(this))
    		return FALSE;
    	ShowWindow(this->_pMainFrame->getHSelf(), nCmdShow);
    	UpdateWindow(this->_pMainFrame->getHSelf());
    	return TRUE;	// initialisation réussie
    }
     
     
    WPARAM Programme::Run()
    {	
    	MSG _msg;
    	_hAccelTable = LoadAccelerators(_hInst, MAKEINTRESOURCE(IDR_DRAWER));
     
    	while (GetMessage(&_msg, NULL, 0, 0))	// Boucle de messages principale*:
    	{
    		if (!TranslateAccelerator(_msg.hwnd, _hAccelTable, &_msg))
    		{
    			TranslateMessage(&_msg);
    			DispatchMessage(&_msg);
    		}
    	}
    	return (int) _msg.wParam;
    }
    la classe TMAINFRAME
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
     
    #ifndef MAINFRAME_H_INCLUDED
    #define MAINFRAME_H_INCLUDED
    class Drawer;
    class TMainFrame:public Window
    {
     
    protected :
     
    	Programme* _pApp;
    	Drawer* _pDrawer;
    	void destroy(){}
    public :
    	// constructeur, destructeur
    	TMainFrame();
    	~TMainFrame();
     
    	BOOL Create(Programme*);
    	inline Drawer*		GetDrawer()		{	return _pDrawer	;}
    	inline Programme*	GetProgramme()	{	return _pApp	;}
     
    protected :
    	static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    	LRESULT MsgCreate	(HWND, WPARAM, LPARAM);	// WM_CREATE
    	LRESULT MsgClose	(WPARAM, LPARAM);		// WM_CLOSE
    	LRESULT MsgDestroy	(WPARAM, LPARAM);		// WM_DESTROY
    	LRESULT MsgSetFocus	(WPARAM, LPARAM);		// WM_SETFOCUS
    	LRESULT MsgCommand	(WPARAM, LPARAM);		// WM_COMMAND
    	void CmdFileQuit		();		// "Fichier->Quitter"
    };
    #endif	// MAINFRAME_H_INCLUDED
    son fichier cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    #include "stdafx.h"
     
    TMainFrame::TMainFrame()
    {
    	_hSelf			= NULL;
    	this->_hParent	= NULL;
    	this->_pApp		= NULL;
    	this->_pDrawer	= new Drawer();
    }
     
    TMainFrame::~TMainFrame(){	delete _pDrawer;}
     
    BOOL TMainFrame::Create(Programme* aApp)
    {
    	this->_pApp = aApp;
    	// classe de fenêtre
    	TCHAR szWndClass[] = _T("Drawer_MainFrame");
     
    	// initialisation classe de fenêtre
    	WNDCLASS wc;
     
    	ZeroMemory(&wc, sizeof(WNDCLASS));
    	wc.style			= CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc		= WndProc;
    	wc.hInstance		= this->_pApp->GetHInst();
    	wc.hIcon			= LoadIcon(this->_pApp->GetHInst(), MAKEINTRESOURCE(IDI_DRAWER));
    	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
    	wc.lpszMenuName		= MAKEINTRESOURCE(IDR_DRAWER);
    	wc.lpszClassName	= szWndClass;
    	wc.hbrBackground = NULL;
    	// enregistrement classe de fenêtre
    	if(!RegisterClass(&wc))
    		return FALSE;
     
    	// création fenêtre principale
    	this->_hSelf = CreateWindowEx(0, szWndClass, this->_pApp->GetAppTitle(), WS_OVERLAPPEDWINDOW,
    							CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
    							NULL, NULL, this->_pApp->GetHInst(), this);
     
    	return (_hSelf != NULL);
    }
     
    LRESULT CALLBACK TMainFrame::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	// affecter l'objet TMainFrame lors de la création de la fenêtre, contenu dans la 
    	// structure CREATESTRUCT pointée par lParam
    	if(msg == WM_CREATE)
    	{
    		LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
    		SetWindowLong(hWnd, GWL_USERDATA, (LONG)lpcs->lpCreateParams);
    	}
     
    	// récupération objet TMainFrame associé à la fenêtre
    	TMainFrame* pWnd = (TMainFrame*) GetWindowLong(hWnd, GWL_USERDATA);
    	if(!pWnd)
    		return DefWindowProc(hWnd, msg, wParam, lParam);
    	switch(msg)
    	{
    		case WM_SETFOCUS	: return pWnd->MsgSetFocus	(wParam, lParam);
    		case WM_CREATE		: return pWnd->MsgCreate	(hWnd, wParam, lParam);
    		case WM_CLOSE		: return pWnd->MsgClose		(wParam, lParam);
    		case WM_DESTROY		: return pWnd->MsgDestroy	(wParam, lParam);
    		case WM_COMMAND		: return pWnd->MsgCommand	(wParam, lParam);
    		default				: return DefWindowProc(hWnd, msg, wParam, lParam);
    	}
     
     
    }
    LRESULT TMainFrame::MsgCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
    {	this->_hSelf=hWnd;
    	this->_pDrawer->Create(this);
     
    	ShowWindow(this->_pDrawer->getHSelf(), SW_SHOW);
    	return 0;
    }
     
    LRESULT TMainFrame::MsgClose(WPARAM wParam, LPARAM lParam)
    {
    	DestroyWindow(_hSelf);
    	return 0;
    }
    LRESULT TMainFrame::MsgSetFocus(WPARAM wParam, LPARAM lParam)
    {	this->_pDrawer->getFocus();
     
    	return 0;
    }
     
    LRESULT TMainFrame::MsgDestroy(WPARAM wParam, LPARAM lParam)
    {
    	PostQuitMessage(0);
    	return 0;
    }
     
     
    LRESULT TMainFrame::MsgCommand(WPARAM wParam, LPARAM lParam)
    {
    	// on laisse la vue de la zone cliente commencer par traiter la commande
    	if(SendMessage(this->_pDrawer->getHSelf(), WM_COMMAND, wParam, lParam))
    		return TRUE;
     
    	int nIDCtl = LOWORD(wParam);	// en fonction de la commande
    	switch(nIDCtl)
    	{
    		case IDM_EXIT					: CmdFileQuit		();			break;
    		default : return FALSE;
    	}
    	return TRUE;// la commande a été traitée
    }
    void TMainFrame::CmdFileQuit(){	SendMessage(_hSelf, WM_CLOSE, 0, 0);}
    et enfin ma class drawer me servant pour le moment de document et de vue:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    #ifndef DRAWER_H
    #define DRAWER_H
    class CElement;
     
    class Drawer:public Window
    {
    protected :
    	TMainFrame* _pTMainFrame;
     
    public :
    	Drawer(){}
    	~Drawer(){}
    	BOOL Create(TMainFrame* pMainFrame);
    protected :
    	static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
     
    	LRESULT MsgMouseMove	(WPARAM, LPARAM);	// WM_MOUSEMOVE
    	void destroy(){}
    protected:
    };
    #endif
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
     
    // Drawer.cpp*: définit le point d'entrée pour l'application.
    //
     
    #include "stdafx.h"
     
     
    BOOL Drawer::Create(TMainFrame* pMainFrame)
    {
    	// classe de fenêtre
    	TCHAR szWndClass[]	= _T("Paint_ChildView");
     
    	// initialisation classe de fenêtre
    	WNDCLASS wc;
    	ZeroMemory(&wc, sizeof(WNDCLASS));
    	wc.style			= CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc		= WndProc;
    	wc.hInstance		= pMainFrame->GetProgramme()->GetHInst();
    	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
    	wc.lpszClassName	= szWndClass;
     
    	// enregistrement classe de fenêtre
    	if(!RegisterClass(&wc))
    		return FALSE;
    	this->_hParent = pMainFrame->getHSelf();
     
    	_hSelf = CreateWindowEx(0, szWndClass, NULL, WS_CHILD,
    							0, 0, 0, 0, pMainFrame->getHSelf(), NULL, pMainFrame->GetProgramme()->GetHInst(), this);
     
    	return (_hSelf != NULL);
    }
     
    LRESULT CALLBACK Drawer::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	// affecter l'objet Drawer lors de la création de la vue, contenu dans la 
    	// structure CREATESTRUCT pointée par lParam
    	if(msg == WM_CREATE)
    	{
    		LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
    		SetWindowLong(hWnd, GWL_USERDATA, (LONG)lpcs->lpCreateParams);
    	}
     
    	// récupération objet Drawer associé à la fenêtre
    	Drawer* pWnd = (Drawer*) GetWindowLong(hWnd, GWL_USERDATA);
    	if(!pWnd)
    		return DefWindowProc(hWnd, msg, wParam, lParam);
     
    	// en fonction du message
    	switch(msg)
    	{
    		case WM_MOUSEMOVE	: return pWnd->MsgMouseMove		(wParam, lParam);
    		default : return FALSE;
    	}
    }
     
     
    LRESULT Drawer::MsgMouseMove	(WPARAM wParam, LPARAM lParam)
    {
    	POINT point;
    	PAINTSTRUCT ps;
    	HDC hdc= BeginPaint(_hSelf,&ps);
    	TCHAR bf2[5];
    	TCHAR bf1[5];
    	GetCursorPos(&point);
    	ScreenToClient(_hSelf,&point);
    	_itow_s(point.x,bf1,5,10);
    	_itow_s(point.y,bf2,5,10);
    	TCHAR aText[MAX_LOADSTRING] =TEXT("Coordonnée cliente :");
    	wcscat(aText,bf1);
    	wcscat(aText,TEXT(","));
    	wcscat(aText,bf2);
    	SetWindowText(this->getHParent(),aText);
    	MoveToEx(hdc,0,0,NULL);
    	LineTo(hdc,point.x,point.y);
    	EndPaint(this->getHSelf(), &ps);
    	return 0;
     
    }
     
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
    	UNREFERENCED_PARAMETER(hPrevInstance);
    	UNREFERENCED_PARAMETER(lpCmdLine);
    	Programme Apps;
    	if(Apps.Init(hInstance,nCmdShow))
    		return Apps.Run();
    	else return 0;
     
     }
    J'ai simplifié au maximum, les messages ne transite pas par mon drawer alors que je sais que c'est possible... mais c'est certain qu'il me manque quelque chose...

  4. #4
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Déjà, je pense que WndProc ne devrait pas être dans Drawer, mais dans Window, et appeler une fonction virtuelle quand pWnd n'est pas nul.

    Aussi, tu devrais utiliser GetWindowLongPtr().
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  5. #5
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut
    Je souhaite avoir un MainFrame comme dans les MFC et un modèle Vue/Document (que je regroupe) dans mon Drawer, Window sert à stocker le HANDLE de ma fenetre et quelques fonctions utilent pour le developpement de mon application.

    Je n'arrive pas à faire transiter mes messages "naturellement" vers les evenement utilisateur comme l'application paint.

    Si je force à travers le MainFrame, ça bug, je n'ai plus d'accès au menu à part si je clique hors application et que je renvoie le focus. Ce n'est pas terrible.

    Je pense que mes WNDPROCs sont bien placés, je ne suis pas un professionnel, Je comprend vite mais faut m'expliquer longtemps

  6. #6
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Le code simplifié que tu as posté, est-ce celui du Drawer.zip ou est-ce celui du Paint.zip?
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  7. #7
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut
    Celui de drawer, j'ai regardé la fonction que tu me conseil pour récuperer le pointeur, elles sont pareil à une exception près, la Ptr fonctionne aussi en mot de 64bits

  8. #8
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Mais dans tous les cas, ça ne devrait pas être la source du bug.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  9. #9
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut mwé
    J'ai modifié dans le create de ma fenetre "fille", cad Drawer, les coordonnées de création de fenetre dans CreateWindowEx
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    _hSelf = CreateWindowEx(0, szWndClass, NULL, WS_CHILD|WS_VISIBLE,
    							0, 0,500, 500, pMainFrame->getHSelf(), NULL, pMainFrame->GetProgramme()->GetHInst(), this);

    j'ai modifié le run() pour tester un peu les message
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    WPARAM Programme::Run()
    {	RECT aRect,bRect;
    	MSG _msg;
    	_hAccelTable = LoadAccelerators(_hInst, MAKEINTRESOURCE(IDR_DRAWER));
    	static int Counter =0;
    	static int Count2 =0;
    	while (GetMessage(&_msg, NULL, 0, 0))	// Boucle de messages principale*:
    	{
    		if (!TranslateAccelerator(_msg.hwnd, _hAccelTable, &_msg))
    		//if (!TranslateAccelerator(NULL, _hAccelTable, &_msg))
    		{	
    			this->_pMainFrame->getWindowRect(aRect);
    			this->_pMainFrame->GetDrawer()->getWindowRect(bRect);
     
    			if(_msg.hwnd == this->GetMainFrame()->GetDrawer()->getHSelf())
    			{	Counter++;
    				if((this->GetMainFrame()->GetDrawer()->getHSelf()!=NULL)&&(512==0x200))
    					MessageBox(this->GetMainFrame()->getHSelf(),TEXT("ça marche!"),TEXT("Ok"),MB_OK);
    				if (_msg.message==512) Count2 ++;
    			}
    			TranslateMessage(&_msg);
    			DispatchMessage(&_msg);
    		}
    	}
    	return (int) _msg.wParam;
    }
    J'imagine que les coordonnées sont données par rapport à l'écran. Ce qui me surprend, c'est que ma MessageBox n'apparait pas..

  10. #10
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut J'ai tout réduit au minimum
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
     
    // Fichier d'entête
    class Drawer;
    class TMainFrame;
    class Programme
    {
    public:
    	~Programme(){}
    	Programme();
    	WPARAM Run();
    	BOOL Init(HINSTANCE hInst,int nCmdShow);
    	inline HINSTANCE GetHInst() const {return _hInst;};
    	inline TMainFrame* GetMainFrame(){return _pMainFrame;}
    	inline TCHAR* GetAppTitle(){return _szTitle;}
    	inline TCHAR* GetWndClass(){return _szWindowClass;}
     
    private:
    	TMainFrame* _pMainFrame;
    	HINSTANCE _hInst;
    	TCHAR _szTitle[MAX_LOADSTRING];
    	TCHAR _szWindowClass[MAX_LOADSTRING];
    };
    class TMainFrame:public Window
    {
    protected :
    	Programme* _pApp;
    	Drawer* _pDrawer;
    	void destroy(){	DestroyWindow(_hSelf);}
    public :
    	// constructeur, destructeur
    	TMainFrame();
    	~TMainFrame(){	delete _pDrawer;}
    	BOOL Create(Programme*);
    	inline Drawer*		GetDrawer()		{	if(_pDrawer)return _pDrawer	;else return NULL;}
    	inline Programme*	GetProgramme()	{	return _pApp	;}
    protected :
    	static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    	LRESULT MsgCreate	(HWND, WPARAM, LPARAM);	// WM_CREATE
    	LRESULT MsgClose	(WPARAM, LPARAM);		// WM_CLOSE
    	LRESULT MsgDestroy	(WPARAM, LPARAM);		// WM_DESTROY
    	LRESULT MsgCommand	(WPARAM, LPARAM);		// WM_COMMAND
    	void CmdFileQuit		();		// "Fichier->Quitter"
    private:
    };
    class Drawer:public Window
    {
    public :
    	Drawer(){}
    	~Drawer(){}
    	BOOL Create(TMainFrame* pMainFrame);
    protected :
    	TMainFrame* _pTMainFrame;
    	WNDPROC OldWndProc;
    	static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    	LRESULT MsgMouseMove	(WPARAM, LPARAM);	// WM_MOUSEMOVE
    	LRESULT MsgCreate	(WPARAM, LPARAM);	// WM_MOUSEMOVE
    	void destroy(){}
    };
    le corps
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
     
    #include "stdafx.h"
     
    TMainFrame::TMainFrame()
    {	_hSelf			= NULL;
    	this->_hParent	= NULL;
    	this->_pApp		= NULL;
    	this->_pDrawer	= new Drawer();
    }
    BOOL TMainFrame::Create(Programme* aApp)
    {
    	this->_pApp = aApp;
    	// classe de fenêtre
    	TCHAR szWndClass[] = _T("Drawer_MainFrame");
    	// initialisation classe de fenêtre
    	WNDCLASS wc;
     
    	ZeroMemory(&wc, sizeof(WNDCLASS));
    	wc.style			= CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc		= WndProc;
    	wc.hInstance		= this->_pApp->GetHInst();
    	wc.hIcon			= LoadIcon(this->_pApp->GetHInst(), MAKEINTRESOURCE(IDI_DRAWER));
    	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);
    	wc.lpszMenuName		= MAKEINTRESOURCE(IDR_DRAWER);
    	wc.lpszClassName	= szWndClass;
    	wc.hbrBackground = NULL;
    	// enregistrement classe de fenêtre
    	if(!RegisterClass(&wc))
    		return FALSE;
     
    	// création fenêtre principale
    	this->_hSelf = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, szWndClass, this->_pApp->GetAppTitle(), WS_OVERLAPPEDWINDOW,
    							CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
    							NULL, NULL, this->_pApp->GetHInst(), this);
     
    	if(this->GetDrawer()->Create(this))
    		this->GetDrawer()->display();
    	return (_hSelf != NULL);
    }
     
    LRESULT CALLBACK TMainFrame::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	// affecter l'objet TMainFrame lors de la création de la fenêtre, contenu dans la 
    	// structure CREATESTRUCT pointée par lParam
    	if(msg == WM_CREATE)
    	{
    		LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
    		SetWindowLong(hWnd, GWL_USERDATA, (LONG)lpcs->lpCreateParams);
    	}
     
    	// récupération objet TMainFrame associé à la fenêtre
    	TMainFrame* pWnd = (TMainFrame*) GetWindowLong(hWnd, GWL_USERDATA);
    	if(!pWnd)
    		return DefWindowProc(hWnd, msg, wParam, lParam);
     
    	switch(msg)
    	{
    		case WM_CREATE		: return pWnd->MsgCreate	(hWnd, wParam, lParam);
    		case WM_CLOSE		: return pWnd->MsgClose		(wParam, lParam);
    		case WM_DESTROY		: return pWnd->MsgDestroy	(wParam, lParam);
    		case WM_COMMAND		: return pWnd->MsgCommand	(wParam, lParam);
    		default				: return DefWindowProc(hWnd, msg, wParam, lParam);
    	}
    }
    LRESULT TMainFrame::MsgCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)	{	this->_hSelf=hWnd;	return 0;}
    LRESULT TMainFrame::MsgClose(WPARAM wParam, LPARAM lParam)				{	this->destroy();	return 0;}
    LRESULT TMainFrame::MsgDestroy(WPARAM wParam, LPARAM lParam)			{	PostQuitMessage(0);	return 0;}
     
     
    LRESULT TMainFrame::MsgCommand(WPARAM wParam, LPARAM lParam)
    {
    	// on laisse la vue de la zone cliente commencer par traiter la commande
    	/*if(SendMessage(this->_pDrawer->getHSelf(), WM_COMMAND, wParam, lParam))
    		return TRUE;
    */
    	int nIDCtl = LOWORD(wParam);	// en fonction de la commande
    	switch(nIDCtl)
    	{	case IDM_FILE_NEW				:MessageBox(this->getHSelf(),TEXT("ça marche!"),TEXT("Ok"),MB_OK);break;
    		case IDM_EXIT					: CmdFileQuit();			break;
    		default : return FALSE;
    	}
    	return TRUE;// la commande a été traitée
    }
    void TMainFrame::CmdFileQuit()	{	SendMessage(_hSelf, WM_CLOSE, 0, 0);}
    Programme::Programme()
    {	this->_hInst=NULL;
    	this->_pMainFrame=NULL;
    	LoadString(_hInst, IDS_APP_TITLE, _szTitle, MAX_LOADSTRING);
    	LoadString(_hInst, IDS_DRAWER, _szWindowClass, MAX_LOADSTRING);
    }
    BOOL Programme::Init(HINSTANCE hInst,int nCmdShow)
    {
    	_hInst = hInst;
    	if (!_hInst){::MessageBox(NULL, TEXT("_hInst == NULL"), TEXT("class Window"), MB_OK);throw int(1999);}
     
    	this->_pMainFrame = new TMainFrame();	// création fenêtre principale
    	if(!this->_pMainFrame->Create(this))
    		return FALSE;
     
    	ShowWindow(this->_pMainFrame->getHSelf(), nCmdShow);
    	UpdateWindow(this->_pMainFrame->getHSelf());
    	return TRUE;	// initialisation réussie
    }
     
     
    WPARAM Programme::Run()
    {	MSG _msg;
    	while (GetMessage(&_msg, NULL, 0, 0))	// Boucle de messages principale*:
    	{
    		TranslateMessage(&_msg);
    		DispatchMessage(&_msg);
    	}
    	return (int) _msg.wParam;
    }
     
    BOOL Drawer::Create(TMainFrame* pMainFrame)
    {
     
    TCHAR szWndClass[]	= TEXT("Paint_ChildView");
    WNDCLASSEX wc;
    wc.hInstance	= pMainFrame->GetProgramme()->GetHInst();
    wc.lpszClassName= szWndClass;
    //OldWndProc		= wc.lpfnWndProc;
    wc.lpfnWndProc	= this->WndProc;
    wc.hbrBackground = NULL;
     
    wc.style = CS_DBLCLKS;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszMenuName = NULL;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
     
     
    if ( !RegisterClassEx( &wc ) )MessageBox (NULL, TEXT("Registering Error"), TEXT("Information"), MB_OK |MB_ICONSTOP);
     
    	this->_hParent = pMainFrame->getHSelf();
     
    	_hSelf = CreateWindowEx(0, szWndClass, NULL, WS_CHILD|WS_VISIBLE,0, 0,500, 500, pMainFrame->getHSelf(), NULL, pMainFrame->GetProgramme()->GetHInst(), this);
    	return (_hSelf != NULL);
    }
     
    LRESULT CALLBACK Drawer::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	// affecter l'objet Drawer lors de la création de la vue, contenu dans la 
    	// structure CREATESTRUCT pointée par lParam
    	if(msg == WM_CREATE)
    	{
    		LPCREATESTRUCT lpcs = (LPCREATESTRUCT) lParam;
    		SetWindowLong(hWnd, GWL_USERDATA, (LONG)lpcs->lpCreateParams);
    	}
     
    	// récupération objet Drawer associé à la fenêtre
    	Drawer* pWnd = (Drawer*) GetWindowLong(hWnd, GWL_USERDATA);
    	if(!pWnd)
    		return DefWindowProc(hWnd, msg, wParam, lParam);
     
    	// en fonction du message
    	switch(msg)
    	{
    		case WM_MOUSEMOVE	: return pWnd->MsgMouseMove		(wParam, lParam);
    		case WM_CREATE		: return pWnd->MsgCreate		(wParam, lParam);
    		//case WM_LBUTTONDOWN:case WM_RBUTTONDOWN:break;
    		default : return FALSE;
    	}
    }
     
    LRESULT Drawer::MsgCreate(WPARAM wParam, LPARAM lParam)
    {
     
    	return FALSE;
    }
     
    LRESULT Drawer::MsgMouseMove	(WPARAM wParam, LPARAM lParam)
    {
    	POINT point;
    	PAINTSTRUCT ps;
    	HDC hdc= BeginPaint(_hSelf,&ps);
    	TCHAR bf2[5];
    	TCHAR bf1[5];
    	GetCursorPos(&point);
    	ScreenToClient(_hSelf,&point);
    	_itow_s(point.x,bf1,5,10);
    	_itow_s(point.y,bf2,5,10);
    	TCHAR aText[MAX_LOADSTRING] =TEXT("Coordonnée cliente :");wcscat(aText,bf1);wcscat(aText,TEXT(","));wcscat(aText,bf2);
    	SetWindowText(this->getHParent(),aText);
    	MoveToEx(hdc,0,0,NULL);
    	LineTo(hdc,point.x,point.y);
    	EndPaint(this->getHSelf(), &ps);
    	return 0;
     
    }
     
    int APIENTRY _tWinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPTSTR    lpCmdLine,
                         int       nCmdShow)
    {
    	UNREFERENCED_PARAMETER(hPrevInstance);
    	UNREFERENCED_PARAMETER(lpCmdLine);
    	Programme Apps;
    	if(Apps.Init(hInstance,nCmdShow))
    		return Apps.Run();
    	else return 0;
     
     }
    J'ai mis la création de ma boite sur Fichier->Nouveau...
    Ce qui me surprend, c'est que ma boite n'apparait pas sauf quand j'appuie sur la touche ALT

  11. #11
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut
    Après deux jour de galère, j'ai trouvé! lol


    je ne renvoyai pas les messages de Drawer vers Windows... lol

  12. #12
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Pour éviter ce genre de problèmes, voici ce que moi je conseille (en pseudo-C++):
    Code C++ : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    class Window
    {
    	static LRESULT CALLBACK SWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    	{
    		if(message==WM_NCCREATE)
    			SetWindowLongPtr(lparam->lpCreateParams);
     
    		if((pThis = GetWindowLongPtr())!=NULL)
    			return pThis->VWindowProc(message, wParam, lParam);
    		else
    			return DefWindowProc(hWnd, message, wParam, lParam);
    	}
     
    	virtual LRESULT VWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    	{
    		LRESULT ret = 0;
    		switch(message)
    		{
    		case ...:
    			...
    			break;
     
    		...
     
    		default:
    			ret = DefWindowProc(hWnd, message, wParam, lParam);
    			break;
    		}
    		return ret;
    	}
    };
     
    class Drawer : public Window
    {
    	typedef Window Super;
     
    	virtual LRESULT VWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    	{
    		LRESULT ret = 0;
    		switch(message)
    		{
    		case ...:
    			...
    			break;
     
    		...
     
    		default:
    			ret = Super::VWindowProc(message, wParam, lParam);
    			break;
    		}
    		return ret;
    	}
    };
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  13. #13
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut
    merci pour ton attention Médinoc, c'est super sympas.

  14. #14
    Membre régulier
    Inscrit en
    Septembre 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Septembre 2009
    Messages : 87
    Points : 77
    Points
    77
    Par défaut
    Medinoc, s'il te plaît:


    Je souhaiterai savoir la différence entre le c et c++,j'ai l'impression de faire du c+,

    soit, j'ai un plus de trop ou il m'en manque un...

  15. #15
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 518
    Points
    41 518
    Par défaut
    Avec mon exemple, c'est clairement du C++ qu'on fait: Héritage de classes, fonctions membres virtuelles...

    Pour ton code, c'est déjà vachement plus proche du "vrai C++ objet" que beaucoup de codes "C++" que j'ai vus...
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] SNMP & Proxy pas les utiliser mais leurs paramètres
    Par Speed41 dans le forum C#
    Réponses: 1
    Dernier message: 26/05/2014, 09h15
  2. [MySQL] Mon client ne reçoit pas les courriels envoyés par mon formulaire (mais moi oui)
    Par carogilb19 dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 16/08/2012, 19h09
  3. Réponses: 1
    Dernier message: 11/09/2007, 17h06
  4. Réponses: 10
    Dernier message: 01/09/2007, 16h12
  5. [Requete] qui n'affiche pas les doublons mais sur un seul champs
    Par joseph.breham dans le forum Requêtes et SQL.
    Réponses: 2
    Dernier message: 19/12/2006, 14h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo