zwei leere Fenster anzeigen



  • ich möchte nichts anderes als zwei leere Fenster anzeigen:
    Fenster1 wird angezeigt... Fenster2 nicht - warum?

    //-----------------------------------------------------------------------------
    // Defines
    
    #define WIN32_LEAN_AND_MEAN // MFC wird nicht benoetigt
    
    //-----------------------------------------------------------------------------
    // Header
    
    #include <windows.h>
    #include <TCHAR.h>
    
    //-----------------------------------------------------------------------------
    // Event Handler
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    {
    	switch(msg)
    	{
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    
    		default: break;
    	}
    
    	return (DefWindowProc(hwnd, msg, wparam, lparam));
    }
    
    //-----------------------------------------------------------------------------
    // Main
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow)
    {
    	WNDCLASSEX winclass;
    	winclass.cbSize = sizeof(WNDCLASSEX);
    	winclass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC | CS_DBLCLKS;
    	winclass.lpfnWndProc = WindowProc;
    	winclass.cbClsExtra = 0; // extra class info space
    	winclass.cbWndExtra = 0; // extra window info space
    	winclass.hInstance = hInstance; // assign the application instance
    	winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
    	winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	winclass.lpszMenuName = NULL; // the name of the menu to attach
    	winclass.lpszClassName = __T("WINCLASS1"); // the name of the class itself
    	winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    	RegisterClassEx(&winclass);
    	HWND hwnd;
    	hwnd = CreateWindowEx(	NULL,
    							__T("WINCLASS1"),
    							__T("Fenstertitel"),
    							WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    							0,
    							0,
    							200,
    							200,
    							NULL, // handle to parent
    							NULL, // handle to menu
    							hInstance, // instance of this application
    							NULL);
    
    	if(hwnd==NULL)
    		return -10;
    
    	// create a second window
    	HWND hwnd2;
    	hwnd2 = CreateWindowEx(	NULL,
    							__T("WINCLASS1"),
    							__T("Fenster 2"),
    							WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    							0,
    							0,
    							300,
    							300,
    							NULL, // handle to parent
    							NULL, // handle to menu
    							hInstance, // instance of this application
    							NULL);
    
    	if(hwnd2==NULL)
    		return -11;
    
    	UpdateWindow(hwnd2);
    	ShowWindow(hwnd2, 0);
    
    	MSG msg;
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		// translate any accelerator keys
    		TranslateMessage(&msg);
    		// send the message to the window proc
    		DispatchMessage(&msg);
    	}
    	return 0;
    }
    


  • unteranderem weil du net ShowWindow(hwnd); aufrufst... du sagst nur das der ShowWindow(hwnd2); machen soll -.- und anders 😃



  • (D)Evil schrieb:

    unteranderem weil du net ShowWindow(hwnd); aufrufst... du sagst nur das der ShowWindow(hwnd2); machen soll -.- und anders 😃

    Nein, das ist es nicht, da er ja bei beiden WS_VISIBLE als Style übergibt, dann ist das ShowWindow(hwnd); nicht mehr erforferlich.

    mfg.



  • läßt man folgenden Code weg:

    UpdateWindow(hwnd2);
    ShowWindow(hwnd2, 0);
    

    dann funktiniert es. Ich hab aber keine Ahnung warum...

    also:

    //-----------------------------------------------------------------------------
    // Defines
    
    #define WIN32_LEAN_AND_MEAN // MFC wird nicht benoetigt
    
    //-----------------------------------------------------------------------------
    // Header
    
    #include <windows.h>
    #include <TCHAR.h>
    
    //-----------------------------------------------------------------------------
    // Event Handler
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    {
        switch(msg)
        {
            case WM_DESTROY:
                PostQuitMessage(0);
                return 0;
    
            default: break;
        }
    
        return (DefWindowProc(hwnd, msg, wparam, lparam));
    }
    
    //-----------------------------------------------------------------------------
    // Main
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow)
    {
        WNDCLASSEX winclass;
        winclass.cbSize = sizeof(WNDCLASSEX);
        winclass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC | CS_DBLCLKS;
        winclass.lpfnWndProc = WindowProc;
        winclass.cbClsExtra = 0; // extra class info space
        winclass.cbWndExtra = 0; // extra window info space
        winclass.hInstance = hInstance; // assign the application instance
        winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
        winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        winclass.lpszMenuName = NULL; // the name of the menu to attach
        winclass.lpszClassName = __T("WINCLASS1"); // the name of the class itself
        winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
        RegisterClassEx(&winclass);
        HWND hwnd;
        hwnd = CreateWindowEx(    NULL,
                                __T("WINCLASS1"),
                                __T("Fenstertitel"),
                                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                                0,
                                0,
                                200,
                                200,
                                NULL, // handle to parent
                                NULL, // handle to menu
                                hInstance, // instance of this application
                                NULL);
    
        if(hwnd==NULL)
            return -10;
    
        // create a second window
        HWND hwnd2;
        hwnd2 = CreateWindowEx(    NULL,
                                __T("WINCLASS1"),
                                __T("Fenster 2"),
                                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                                0,
                                0,
                                300,
                                300,
                                NULL, // handle to parent
                                NULL, // handle to menu
                                hInstance, // instance of this application
                                NULL);
    
        if(hwnd2==NULL)
            return -11;
    
       // UpdateWindow(hwnd2);
        //ShowWindow(hwnd2, 0);
    
        MSG msg;
        while(GetMessage(&msg, NULL, 0, 0))
        {
            // translate any accelerator keys
            TranslateMessage(&msg);
            // send the message to the window proc
            DispatchMessage(&msg);
        }
        return 0;
    }
    


  • ups hab jetzt herausgefunden woran es liegt:

    ShowWindow(hwnd2, 0 );
    

    ist gleichbedeutend mit

    ShowWindow(hwnd2, SW_HIDE );
    

Anmelden zum Antworten