0
#ifndef UNICODE
#define UNICODE
#endif

#include <Windows.h>
#include <d2d1.h>

LRESULT CALLBACK WProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

template <class T>
void SafeRelease(T **ppT)
{
    if (*ppT)
    {
        (*ppT)->Release();
        *ppT = NULL;
    }
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdLine)
{
    const wchar_t CLASS_NAME[] = L"Class name";

    WNDCLASS wc = {};
    wc.hInstance = hInstance;
    wc.lpfnWndProc = WProc;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);

    HWND hwnd = CreateWindowEx(0, CLASS_NAME, L"LEARN", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
    if (hwnd == NULL)
        return 0;

    ShowWindow(hwnd, nCmdLine);

    MSG msg = {};
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}

LRESULT CALLBACK WProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;

        case WM_PAINT:
            ID2D1Factory *pD2DFactory = NULL;
            HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory);
            if (SUCCEEDED(hr))
            {
                // Obtain the size of the drawing area.
                RECT rc;
                GetClientRect(hwnd, &rc);

                // Create a Direct2D render target
                ID2D1HwndRenderTarget* pRT = NULL;
                hr = pD2DFactory->CreateHwndRenderTarget(D2D1::RenderTargetProperties(), D2D1::HwndRenderTargetProperties(hwnd, D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top)), &pRT);

                if (SUCCEEDED(hr))
                {
                    ID2D1SolidColorBrush *pBlackBrush = NULL;
                    hr = pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &pBlackBrush);

                    if (SUCCEEDED(hr))
                    {
                        pRT->BeginDraw();
                        pRT->DrawRectangle(D2D1::RectF(rc.left + 100.00f, rc.top + 100.00f, rc.right - 100.00f, rc.bottom - 100.00f), pBlackBrush);
                        pRT->EndDraw();
                    }
                    SafeRelease(&pBlackBrush);
                }
                SafeRelease(&pRT);
            }
            SafeRelease(&pD2DFactory);
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

Ошибки:

1>main.obj : error LNK2019: ссылка на неразрешенный внешний символ _D2D1CreateFactory@16 в функции "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory@@YAJW4D2D1_FACTORY_TYPE@@ABU_GUID@@PAPAX@Z)

1>E:\Projects\OWN\Win32Projects\Rectangle_Direct2D\Debug\Rectangle_Direct2D.exe : fatal error LNK1120: неразрешенных внешних элементов: 1

1

1 ответ 1

1

Оно у вас не собралось, нечему запускаться. D2d1.lib добавьте в проект.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.