How to use Region (Win GDI) APIs on top of Xaml Island window
Shyam Butani
285
Reputation points
Hello,
I want to draw different shapes in WinRT/C++ application using Region APIs. It is Windows Desktop Application with Xaml Island.
I'm creating child window of the Xaml Island window, and then trying to use Region APIs to draw rectangle on this child window.
It is not working. Child window is visible on top of Xaml Island window but Region API is not painting on this child window.
Can you please help me understand why it's not working? Below is the code snippet to understand what I'm trying to do.
void DrawRectRegion(HWND hwnd)
{
RECT rect = { 10, 10, 200, 100 };
HDC hdc = GetDC(hwnd);
// Create a region
HRGN hRegion = CreateEllipticRgn(rect.left, rect.top, rect.right, rect.bottom);
if (hRegion != NULL) {
// Set the region as the clipping region
SelectClipRgn(hdc, hRegion);
// Draw something within the clipping region
FillRect(hdc, &rect, (HBRUSH)(COLOR_WINDOW + 2));
// Clean up
DeleteObject(hRegion);
}
}
// ... creating Xaml Island container and get it's window handle - hWndXamlIsland
// Create child window
HWND child = CreateWindowExW(WS_EX_LAYERED, szWindowClass, L"Dummy text", WS_VISIBLE | WS_CHILD, 20, 20, 1000, 1000, hWndXamlIsland, NULL, NULL, NULL);
// Draw Rectangle on this child window
DrawRectRegion(child);
// ... message loop
Thanks.
Sign in to answer