tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
3
ZUGRIFFE
417
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Ninjasturm Ninjasturm ist offline Mitglied Bronze
    Registriert seit
    May 2010
    Beiträge
    42
    Hallo tutorials.de,

    ich habe mir einen Klasse erstellt die das erstellen eines Win32 Fensters übernimmt doch
    irgendwie funktioniert das nicht, es gibt keine Fehler beim Kompilieren nur das Fenster wird nicht erstellt könntet ihr mal drüber schauen:

    System.hpp
    Code cpp:
    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
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // System
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     
    #include <Windows.h>
    #include <StdIO.h>
    #include <IOStream>
    #include <D3D9.h>
     
    namespace Heaven
    {
        namespace System
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // WindowHandle                                                                                                                         //
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            struct WindowHandle
            {
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // WindowClass                                                                                                                          //
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                WNDCLASSEX      WindowClass;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Handle                                                                                                                               //
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                HWND            Handle;
            };
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // VideoMode                                                                                                                            //
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            struct VideoMode
            {
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // X , Y
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                int X, Y;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Width, Height                                                                                                                        //
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                int Width, Height;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Set                                                                                                                       //
                // -------------------------------------------------------------------------------------------------------------------------------------//
                // X                                                                                                                                    //
                // Y                                                                                                                                    //
                // Width                                                                                                                                //
                // Height                                                                                                                               //
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                void Set(int iX, int iY, int iWidth, int iHeight);
            };
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Window                                                                                                                               //
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            class Window
            {
                public:
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Window                                                                                                                               //
                    // -------------------------------------------------------------------------------------------------------------------------------------//
                    // Caption                                                                                                                              //
                    // VideoMode                                                                                                                            //
                    // Direct3D                                                                                                                             //
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    WindowHandle Create(const CHAR* acCaption, VideoMode vmVideoMode);
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Message                                                                                                                              //
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    static LRESULT WINAPI Message(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Release
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    void Release();
                protected:
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Caption                                                                                                                              //
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    const CHAR* m_acCaption;
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // VideoMode                                                                                                                           //
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    VideoMode m_vmVideoMode;
                    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    // Handle
                    WindowHandle m_Handle;
            };
        }
    }
    System.cpp
    Code cpp:
    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
    
    #include <System/System.hpp>
     
    void Heaven::System::VideoMode::Set(int iX, int iY, int iWidth, int iHeight)
    {
        X            = iX;
        Y            = iY;
        Width        = iWidth;
        Height       = iHeight;
    }
    LRESULT WINAPI Heaven::System::Window::Message (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch( msg )
        {
            case WM_DESTROY:
                PostQuitMessage( 0 );
                return 0;
     
            case WM_PAINT:
                ValidateRect( hWnd, NULL );
                return 0;
        }
     
        return DefWindowProc( hWnd, msg, wParam, lParam );
    }
    Heaven::System::WindowHandle Heaven::System::Window::Create(const CHAR* acCaption, VideoMode vmVideoMode)
    {
        this->m_acCaption       = acCaption;
        this->m_vmVideoMode     = vmVideoMode;
     
        std::cout << "Heaven3D v0.1" << std::endl;
     
        // Fensterklasse
        this->m_Handle.WindowClass.cbSize = sizeof(WNDCLASSEX);
        this->m_Handle.WindowClass.style = CS_CLASSDC;
        this->m_Handle.WindowClass.lpfnWndProc = this->Message;
        this->m_Handle.WindowClass.cbClsExtra = 0L;
        this->m_Handle.WindowClass.cbWndExtra = sizeof(Heaven::System::Window*);
        this->m_Handle.WindowClass.hInstance = GetModuleHandle(0);
        this->m_Handle.WindowClass.hIcon = 0;
        this->m_Handle.WindowClass.hCursor = 0;
        this->m_Handle.WindowClass.hbrBackground = 0;
        this->m_Handle.WindowClass.lpszMenuName = 0;
        this->m_Handle.WindowClass.lpszClassName = this->m_acCaption;
        this->m_Handle.WindowClass.hIconSm = 0;
        RegisterClassEx( &this->m_Handle.WindowClass );
     
        // Fenster
        HWND hWnd = CreateWindow( this->m_acCaption , this->m_acCaption ,
                                  WS_OVERLAPPEDWINDOW, this->m_vmVideoMode.X , this->m_vmVideoMode.Y  , this->m_vmVideoMode.Width, this->m_vmVideoMode.Height,
                                  NULL, NULL, this->m_Handle.WindowClass.hInstance, NULL );
     
        std::cout << "Caption:        " << this->m_acCaption            << std::endl;
        std::cout << "X:              " << this->m_vmVideoMode.X        << std::endl;
        std::cout << "Y:              " << this->m_vmVideoMode.Y        << std::endl;
        std::cout << "Width:          " << this->m_vmVideoMode.Width    << std::endl;
        std::cout << "Height:         " << this->m_vmVideoMode.Height   << std::endl;
        return this->m_Handle;
    }
    void Heaven::System::Window::Release()
    {
        UnregisterClass( this->m_acCaption, this->m_Handle.WindowClass.hInstance);
    }
    main.cpp
    Code cpp:
    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
    
    #include <d3d9.h>
    #include <strsafe.h>
    #include <Heaven3D.hpp>
     
    LPDIRECT3D9         g_pD3D = NULL; // Used to create the D3DDevice
    LPDIRECT3DDEVICE9   g_pd3dDevice = NULL; // Our rendering device
     
    HRESULT InitD3D( HWND hWnd )
    {
        if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
            return E_FAIL;
     
        D3DPRESENT_PARAMETERS d3dpp;
        ZeroMemory( &d3dpp, sizeof( d3dpp ) );
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
     
        if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                          &d3dpp, &g_pd3dDevice ) ) )
        {
            return E_FAIL;
        }
     
        return S_OK;
    }
     
    VOID Cleanup()
    {
        if( g_pd3dDevice != NULL )
            g_pd3dDevice->Release();
     
        if( g_pD3D != NULL )
            g_pD3D->Release();
    }
     
    VOID Render()
    {
        if( NULL == g_pd3dDevice )
            return;
     
        // Clear the backbuffer to a blue color
        g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
     
        // Begin the scene
        if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
        {
            // Rendering of scene objects can happen here
     
            // End the scene
            g_pd3dDevice->EndScene();
        }
     
        // Present the backbuffer contents to the display
        g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
    }
     
    LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
        switch( msg )
        {
            case WM_DESTROY:
                Cleanup();
                PostQuitMessage( 0 );
                return 0;
     
            case WM_PAINT:
                Render();
                ValidateRect( hWnd, NULL );
                return 0;
        }
     
        return DefWindowProc( hWnd, msg, wParam, lParam );
    }
     
    INT main( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
    {
     
        Heaven::System::VideoMode VideoMode;
        VideoMode.Set(0, 0, 1024, 768);
     
        Heaven::System::Window Window;
        Heaven::System::WindowHandle Handle = Window.Create("Hello World", VideoMode);
     
        // Initialize Direct3D
        if( SUCCEEDED( InitD3D(Handle.Handle) ) )
        {
            // Show the window
            ShowWindow(Handle.Handle, SW_SHOWDEFAULT );
            UpdateWindow(Handle.Handle);
     
            // Enter the message loop
            MSG msg;
            while( GetMessage( &msg, NULL, 0, 0 ) )
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        }
        return 0;
    }

    Die Engine also Heaven3D compiliere ich in eine DLL Datei.
    Es werden auch die Informationen zum VideoMode angezeigt, die Funktion findet er also.

    IDE: Code::Blocks
    Compiler: MinGW
    DirectX: 9
     
    MfG Ninjasturm

  2. #2
    Registriert seit
    Dec 2001
    Ort
    Bayern
    Beiträge
    5.802
    Blog-Einträge
    5
    Hallo Ninjasturm,

    verwende doch einfach einen Debugger und verfolge den Programmablauf Schritt für Schritt. Dann solltest du auch sehen, dass CreateDevice einen Fehler zurückliefert.

    Grüße,
    Matthias
     
    „Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
    “For every complex problem, there is an answer that is short, simple and wrong.”
    “Pessimism is safe, but optimism is a lot faster!”


    Aktuelles Coding Quiz: #17 - Wörter kreuz und quer

  3. #3
    Ninjasturm Ninjasturm ist offline Mitglied Bronze
    Registriert seit
    May 2010
    Beiträge
    42
    Und warum funktioniert
    Code cpp:
    1
    2
    3
    
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                          &d3dpp, &g_pd3dDevice ) ) )
    nicht. Ich kann mir das irgendwie nicht erklären warum das nicht funktioniert.
     
    MfG Ninjasturm

  4. #4
    Registriert seit
    Dec 2001
    Ort
    Bayern
    Beiträge
    5.802
    Blog-Einträge
    5
    Zitat Zitat von Ninjasturm Beitrag anzeigen
    Und warum funktioniert
    Code cpp:
    1
    2
    3
    
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                          &d3dpp, &g_pd3dDevice ) ) )
    nicht. Ich kann mir das irgendwie nicht erklären warum das nicht funktioniert.
    Lass dir mal vom Debugger anzeigen, welchen Wert hWnd hat. Allgemeiner Tipp zur Direct3D-9-Entwicklung: aktiviere die Debug-Version von Direct3D 9 im DirectX Control Panel. Dann erhältst du nützliche Fehlermeldungen auf der Debugkonsole. Hier bekomme ich z.B. Folgendes ausgegeben:
    Code :
    1
    
    Direct3D9: (ERROR) :Invalid HWND specified for hwndFocusWindow, CreateDeviceEx fails

    Grüße,
    Matthias
     
    „Gib einem Menschen einen Fisch, und er wird für einen Tag satt. Lehre ihn Fischen, und er wird ein Leben lang satt.“
    “For every complex problem, there is an answer that is short, simple and wrong.”
    “Pessimism is safe, but optimism is a lot faster!”


    Aktuelles Coding Quiz: #17 - Wörter kreuz und quer

Ähnliche Themen

  1. Mit einer Klasse Objekte für eine andere Klasse erstellen.
    Von New2Java im Forum Java Grundlagen
    Antworten: 14
    Letzter Beitrag: 21.11.10, 12:37
  2. Antworten: 3
    Letzter Beitrag: 18.03.09, 09:27
  3. Antworten: 15
    Letzter Beitrag: 05.03.08, 15:36
  4. Antworten: 0
    Letzter Beitrag: 15.07.07, 06:46
  5. Antworten: 6
    Letzter Beitrag: 25.03.05, 23:40