Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
test gdi+ with minGL
Browse files Browse the repository at this point in the history
  • Loading branch information
romanstrazanec committed Apr 8, 2020
1 parent c0bf93e commit ac1b708
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
10 changes: 7 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
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)
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}")
35 changes: 14 additions & 21 deletions test/test_gdi_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -34,28 +32,23 @@ 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;
default:
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);
}
16 changes: 16 additions & 0 deletions test/test_gdi_plus_mingl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <mingl>

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();
}

0 comments on commit ac1b708

Please sign in to comment.