Partage
  • Partager sur Facebook
  • Partager sur Twitter

C++/Win32

Problème avec création d'un seconde fenêtre

Sujet résolu
Anonyme
    13 janvier 2006 à 0:22:29

    Salut à tous,
    mon problème se résume tout simplement à créé une seconde window qui ne veut pas s'afficher lorsque je clique sur un "IDC" dans ma première fenêtre, j'explique après vous avoir montré le code:


    // main file

    #include <iostream>
    #include <string.h>

    #include <windows.h>

    #include "resource.h"
    #include "navquarantine.h"

    #define IDC_BROWSE                  1
    #define IDC_EDIT                        2
    #define IDC_HELP_ABOUT    3
    #define IDC_OKOK                        4

            HWND            hWndAbout;
            nav                    navob;
            OPENFILENAME    ofn2;
            HWND            hWndedit;
            HWND            hWndtext;
            HINSTANCE              hInstance;

    const char *ClsName = "WinApp";
    const char *WndName = "software - beta v1.02";

    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
                               WPARAM wParam, LPARAM lParam);

    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
    {

           
            MSG               Msg;
            HWND        hWnd;

            HWND        hWndtext;
            WNDCLASSEX      WndClsEx;

            // Create the application window MAKE OPEN FILE
            WndClsEx.cbSize        = sizeof(WNDCLASSEX);
            WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
            WndClsEx.lpfnWndProc   = WndProcedure;
            WndClsEx.cbClsExtra    = 0;
            WndClsEx.cbWndExtra    = 0;
            WndClsEx.hIcon         = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1));
            WndClsEx.hCursor       = LoadCursor(hInstance, IDC_ARROW);
            WndClsEx.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
            WndClsEx.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
            WndClsEx.lpszClassName = ClsName;
            WndClsEx.hInstance     = hInstance;
            WndClsEx.hIconSm       = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2));

            // Register the application
            RegisterClassEx(&WndClsEx);

            // Create the window object
            hWnd = CreateWindow(ClsName,
                            WndName,
                            WS_OVERLAPPEDWINDOW,
                            450,       
                            250,       
                            530,        // window width
                            430,        // window heigh
                            NULL,
                            NULL,
                            hInstance,
                            NULL);

            // Create text object
            hWndtext = CreateWindowEx(0,
                    "STATIC", "Norton's quarantine directory",
            WS_CHILD|WS_VISIBLE,
                    5,10,200,20,
            hWnd, NULL, NULL, 0);

            hWndtext = CreateWindowEx(0,
                    "STATIC", "Directory: ",
            WS_CHILD|WS_VISIBLE,
                    5,30,200,20,
            hWnd, NULL, NULL, 0);
           
           
            // Create the edit object
            hWndedit = CreateWindow("EDIT", "",
                            WS_CHILD | WS_VISIBLE |ES_LEFT |
                            ES_MULTILINE | ES_AUTOVSCROLL |WS_BORDER,
                            5, 50, 150, 36,
                            hWnd, (HMENU)IDC_EDIT, hInstance, NULL);
           
            // Create button object
            HWND button = CreateWindowEx(0,
            "BUTTON", "Browse",
            WS_CHILD|WS_VISIBLE, 5, 90, 60, 20,
            hWnd, (HMENU)IDC_BROWSE, NULL, 0);

            // Find out if the window was created
            if( !hWnd )
            {
                    // If the window was not created,
                    MessageBox(hWnd, "An error has occured while creating window!\nApplication will be closed",
                            "Error", MB_OK);
                    return 0; // stop the application
            }

            // Display the window to the user
            ShowWindow(hWnd, SW_SHOWNORMAL);
            UpdateWindow(hWnd);

            // Decode and treat the messages
            // as long as the application is running
            while( GetMessage(&Msg, NULL, 0, 0) )
            {
                 TranslateMessage(&Msg);
                 DispatchMessage(&Msg);
            }

            return Msg.wParam;
    }

    LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
                               WPARAM wParam, LPARAM lParam)
    {
           
        switch(Msg)
        {
                   
            PAINTSTRUCT Ps;
           
                    case WM_COMMAND:

                            switch (LOWORD(wParam))
                            {
                                    case ID_FILE_EXIT:
                                           
                                            PostQuitMessage(WM_QUIT);
                                           
                                            break;

                                    case IDC_BROWSE:
                                            {
                                            string dir = navob.findnavqdirectory();
                                            SetWindowText(hWndedit, dir.c_str());
                                            }
                                    break;

                                    case ID_HELP_ABOUT:
                                           
                                            hWndAbout = CreateWindow("WinAbout",
                                            "",
                                            WS_OVERLAPPEDWINDOW,
                                            200,
                                            150,
                                            CW_USEDEFAULT,
                                            CW_USEDEFAULT,
                                            NULL,
                                            NULL,
                                            hInstance,
                                            NULL);
                                            ShowWindow(hWndAbout, SW_SHOW);
                                           
                                    break;

                                    default:
                                            break;

                            }

                    case WM_CREATE:

                    break;

                    case WM_SHOWWINDOW:
                    break;

                    case WM_ACTIVATE:
                    break;

                            // If the user wants to close the application
                    case WM_DESTROY:
                            // then close it
                            PostQuitMessage(WM_QUIT);
            break;

                    default:
                            // Process the left-over messages
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        return 0;
    }


    Alors voilà, ça parrait compliqué mais pas tant que ça, dans ma fonction WndProcedure: dans mon switch, la case ID_HELP_ABOUT, je voudrais qu'une nouvelle fenêtre apparaise à l'écran quand je clique sur le boutton, et je voudrais savoir en même lieu comment il sera possible je créé des static control dans ma seconde fenêtre! J'ai essayé quelques trucs qui ne fonctionne pas, et je ne trouve pas de tuto. sur le sujet, et il n'y en a pas beaucoup.

    Aucune erreur dans le code n'est procoqué.
    Rien ne se produit lorsque je clique sur le boutton, maleureusement, j'espère qu'une personne sera de quoi je parle.

    Merci à l'avance, Mazh
    • Partager sur Facebook
    • Partager sur Twitter

    C++/Win32

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown