vendredi 1 juillet 2016

Wndproc handling events less code

I want to know if there is a way i could write this code shorter, if there is anyway to make a #define that can shorten the way im doing my if statements in the message switch. I check if i have set up a function if there is i then call it This is just apart of my wndproc it is alot bigger

LRESULT Base::WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
        switch (uMsg)
        {
        case WM_CREATE:
        {
            if (this->onCreate != NULL)
            {
                if (onCreate(hwnd, (LPCREATESTRUCT)lParam))
                    return 1;
            }
        }break;

        case WM_DESTROY:
        {
            if (onDestroy != NULL)
            {
                if (onDestroy(hwnd))
                    return 1;
            }
            this->Destroy();
        }break;

        case WM_SIZE:
        {
            if (onSize != NULL)
            {
                if (onSize(hwnd, wParam, lParam))
                    return 1;
            }
        }break;

        case WM_CLOSE:
        {
            if (onClose != NULL)
            {
                if (onClose(hwnd))
                    return 1;
            }
        }break;

        default:
        {

        }break;

        }

        return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

pointers defined like this

LRESULT(*onCreate) (HWND, LPCREATESTRUCT);

I then add them like this

LRESULT onCreate(HWND, LPCREATESTRUCT)
{

    return true;
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR pCmdLine, int nCmdShow)
{
    Window mainWindow;
    mainWindow.onCreate = onCreate;

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire