WndProc... HILFE!!!



  • Hallo,
    ich bin am verzweifeln.

    Und zwar deswegen:

    error C2440: '=': 'LRESULT (__stdcall *)(HINSTANCE,UINT,WPARAM,LPARAM)' kann nicht in 'WNDPROC' konvertiert werden
    

    Ich habe aus dem DirectX Beispielprojekt das herauskopiert, um ein Fenster mit WinAPI zu erstellen.
    Dort wird auch:

    wcex.lpfnWndProc = WndProc;
    

    geschrieben, und es funktioniert.

    Es hat auch schon geklappt, doch dann wollte ich das in eine Klasse auslagern, dort kam dieser Fehler auf, und als ich das jetzt rückgängig gemacht habe, verschwand er nicht 😞

    Also hier mein Code:

    #ifndef _main_cpp_
    #define _main_cpp_
    
    #include <windows.h>
    #include <cstdlib>
    #include <string>
    
    HINSTANCE  g_hInst = NULL;
    HWND       g_hWnd = NULL;
    
    HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow );
    LRESULT CALLBACK WndProc(HINSTANCE, UINT, WPARAM, LPARAM);
    
    int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
    {
    	InitWindow(hInstance, nCmdShow)	;
    
    	UNREFERENCED_PARAMETER( hPrevInstance );
        UNREFERENCED_PARAMETER( lpCmdLine );
    
    	MSG msg = {0};
        while( WM_QUIT != msg.message )
        {
            if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
    
        }
    
    	return 0;
    }
    
    HRESULT InitWindow( HINSTANCE hInstance, int nCmdShow )
    {
        // Register class
        WNDCLASSEX wcex;
        wcex.cbSize = sizeof( WNDCLASSEX );
        wcex.style = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc = WndProc;
        wcex.cbClsExtra = 0;
        wcex.cbWndExtra = 0;
        wcex.hInstance = hInstance;
        wcex.hIcon = LoadIcon( hInstance, ( LPCTSTR ) 107 );
        wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
        wcex.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
        wcex.lpszMenuName = NULL;
        wcex.lpszClassName = L"TutorialWindowClass";
        wcex.hIconSm = LoadIcon( wcex.hInstance, ( LPCTSTR ) 107);
        if( !RegisterClassEx( &wcex ) )
            return E_FAIL;
    
        // Create window
        g_hInst = hInstance;
        RECT rc = { 0, 0, 640, 480 };
        AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
        g_hWnd = CreateWindow( L"TutorialWindowClass", L"Direct3D 10 Tutorial 2: Rendering a Triangle",
                               WS_OVERLAPPEDWINDOW,
                               CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, hInstance,
                               NULL );
        if( !g_hWnd )
            return E_FAIL;
    
        ShowWindow( g_hWnd, nCmdShow );
    
        return S_OK;
    }
    
    LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
    {
        PAINTSTRUCT ps;
        HDC hdc;
    
        switch( message )
        {
            case WM_PAINT:
                hdc = BeginPaint( hWnd, &ps );
                EndPaint( hWnd, &ps );
                break;
    
            case WM_DESTROY:
                PostQuitMessage( 0 );
                break;
    
            default:
                return DefWindowProc( hWnd, message, wParam, lParam );
        }
    
        return 0;
    }
    
    #endif
    

    Kann mir jemand helfen?

    Danke!

    Player894



  • Zeile 14:
    LRESULT CALLBACK WndProc(HINSTANCE, UINT, WPARAM, LPARAM);

    Zeile 81:
    LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )



  • Oh Gott und das habe ich nicht bemerkt...
    Auf jeden Fall vielen Dank!!

    wcex.lpfnWndProc = WndProc;
    

    Allerdings wenn ich das in eine Klasse packen will, kommt sowas:

    IntelliSense: Ein Wert vom Typ ""LRESULT (__stdcall Fenster::*)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)"" kann keiner Entität vom Typ ""WNDPROC"" zugewiesen werden.
    

    und mit this-> davor kommt das:

    error C2440: '=': 'LRESULT (__stdcall Fenster::* )(HWND,UINT,WPARAM,LPARAM)' kann nicht in 'WNDPROC' konvertiert werden
    


  • Du musst entweder eine freie Funktion oder eine statische Klassen-Funktion als Windows Procedure verwenden!



  • Ok, danke, es geht jetzt 🙂


Anmelden zum Antworten