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

Windows Discussion :

Problème affichage d'une fenetre dans une fenetre


Sujet :

Windows

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut Problème affichage d'une fenetre dans une fenetre
    Bonjour !

    J'ai un programme très simple dont le principe est :
    - Créer une simple fenêtre Windows.
    - Ajouter une autre fenêtre dans cette fenetre (child).

    Mon soucis est que je ne vois pas du tout la fenêtre interne?
    Au début, j'avais mis la même classe wc.lpszClassName = "WindowClass1"; pour les deux WNDCLASSEX. J'avais alors juste une bordure (une ligne) noir qui s'affichait. Mais là, je n'ai rien du tout.

    En plus, ce que je voudrais, c'est que la fenêtre interne ait aussi un titre et la petite croix pour la fermer...

    Ci joint mon bout de code, pour mieux comprendre...!?

    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
    // the entry point for any Windows program
    int WINAPI MyCreateWindow(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow, int nbChild)
    {
        // the handle for the window, filled by a function
        HWND hWnd;
        // this struct holds information for the window class
        WNDCLASSEX wc;
    
        // clear out the window class for use
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
    
    	// fill in the struct with the needed information
    
    	// Main Window
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = (WNDPROC)WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wc.lpszClassName = "WindowClass1";
    
    	// register the window class
        RegisterClassEx(&wc);
    
    	// this struct holds information for the window class
        WNDCLASSEX wc2;
    
    	// clear out the window class for use
        ZeroMemory(&wc2, sizeof(WNDCLASSEX));
    
    	// Child Window
    	wc2.cbSize = sizeof(WNDCLASSEX);
        wc2.style = CS_HREDRAW | CS_VREDRAW;
        wc2.lpfnWndProc = (WNDPROC)WindowProcChild;
        wc2.hInstance = hInstance;
        wc2.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc2.hbrBackground = (HBRUSH)COLOR_WINDOW;
        wc2.lpszClassName = "WindowClass2";
        
    
        // create the window and use the result as the handle
        hWnd = CreateWindowEx(NULL,
                              "WindowClass1",    // name of the window class
                              "Our First Windowed Program",   // title of the window
                              WS_OVERLAPPEDWINDOW,    // window style
                              300,    // x-position of the window
                              300,    // y-position of the window
                              WIN_W,    // width of the window
                              WIN_H,    // height of the window
                              NULL,    // we have no parent window, NULL
                              NULL,    // we aren't using menus, NULL
                              hInstance,    // application handle
                              NULL);    // used with multiple windows, NULL
    
    	int maxCol = WIN_W / WIN_W_CHILD;
    	int nbCol = 0;
    	int nbRow = 0;
    	for (int i = 0; i < nbChild; i++) {
    		int posX = nbCol * WIN_W_CHILD;
    		int posY = nbRow * WIN_H_CHILD;
    		HWND child = CreateWindowEx(NULL,
    			"WindowClass2",    // name of the window class
    			"Our Second Windowed Program" ,   // title of the window
    			WS_CHILD | WS_CLIPCHILDREN | WS_BORDER,    // window style
    			posX,    // x-position of the window
    			posY,    // y-position of the window
    			WIN_W_CHILD,    // width of the window
    			WIN_H_CHILD,    // height of the window
    			hWnd,    // we have no parent window, NULL
    			NULL,    // we aren't using menus, NULL
    			hInstance,    // application handle
    			NULL);    // used with multiple windows, NULL
    
    		// display the window on the screen
    		ShowWindow(child, nCmdShow);
    
    		if (nbCol == maxCol) {
    			nbCol = 0;
    			nbRow++;
    		}
    	}
        
        ShowWindow(hWnd, nCmdShow);

  2. #2
    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 519
    Points
    41 519
    Par défaut
    nCmdShow, c'est supposé être uniquement pour la fenêtre principale, pas les fenêtres filles.
    Essaie en rajoutant directement le style WS_VISIBLE à la fenêtre fille.

    Et aussi, tu peux regarder avec spy++ si les fenêtres sont bien crées, etc.
    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.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut
    J'ai remplacé WS_VISIBLE comme tu me l'as conseillé, mais cela ne change rien...
    En fait, quand je précise que les deux fenetres ont la meme classe WindowClass1, je vois apparaitre la bordure (un trait noir) de ma fenêtre interne. Mais c'est tout... Mais la avec les classes différentes (puisque c'est ce que je veux), ça ne marche toujours pas...

  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 519
    Points
    41 519
    Par défaut
    • Vérifie les retours d'erreurs: GetLastError(), FormatMessage() et Cie.
    • Il faut ajouter un +1 au nom de la couleur pour le HBRUSH.
    • Tu bosses en C++, un bon programmeur ne met pas de cast C-Style en C++. Remplace ce (HBRUSH) par un reinterpret_cast<HBRUSH>()...
    • Si tu dois caster ta WNDPROC, c'est qu'elle est mal déclarée. Corrige le prototype de la fonction et supprime cet hideux cast.
    • Corrige ton commentaire "we have no parent window, NULL" pour la fenêtre fille : Le commentaire est faux, voilà ce que c'est le copier-coller...
    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
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut
    J'ai l'impression que lorsque je ferme ma fenêtre, j'aperçois brièvement une autre fenêtre, mais j'en suis pas sure.
    Pour les cast, désolée, c'est juste que j'ai pris une base de code provenant des tutorial de DirectX. Et ils ont l'habitude de coder comme cela dans tous leurs examples...

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut
    Je suis entrain de parcourir de document que tu m'as indiqué, mais je ne comprend pas pourquoi il y a un problème avec mon prototype de fonction... ?

    Au fait, tu as raison, j'ai verifié le retour de la fonction
    if (!RegisterClassEx(&wc2)) return 0;
    Et elle n'est pas enregistrée .... Pourquoi?

    Avec GetLastError(), j'obtiens le code 3435973836 ...

  7. #7
    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 519
    Points
    41 519
    Par défaut
    Citation Envoyé par zuzuu Voir le message
    Je suis entrain de parcourir de document que tu m'as indiqué, mais je ne comprend pas pourquoi il y a un problème avec mon prototype de fonction... ?
    Retire le cast en (WNDPROC). Si ça compile toujours, c'est qu'il n'y avait pas de problème. Si ça ne compile plus, c'est que la fonction est mal déclarée (pas le bon type de retour, pas la bonne convention d'appel, etc.).

    Au fait, tu as raison, j'ai verifié le retour de la fonction
    if (!RegisterClassEx(&wc2)) return 0;
    Et elle n'est pas enregistrée .... Pourquoi?

    Avec GetLastError(), j'obtiens le code 3435973836 ...
    C'est vraiment bizarre que tu aies cette valeur avec GetLastError(): 3435973836 correspond à la valeur hexa CCCCCCCC, c'est-à-dire une valeur non-initialisée...
    Pourrais-tu montrer le code ?
    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.

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut
    Oui, voici le code : (Si tu remplaces MyCreateWindows () par WinMain () et que tu enlèves le cinquième élément, normalement, tu peux le lancer à lui tout seul...)
    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
    #include "RenderTest.hpp"
    
    #define WIN_H 600	
    #define WIN_W 600
    
    #define WIN_H_CHILD 50	
    #define WIN_W_CHILD	50
    
    
    
    
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd,
    							UINT message,
    							WPARAM wParam,
    							LPARAM lParam);
    
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProcChild(HWND hWnd,
    								 UINT message,
    								 WPARAM wParam,
    								 LPARAM lParam);
    
    void initClass (WNDCLASSEX & wc, WNDPROC winProc, char * className, HINSTANCE hInstance);
    
    // the entry point for any Windows program
    int WINAPI MyCreateWindow(HINSTANCE hInstance,
    						  HINSTANCE hPrevInstance,
    						  LPSTR lpCmdLine,
    						  int nCmdShow,
    						  int nbChild)
    {
    
    
        // the handle for the window, filled by a function
        HWND hWnd;
        // this struct holds information for the window class
        WNDCLASSEX wc;
    	
        // clear out the window class for use
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
    	initClass(wc, (WNDPROC)WindowProc, "WindowClass1", hInstance);
    	if (!RegisterClassEx(&wc)) return 0;
    	
    	// this struct holds information for the window class
        WNDCLASSEX wc2;
    	
    	// clear out the window class for use
        ZeroMemory(&wc2, sizeof(WNDCLASSEX));
    	initClass(wc2, (WNDPROC)WindowProcChild, "WindowClass1", hInstance);
    	if (!RegisterClassEx(&wc2))
    	{
    		unsigned long tmp = GetLastError();
    		return 0;
    	}
    
    	
        // create the window and use the result as the handle
        hWnd = CreateWindowEx(NULL,
    		"WindowClass1",    // name of the window class
    		"Our First Windowed Program",   // title of the window
    		WS_OVERLAPPEDWINDOW,    // window style
    		300,    // x-position of the window
    		300,    // y-position of the window
    		WIN_W,    // width of the window
    		WIN_H,    // height of the window
    		NULL,    // we have no parent window, NULL
    		NULL,    // we aren't using menus, NULL
    		hInstance,    // application handle
    		NULL);    // used with multiple windows, NULL
    	
    	
    	
    	int maxCol = WIN_W / WIN_W_CHILD;
    	int nbCol = 0;
    	int nbRow = 0;
    	for (int i = 0; i < nbChild; i++) {
    		int posX = nbCol * WIN_W_CHILD;
    		int posY = nbRow * WIN_H_CHILD;
    		HWND child = CreateWindowEx(NULL,
    			"WindowClass2",    // name of the window class
    			"Our Second Windowed Program" ,   // title of the window
    			WS_CHILD |  WS_BORDER |  WS_OVERLAPPED,    // window style // WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,// WS_CLIPCHILDREN
    			posX,    // x-position of the window
    			posY,    // y-position of the window
    			WIN_W_CHILD,    // width of the window
    			WIN_H_CHILD,    // height of the window
    			hWnd,    // we have parent window
    			NULL,    // we aren't using menus, NULL
    			hInstance,    // application handle
    			NULL);    // used with multiple windows, NULL
    		
    		// display the window on the screen
    		ShowWindow(child, WS_VISIBLE);
    		
    		if (nbCol == maxCol) {
    			nbCol = 0;
    			nbRow++;
    		}
    	}
        
    	ShowWindow(hWnd, nCmdShow);
    	
    	
        // enter the main loop:
    	
        // this struct holds Windows event messages
        MSG msg;
    	
        // wait for the next message in the queue, store the result in 'msg'
        // Enter the infinite message loop
    	while(TRUE)
    	{
    		// Check to see if any messages are waiting in the queue
    		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			// If the message is WM_QUIT, exit the while loop
    			if (msg.message == WM_QUIT)
    				break;
    			
    			// Translate the message and dispatch it to WindowProc()
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    		
    		// Run game code here
    		// ...
    		// ...
    	}
        // return this part of the WM_QUIT message to Windows
        return msg.wParam;
    }
    
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        // sort through and find what code to run for the message given
        switch(message)
        {
            // this message is read when the window is closed
    	case WM_DESTROY:
    		{
    			// close the application entirely
    			PostQuitMessage(0);
    			return 0;
    		} break;
        }
    	
        // Handle any messages the switch statement didn't
        return DefWindowProc (hWnd, message, wParam, lParam);
    }
    
    // this is the main message handler for the child program
    LRESULT CALLBACK WindowProcChild(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        // sort through and find what code to run for the message given
        switch(message)
        {
            // this message is read when the window is closed
    	case WM_DESTROY:
    		{
    			// close the application entirely
    			PostQuitMessage(0);
    			return 0;
    		} break;
        }
    	
        // Handle any messages the switch statement didn't
        return DefWindowProc (hWnd, message, wParam, lParam);
    }
    
    void initClass (WNDCLASSEX & wc, WNDPROC winProc, char * className, HINSTANCE hInstance) 
    {
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = winProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW);
        wc.lpszClassName = className;
    }

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut
    Attends je pense que je me suis trompée. Ma variable valait la valeur que je t'ai indiqué quand je passe au debuger et juste aprés cette ligne en fait il y a le nombre 1410 (pour tmp = GetLastError()).

    ça veut dire que la classe existe déjà? C'est bizare? C'est vrai j'avais oublié de changer le nom de la classe... Mais je ne vois toujours pas ma fenetre fille...

  10. #10
    Membre actif

    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    193
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 193
    Points : 277
    Points
    277
    Par défaut
    Salut,
    Le tutorial est pour masm,mais il n'y a pas de différences notables de construction avec le c++ et en plus des exemples.
    http://perso.orange.fr/luce.yves/progwin.htm

  11. #11
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    574
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2004
    Messages : 574
    Points : 109
    Points
    109
    Par défaut
    En fait, c'est bon merci, j'ai résolu mon problème. Cela venait notamment des bit de style qui n'étaient pas bons.

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

Discussions similaires

  1. [XL-2007] Afficher une checkbox dans une feuille si une checkbox d'une autre feuille est cochée
    Par JessieCoutas dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 18/08/2009, 13h35
  2. portée d'une variable dans une fonction dans une méthode
    Par laurentg2003 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 29/06/2009, 19h05
  3. [POO] dans une classe, appeler une fonction dans une méthode
    Par arnaudperfect dans le forum Langage
    Réponses: 3
    Dernier message: 26/08/2007, 23h04
  4. Envoyer une formulaire dans une page dans une Frame
    Par zooffy dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 29/06/2007, 10h13
  5. Recherche une valeur d'une cellule dans une colonne d'une autre feuille
    Par kourria dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 21/06/2007, 13h48

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