Bsbosa.com
07-11-2010, 11:08 PM
I've never used GDI in any of my projects.
But had some programming introduction to it.
Since I've been using Windows 7, I'm trying to build a new project with Direct2D.
It compiles and runs, but it doesn't display anything!
Does anyone have any experience, what could be the reason?
#include #include
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hCurrInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS SetFileTime = {};
SetFileTime.hInstance = hCurrInstance;
SetFileTime.lpfnWndProc = WndProc;
SetFileTime.lpszClassName = L"D2D";
RegisterClass(&SetFileTime);
CreateWindow(
L"D2D",
L"Direct2D",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
100, 100, 800, 600,
NULL,
NULL,
hCurrInstance,
NULL);
MSG WindowMessages = { };
while (GetMessage(&WindowMessages, NULL, 0, 0))
{
TranslateMessage(&WindowMessages);
DispatchMessage(&WindowMessages);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
ID2D1Factory* pD2DFactory = NULL;
D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED , &pD2DFactory);
RECT rc;
GetClientRect(hwnd, &rc);
ID2D1HwndRenderTarget* pRT = NULL;
pD2DFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(hwnd, D2D1::SizeU( rc.right - rc.left, rc.bottom - rc.top)),
&pRT);
ID2D1SolidColorBrush* m_pLightSlateGrayBrush = NULL;
pRT->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::LightSlateGray), &m_pLightSlateGrayBrush);
D2D_RECT_F OriginalRect;
OriginalRect.left = 10.f;
OriginalRect.top = 10.f;
OriginalRect.bottom = 100.f;
OriginalRect.right = 100.f;
D2D1_ROUNDED_RECT RoundedRect;
RoundedRect.rect = OriginalRect;
RoundedRect.radiusX = 1.0f;
RoundedRect.radiusY = 1.0f;
ID2D1RoundedRectangleGeometry* Card = NULL;
pD2DFactory->CreateRoundedRectangleGeometry(RoundedRect, &Card);
pRT->BeginDraw();
pRT->FillRoundedRectangle(&RoundedRect, m_pLightSlateGrayBrush);
pRT->DrawRoundedRectangle(&RoundedRect, m_pLightSlateGrayBrush);
pRT->EndDraw();
return 0;
}
case WM_CLOSE:
{
DestroyWindow(hwnd);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
But had some programming introduction to it.
Since I've been using Windows 7, I'm trying to build a new project with Direct2D.
It compiles and runs, but it doesn't display anything!
Does anyone have any experience, what could be the reason?
#include #include
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hCurrInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS SetFileTime = {};
SetFileTime.hInstance = hCurrInstance;
SetFileTime.lpfnWndProc = WndProc;
SetFileTime.lpszClassName = L"D2D";
RegisterClass(&SetFileTime);
CreateWindow(
L"D2D",
L"Direct2D",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
100, 100, 800, 600,
NULL,
NULL,
hCurrInstance,
NULL);
MSG WindowMessages = { };
while (GetMessage(&WindowMessages, NULL, 0, 0))
{
TranslateMessage(&WindowMessages);
DispatchMessage(&WindowMessages);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
ID2D1Factory* pD2DFactory = NULL;
D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED , &pD2DFactory);
RECT rc;
GetClientRect(hwnd, &rc);
ID2D1HwndRenderTarget* pRT = NULL;
pD2DFactory->CreateHwndRenderTarget( D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(hwnd, D2D1::SizeU( rc.right - rc.left, rc.bottom - rc.top)),
&pRT);
ID2D1SolidColorBrush* m_pLightSlateGrayBrush = NULL;
pRT->CreateSolidColorBrush( D2D1::ColorF(D2D1::ColorF::LightSlateGray), &m_pLightSlateGrayBrush);
D2D_RECT_F OriginalRect;
OriginalRect.left = 10.f;
OriginalRect.top = 10.f;
OriginalRect.bottom = 100.f;
OriginalRect.right = 100.f;
D2D1_ROUNDED_RECT RoundedRect;
RoundedRect.rect = OriginalRect;
RoundedRect.radiusX = 1.0f;
RoundedRect.radiusY = 1.0f;
ID2D1RoundedRectangleGeometry* Card = NULL;
pD2DFactory->CreateRoundedRectangleGeometry(RoundedRect, &Card);
pRT->BeginDraw();
pRT->FillRoundedRectangle(&RoundedRect, m_pLightSlateGrayBrush);
pRT->DrawRoundedRectangle(&RoundedRect, m_pLightSlateGrayBrush);
pRT->EndDraw();
return 0;
}
case WM_CLOSE:
{
DestroyWindow(hwnd);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}