Bringe mein MDI Fenster nicht zum erscheinen



  • Hi,

    ich hab ein kleines Problem mit einem MDI Fenster.
    Zuerst mal der Quelltext:

    #include <windows.h>
    
    #define IDM_FIRSTCHILD 5947375
    
    wchar_t name[]=L"LIBTEST";
    wchar_t mdin[]=L"MDI";
    __w64 long __stdcall WndProc (HWND hwnd, unsigned int message, __w64 unsigned int wParam, __w64 long lParam);
    __w64 long __stdcall ViewProc(HWND hwnd, unsigned int message, __w64 unsigned int wParam, __w64 long lParam);
    
    int WINAPI WinMain (HINSTANCE__* hInstance, HINSTANCE__* hPrevInstance,
    				    char *szCmdLine, int iCmdShow)
    {
    	HACCEL          hAccel;
    	MSG             msg;
    	WNDCLASSW       wndclass;
    	HWND			  hwnd, hwnd_client;
    	HDC				  hdc = NULL;
    
        ZeroMemory(&hwnd,     sizeof(HWND__*));
        ZeroMemory(&msg,      sizeof(MSG));
    	ZeroMemory(&wndclass, sizeof(WNDCLASSW));
    
    	wndclass.style         = CS_HREDRAW | CS_VREDRAW;
    	wndclass.lpfnWndProc   = WndProc;
    	wndclass.cbClsExtra    = 0;
    	wndclass.cbWndExtra    = 0;
    	wndclass.hInstance     = hInstance ;
    	wndclass.hIcon         = NULL ;
    	wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    	wndclass.lpszMenuName  = NULL;
    	wndclass.lpszClassName = name;
    
    	if(RegisterClass(&wndclass))
        {
            MessageBoxW(hwnd, L"Die Anwendung konnte nicht richtig initalisiert werden. Wenn es nicht klappt beten sie ein bisschen vielleicht klappts dann! ;-)", L"Error", MB_OK);
            return 0;
        }
    
    	wndclass.style         = CS_HREDRAW | CS_VREDRAW;
    	wndclass.lpfnWndProc   = ViewProc;
    	wndclass.cbClsExtra    = 0;
    	wndclass.cbWndExtra    = 0;
    	wndclass.hInstance     = hInstance ;
    	wndclass.hIcon         = NULL ;
    	wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    	wndclass.lpszMenuName  = NULL;
    	wndclass.lpszClassName = L"View";
    
    	if (!RegisterClass(&wndclass))
        {
            MessageBoxW(hwnd, L"Die Anwendung konnte nicht richtig initalisiert werden. Wenn es nicht klappt beten sie ein bisschen vielleicht klappts dann! ;-)", L"Error", MB_OK);
            return 0;
        }
    
    	hAccel = LoadAccelerators(hInstance,name);
    
    	hwnd = CreateWindow (name, name, WS_SYSMENU|WS_CAPTION ,
    		                 CW_USEDEFAULT, CW_USEDEFAULT,
    		                 640, 480,
    						 NULL, NULL, hInstance, NULL);
    
    	hwnd_client = GetWindow(hwnd, GW_CHILD);
    
    	ShowWindow (hwnd, iCmdShow);
    	UpdateWindow (hwnd);
    
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
    		if(!TranslateMDISysAccel(hwnd_client,&msg) && 
    		   !TranslateAccelerator(hwnd,hAccel,&msg))
    		{
    			TranslateMessage (&msg);
    			DispatchMessage (&msg);
    		}
    	}
    
    	return (static_cast<int>(msg.wParam));
    }
    
    __w64 long __stdcall WndProc (HWND__* hwnd, unsigned int message, __w64 unsigned int wParam, __w64 long lParam)
    {
    	CLIENTCREATESTRUCT clientcreate;
    	static HWND	hwnd_client;
    	HWND  hwnd_child;
    	MDICREATESTRUCT mdicreate;
    	HINSTANCE hInst = NULL;
    
        switch (message)
    	{
    	case WM_CREATE:
    		clientcreate.idFirstChild = IDM_FIRSTCHILD;
    		hwnd_client = CreateWindow (TEXT ("MDICLIENT"), NULL,
                                         WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,   
                                         10, 10, 100, 100, hwnd, 0, hInst,
                                         (PSTR) &clientcreate) ;
    
            mdicreate.szClass = L"HALLO" ;
            mdicreate.szTitle = TEXT ("Hello") ;
            mdicreate.hOwner  = hInst ;
            mdicreate.x       = 10 ;
            mdicreate.y       = 10 ;
            mdicreate.cx      = 100 ;
            mdicreate.cy      = 100 ;
            mdicreate.style   = 0 ;
            mdicreate.lParam  = 0 ;
    
            hwnd_child = (HWND) SendMessage (hwnd_client, WM_MDICREATE, 0,
                                       (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ;
    
    		break;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		MessageBeep(50);
    		break;
    	}
    
         return DefFrameProc (hwnd, hwnd_client, message, wParam, lParam) ;
    }
    
    __w64 long __stdcall ViewProc(HWND hwnd, unsigned int message, __w64 unsigned int wParam, __w64 long lParam)
    {
        static HWND     hwnd_client, hwndFrame ;
    
        switch (message)
    	{
    	case WM_CREATE:
            hwnd_client = GetParent (hwnd) ;
            hwndFrame  =  GetParent (hwnd_client) ;
    		break;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		MessageBeep(50);
    		break;
    	}
    
        return DefWindowProc (hwnd, message, wParam, lParam);
    
    }
    

    Das Fenster erscheint wie erwartet aber es wird seltsamerweise kein MDI Fenster angezeigt!
    Ich bitte euch um Hilfe und bin euch über jede Hilfe dankbar
    Schon mal danke im vorraus

    Multiple Document Interf.



  • Hat sich im ICQ ja geklärt, hier aber nochmal ein simples Beispiel:

    #include <windows.h>
    
    // Globaler Unsinn
    //
    const TCHAR applicationClassName[] = TEXT( "MainFrm" );
    const TCHAR mdiChildClassName[] = TEXT( "MDIChildFrm" );
    
    enum { IDM_FIRSTCHILD = 0xff };
    
    // Forwarddeclarations
    //
    LRESULT APIENTRY WndProc( HWND, UINT, WPARAM, LPARAM );
    LRESULT APIENTRY WndProcMDIChild( HWND, UINT, WPARAM, LPARAM );
    
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow )
    {
    	MSG msg;
    
    	// Mainframe registrieren
    	//
    	WNDCLASSEX cls =
    	{
    		sizeof( WNDCLASSEX ),
    		CS_VREDRAW | CS_HREDRAW,
    		WndProc,
    		0, 0,
    		hInstance,
    		LoadIcon( NULL, IDI_APPLICATION ),
    		LoadCursor( NULL, IDC_ARROW ),
    		GetSysColorBrush( COLOR_BTNFACE ),
    		NULL,
    		applicationClassName,
    		LoadIcon( NULL, IDI_APPLICATION )
    	};
    
    	if ( !RegisterClassEx( &cls ) )
    	{
    		MessageBox( NULL, TEXT( "Fehler beim registrieren der Klasse 'MainFrm'" ), TEXT( "Error" ), MB_OK | MB_ICONERROR );
    		return 0;
    	}
    
    	// MDI Child Frame registrieren
    	//
    	cls.lpfnWndProc   = WndProcMDIChild;
    	cls.hIcon		  = NULL;
    	cls.lpszClassName = mdiChildClassName;
    
    	if ( !RegisterClassEx( &cls ) )
    	{
    		MessageBox( NULL, TEXT( "Fehler beim registrieren der Klasse 'MDIChildFrm'" ), TEXT( "Error" ), MB_OK | MB_ICONERROR );
    		return 0;
    	}
    
    	// Fenster erzeugen
    	//
    	HWND hWnd = CreateWindowEx( NULL, 
    								applicationClassName,
    								TEXT( "My MDI Application" ),
    								WS_OVERLAPPEDWINDOW,
    								0, 0,
    								800, 600,
    								NULL, 
    								NULL,
    								hInstance,
    								NULL );
    
    	HWND hWndMDIClient = GetWindow( hWnd, GW_CHILD );
    
    	ShowWindow( hWnd, SW_SHOW );
    	UpdateWindow( hWnd );
    
    	while ( GetMessage( &msg, NULL, 0, 0 ) )
    	{
    		if ( !TranslateMDISysAccel( hWndMDIClient, &msg ) )
    		{
    			TranslateMessage( &msg );
    			DispatchMessage( &msg );
    		}
    	}
    
    	return static_cast< int >( msg.wParam );
    }
    
    LRESULT APIENTRY WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
    	switch ( uMsg )
    	{
    	case WM_CREATE:
    		{
    			// MDI Client erzeugen
    			//
    			CLIENTCREATESTRUCT ccs =
    			{
    				NULL,
    				IDM_FIRSTCHILD
    			}; 
    
    			HINSTANCE hInstance = GetModuleHandle( NULL );
    			HWND hWndClient = CreateWindowEx( NULL, 
    											  TEXT( "MDICLIENT" ), 
    											  NULL, 
    											  WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,
    											  CW_USEDEFAULT, 
    											  CW_USEDEFAULT,
    											  CW_USEDEFAULT,
    											  CW_USEDEFAULT,
    											  hWnd,
    											  NULL,
    											  hInstance,
    											  ( LPSTR )&ccs );
    
    			ShowWindow( hWndClient, SW_SHOW );
    
    			// MDI Child hinzufuegen
    			//
    
    			MDICREATESTRUCT childFrm =
    			{
    				mdiChildClassName,
    				TEXT( "Foobar" ),
    				hInstance,
    				0, 0, 200, 200,
    				0,
    				0
    			};
    
    			SendMessage( hWndClient, WM_MDICREATE, 0, ( LPARAM )( LPMDICREATESTRUCT )&childFrm );
    		}
    		break;
    
    	case WM_DESTROY:
    		PostQuitMessage( 0 );
    		break;
    
    	case WM_SIZE:
    		{
    			HWND hWndMDIClient = GetWindow( hWnd, GW_CHILD );
    			RECT rect;
    
    			GetClientRect( hWnd, &rect );	
    			SetWindowPos( hWndMDIClient, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER );
    		}
    		break;
    	}
    
    	return DefWindowProc( hWnd, uMsg, wParam, lParam );
    }
    
    LRESULT APIENTRY WndProcMDIChild( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
    	return DefWindowProc( hWnd, uMsg, wParam, lParam );
    }
    

Log in to reply