diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8ab6df1..eba8c18 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,13 +2,17 @@ add_executable(test_gdi_plus test_gdi_plus.cpp) target_link_libraries(test_gdi_plus PRIVATE gdiplus) +# GDIPLUS with minGL test +add_executable(test_gdi_plus_mingl test_gdi_plus_mingl.cpp) +target_link_libraries(test_gdi_plus_mingl PRIVATE "${PROJECT_NAME}") + # Simple Window test add_executable(test_simple_window test_simple_window.cpp) -target_link_libraries(test_simple_window PRIVATE minGL) +target_link_libraries(test_simple_window PRIVATE "${PROJECT_NAME}") # Regular command line test add_executable(test test_cli.cpp) -target_link_libraries(test PRIVATE minGL) +target_link_libraries(test PRIVATE "${PROJECT_NAME}") # Windows apps with win32api add_executable(test_windows_api test_windows_api.cpp) @@ -16,4 +20,4 @@ add_executable(test_windows_api_app test_windows_api_app.cpp) # Mouse interaction application test add_executable(test_mouse_interaction test_mouse_interaction.cpp) -target_link_libraries(test_mouse_interaction PRIVATE minGL) +target_link_libraries(test_mouse_interaction PRIVATE "${PROJECT_NAME}") diff --git a/test/test_gdi_plus.cpp b/test/test_gdi_plus.cpp index f68420b..99f54a4 100644 --- a/test/test_gdi_plus.cpp +++ b/test/test_gdi_plus.cpp @@ -3,10 +3,7 @@ LRESULT CALLBACK WindowProcessMessages(HWND, UINT, WPARAM, LPARAM); -void draw(HDC hdc); - int WINAPI WinMain(HINSTANCE currentInstance, HINSTANCE previousInstance, PSTR cmdLine, INT cmdCount) { - PROPID p; Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr); @@ -18,13 +15,14 @@ int WINAPI WinMain(HINSTANCE currentInstance, HINSTANCE previousInstance, PSTR c wc.hCursor = LoadCursor(nullptr, IDC_ARROW); wc.hbrBackground = (HBRUSH) COLOR_WINDOW; wc.lpfnWndProc = WindowProcessMessages; - RegisterClass(&wc); - CreateWindow(CLASS_NAME, "Win32 Tutorial", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, + if (!RegisterClass(&wc)) return -1; + + CreateWindow(CLASS_NAME, "GDI+ Test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 50, 800, 600, nullptr, nullptr, nullptr, nullptr); MSG msg{}; - while (GetMessage(&msg, nullptr, 0, 0)) { + while (GetMessage(&msg, nullptr, NULL, NULL) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } @@ -34,14 +32,19 @@ int WINAPI WinMain(HINSTANCE currentInstance, HINSTANCE previousInstance, PSTR c } LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - HDC hdc; - PAINTSTRUCT ps; switch (msg) { - case WM_PAINT: - hdc = BeginPaint(hwnd, &ps); - draw(hdc); + case WM_PAINT: { + PAINTSTRUCT ps; + Gdiplus::Graphics gf(BeginPaint(hwnd, &ps)); + Gdiplus::Pen pen(Gdiplus::Color(255, 255, 0, 0)); + Gdiplus::SolidBrush brush(Gdiplus::Color(255, 0, 255, 0)); + + gf.DrawLine(&pen, 0, 0, 500, 500); + gf.FillRectangle(&brush, 400, 200, 100, 100); + gf.DrawRectangle(&pen, 450, 400, 100, 150); EndPaint(hwnd, &ps); return 0; + } case WM_DESTROY: PostQuitMessage(0); return 0; @@ -49,13 +52,3 @@ LRESULT CALLBACK WindowProcessMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARA return DefWindowProc(hwnd, msg, wparam, lparam); } } - -void draw(HDC hdc) { - Gdiplus::Graphics gf(hdc); - Gdiplus::Pen pen(Gdiplus::Color(255, 255, 0, 0)); - Gdiplus::SolidBrush brush(Gdiplus::Color(255, 0, 255, 0)); - - gf.DrawLine(&pen, 0, 0, 500, 500); - gf.FillRectangle(&brush, 400, 200, 100, 100); - gf.DrawRectangle(&pen, 450, 400, 100, 150); -} diff --git a/test/test_gdi_plus_mingl.cpp b/test/test_gdi_plus_mingl.cpp new file mode 100644 index 0000000..98e31cc --- /dev/null +++ b/test/test_gdi_plus_mingl.cpp @@ -0,0 +1,16 @@ +#include + +int main() { + Window window("GDI+ Test", 100, 50, 800, 600); + + window.addOnDrawHandler([](Gdiplus::Graphics *graphics) { + Gdiplus::Pen pen(Gdiplus::Color(255, 255, 0, 0)); + Gdiplus::SolidBrush brush(Gdiplus::Color(255, 0, 255, 0)); + + graphics->DrawLine(&pen, 0, 0, 500, 500); + graphics->FillRectangle(&brush, 400, 200, 100, 100); + graphics->DrawRectangle(&pen, 450, 400, 100, 150); + }); + + window.show(); +}