Skip to content

Commit 1eeb30a

Browse files
authored
Second set of samples including Acrylic and Advanced Color. (#34)
1 parent 57443df commit 1eeb30a

107 files changed

Lines changed: 6744 additions & 1649 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For related documentation, see [Modernize your desktop app using the Visual laye
1818

1919
Minimum requirements for using the Visual layer in desktop apps are listed here. Individual samples might have different requirements, which are listed in the readme for the sample.
2020

21-
- Visual Studio 2017 - [Get a free copy of Visual Studio 2017 with support for building Universal Windows apps](http://go.microsoft.com/fwlink/?LinkID=280676)
21+
- Visual Studio 2017 or later - [Get a free copy of Visual Studio](http://go.microsoft.com/fwlink/?LinkID=280676)
2222
- .NET Framework 4.7.2 or later
2323
- Windows 10 version 1803 or later
2424
- Windows 10 SDK 17134 or later
@@ -32,6 +32,7 @@ Minimum requirements for using the Visual layer in desktop apps are listed here.
3232
| [**Hello Composition sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp/HelloComposition)</br>Demonstrates how to set up a project to use Composition APIs in a C++ Win32 app.</br>See the [Using the Visual layer with Win32](https://docs.microsoft.com/windows/uwp/composition/using-the-visual-layer-with-win32) tutorial for more info. | ![Hello Composition sample](images/hello-comp-win32.png) |
3333
| [**Hello Vectors sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp/HelloVectors)</br>Demonstrates how to use vectors in the Visual layer. | ![Vector graphics UI](images/hello-vectors-win32.png) |
3434
| [**Virtual Surfaces sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp/VirtualSurfaces)</br>Demonstrates how to use virtual surfaces in the Visual layer. | ![Virtual surfaces UI](images/virtual-surfaces-win32.png) |
35+
| [**Advanced Color sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp/AdvancedColorImages)</br>Demonstrates how to load advanced color (HDR, High Color Gamut, High precision) images into a Virtual Surface and use an Interaction Tracker that helps create a smooth scrollable surface that responds well to touch, mouse, and precision touchpad. | ![Advanced color image UI](images/advanced-color-win32.png) |
3536
| [**Screen Capture sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/cpp/ScreenCaptureforHWND)</br>Demonstrates how to use screen capture APIs. | ![Screen capture UI](images/screen-capture-win32.png) |
3637

3738
### Windows Forms
@@ -40,6 +41,7 @@ Minimum requirements for using the Visual layer in desktop apps are listed here.
4041
| - | - |
4142
| [**Hello Composition sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WinForms/HelloComposition)</br>Demonstrates how to set up a project to use Composition APIs in a Windows Forms app.</br>See the [Using the Visual layer with Windows Forms](https://docs.microsoft.com/windows/uwp/composition/using-the-visual-layer-with-windows-forms) tutorial for more info. | ![Hello Composition sample](images/hello-comp-wf.png) |
4243
| [**Visual Layer Integration sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WinForms/VisualLayerIntegration)</br>Demonstrates how to use a bar graph created with Composition APIs in a Windows Forms app. | ![Bar graph UI](images/bar-graph-winforms.png) |
44+
| [**Win2D Effects (Acrylic) sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WinForms/AcrylicEffect)</br>Demonstrates how to use Win2D effects to show an acrylic overlay on top of a picture. | ![Acrylic effect](images/acrylic-effect-winforms.png) |
4345

4446
### WPF
4547

@@ -48,12 +50,13 @@ Minimum requirements for using the Visual layer in desktop apps are listed here.
4850
| [**Hello Composition sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/HelloComposition)</br>Demonstrates how to set up a project to use Composition APIs in a WPF app.</br>See the [Using the Visual layer with WPF](https://docs.microsoft.com/windows/uwp/composition/using-the-visual-layer-with-wpf) tutorial for more info. | ![Hello Composition sample](images/hello-comp-wpf.png) |
4951
| [**Visual Layer Integration sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/VisualLayerIntegration)</br>Demonstrates how to use a bar graph created with Composition APIs in a WPF app. | ![Bar graph UI](images/bar-graph-wpf.png) |
5052
| [**Screen Capture sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/ScreenCapture)</br>Demonstrates how to use screen capture APIs. | ![Screen capture UI](images/capture-wpf.png) |
53+
| [**Win2D Effects (Acrylic) sample**](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect)</br>Demonstrates how to use Win2D effects to show an acrylic overlay on top of a picture. | ![Acrylic effect](images/acrlyic-effect-wpf.png) |
5154

5255
## Limitations
5356

5457
While many Visual Layer features work the same when hosted in a desktop application as they do in a UWP app, some features do have limitations. Here are some of the limitations to be aware of:
5558

56-
- Effect chains rely on [Win2D](http://microsoft.github.io/Win2D/html/Introduction.htm) for the effect descriptions. The [Win2D NuGet package](https://www.nuget.org/packages/Win2D.uwp) is not supported in desktop applications, so you would need to recompile it from the [source code](https://github.com/Microsoft/Win2D).
59+
- Effect chains rely on [Win2D](http://microsoft.github.io/Win2D/html/Introduction.htm) for the effect descriptions. The [Win2D NuGet package](https://www.nuget.org/packages/Win2D.uwp) is not supported in desktop applications, so you need to manually add the DLL to your projects output folder. See the **Win2D Effects (Acrylic) sample** for [WPF](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WPF/AcrylicEffect) or [Windows Forms](https://github.com/Microsoft/Windows.UI.Composition-Win32-Samples/tree/master/dotnet/WinForms/AcrylicEffect) for more information.
5760
- To do hit testing, you need to do bounds calculations by walking the visual tree yourself. This is the same as the Visual Layer in UWP, except in this case there's no XAML element you can easily bind to for hit testing.
5861
- The Visual Layer does not have a primitive for rendering text.
5962
- When two different UI technologies are used together, such as WPF and the Visual Layer, they are each responsible for drawing their own pixels on the screen, and they can't share pixels. As a result, Visual Layer content is always rendered on top of other UI content. (This is known as the _airspace_ issue.) You might need to do extra coding and testing to ensure your Visual layer content resizes with the host UI and doesn't occlude other content.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.168
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdvancedColorImages", "AdvancedColorImages\AdvancedColorImages.vcxproj", "{740EF6CC-CDDA-4413-8D66-FF32C113F077}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Debug|x64.ActiveCfg = Debug|x64
17+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Debug|x64.Build.0 = Debug|x64
18+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Debug|x86.ActiveCfg = Debug|Win32
19+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Debug|x86.Build.0 = Debug|Win32
20+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Release|x64.ActiveCfg = Release|x64
21+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Release|x64.Build.0 = Release|x64
22+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Release|x86.ActiveCfg = Release|Win32
23+
{740EF6CC-CDDA-4413-8D66-FF32C113F077}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {7B0452A9-175E-4DE1-ACAE-560B0327AF7A}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,289 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
// main.cpp : Defines the entry point for the application.
16+
17+
#include "stdafx.h"
18+
#include "AdvancedColorImages.h"
19+
#include "WinComp.h"
20+
21+
using namespace winrt;
22+
using namespace Windows::UI;
23+
using namespace Windows::UI::Composition;
24+
using namespace Windows::UI::Composition::Desktop;
25+
using namespace Windows::UI::Input;
26+
27+
28+
#define MAX_LOADSTRING 100
29+
30+
// Global Variables:
31+
HINSTANCE hInst; // current instance
32+
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
33+
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
34+
HWND m_childHWnd;
35+
WinComp* m_winComp;
36+
37+
// Forward declarations of functions included in this code module:
38+
ATOM MyRegisterClass(HINSTANCE hInstance);
39+
BOOL InitInstance(HINSTANCE, int);
40+
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
41+
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
42+
43+
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
44+
_In_opt_ HINSTANCE hPrevInstance,
45+
_In_ LPWSTR lpCmdLine,
46+
_In_ int nCmdShow)
47+
{
48+
49+
50+
UNREFERENCED_PARAMETER(hPrevInstance);
51+
UNREFERENCED_PARAMETER(lpCmdLine);
52+
53+
winrt::init_apartment(winrt::apartment_type::single_threaded);
54+
55+
// Initialize global strings
56+
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
57+
LoadStringW(hInstance, IDC_ADVANCEDCOLORIMAGES, szWindowClass, MAX_LOADSTRING);
58+
MyRegisterClass(hInstance);
59+
// Perform application initialization:
60+
if (!InitInstance(hInstance, nCmdShow))
61+
{
62+
return FALSE;
63+
}
64+
65+
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ADVANCEDCOLORIMAGES));
66+
67+
MSG msg;
68+
69+
// Main message loop:
70+
while (GetMessage(&msg, nullptr, 0, 0))
71+
{
72+
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
73+
{
74+
TranslateMessage(&msg);
75+
DispatchMessage(&msg);
76+
}
77+
}
78+
return (int)msg.wParam;
79+
}
80+
81+
82+
//
83+
// FUNCTION: MyRegisterClass()
84+
//
85+
// PURPOSE: Registers the window class.
86+
//
87+
ATOM MyRegisterClass(HINSTANCE hInstance)
88+
{
89+
WNDCLASSEXW wcex;
90+
91+
wcex.cbSize = sizeof(WNDCLASSEX);
92+
93+
wcex.style = CS_HREDRAW | CS_VREDRAW;
94+
wcex.lpfnWndProc = WndProc;
95+
wcex.cbClsExtra = 0;
96+
wcex.cbWndExtra = 0;
97+
wcex.hInstance = hInstance;
98+
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ADVANCEDCOLORIMAGES));
99+
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
100+
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
101+
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_ADVANCEDCOLORIMAGES);
102+
wcex.lpszClassName = szWindowClass;
103+
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
104+
105+
return RegisterClassExW(&wcex);
106+
}
107+
108+
//
109+
// FUNCTION: InitInstance(HINSTANCE, int)
110+
//
111+
// PURPOSE: Saves instance handle and creates main window
112+
//
113+
// COMMENTS:
114+
//
115+
// In this function, we save the instance handle in a global variable and
116+
// create and display the main program window.
117+
//
118+
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
119+
{
120+
hInst = hInstance; // Store instance handle in our global variable
121+
122+
HWND hWndParent = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
123+
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
124+
125+
//SetWindowPos(hWndParent, HWND_TOPMOST, 0, 0, 300, 300, SWP_SHOWWINDOW);
126+
if (!hWndParent)
127+
{
128+
return FALSE;
129+
}
130+
131+
//Create the child HWND with the same size as the parent HWND, so it fills up the entire space.
132+
133+
RECT rect;
134+
::GetWindowRect(hWndParent, &rect);
135+
136+
m_childHWnd = CreateWindowW(szWindowClass, szTitle, WS_CHILD,
137+
0, 0, rect.right - rect.left, rect.bottom - rect.top,
138+
hWndParent, nullptr, hInstance, nullptr);
139+
140+
if (!m_childHWnd)
141+
{
142+
return FALSE;
143+
}
144+
m_winComp = new WinComp();
145+
// Ensure that the DispatcherQueue is initialized. This is required by the Compositor.
146+
auto controller = m_winComp->EnsureDispatcherQueue();
147+
148+
ShowWindow(hWndParent, nCmdShow);
149+
UpdateWindow(hWndParent);
150+
ShowWindow(m_childHWnd, nCmdShow);
151+
UpdateWindow(m_childHWnd);
152+
m_winComp->Initialize(m_childHWnd);
153+
m_winComp->PrepareVisuals();
154+
m_winComp->ConfigureInteraction();
155+
m_winComp->LoadImageFromFileName(L"hdr-image.jxr");
156+
m_winComp->UpdateViewPort(true);
157+
return TRUE;
158+
}
159+
160+
bool LocateImageFile(HWND hWnd, LPWSTR pszFileName, DWORD cchFileName)
161+
{
162+
pszFileName[0] = L'\0';
163+
164+
OPENFILENAME ofn;
165+
ZeroMemory(&ofn, sizeof(ofn));
166+
167+
ofn.lStructSize = sizeof(ofn);
168+
ofn.hwndOwner = hWnd;
169+
ofn.lpstrFilter = L"All Image Files\0" L"*.bmp;*.dib;*.wdp;*.mdp;*.hdp;*.gif;*.png;*.jpg;*.jpeg;*.tif;*.ico;*.jxr\0"
170+
L"JPEG File Interchange Format\0" L"*.jpg;*.jpeg\0"
171+
L"JPEG XR Extented Range Format\0" L"*.jxr\0"
172+
L"Windows Bitmap\0" L"*.bmp;*.dib\0"
173+
L"High Definition Photo\0" L"*.wdp;*.mdp;*.hdp\0"
174+
L"Graphics Interchange Format\0" L"*.gif\0"
175+
L"Portable Network Graphics\0" L"*.png\0"
176+
L"Tiff File\0" L"*.tif\0"
177+
L"Icon\0" L"*.ico\0"
178+
L"All Files\0" L"*.*\0"
179+
L"\0";
180+
ofn.lpstrFile = pszFileName;
181+
ofn.nMaxFile = cchFileName;
182+
ofn.lpstrTitle = L"Open Image";
183+
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
184+
185+
// Display the Open dialog box.
186+
return (GetOpenFileName(&ofn) == TRUE);
187+
}
188+
189+
//
190+
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
191+
//
192+
// PURPOSE: Processes messages for the main window.
193+
//
194+
// WM_COMMAND - process the application menu
195+
// WM_PAINT - Paint the main window
196+
// WM_DESTROY - post a quit message and return
197+
//
198+
//
199+
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
200+
{
201+
switch (message)
202+
{
203+
case WM_COMMAND:
204+
{
205+
int wmId = LOWORD(wParam);
206+
// Parse the menu selections:
207+
switch (wmId)
208+
{
209+
210+
case IDM_FILE:
211+
WCHAR szFileName[MAX_PATH];
212+
213+
if (LocateImageFile(hWnd, szFileName, ARRAYSIZE(szFileName)))
214+
{
215+
m_winComp->LoadImageFromFileName(szFileName);
216+
}
217+
else
218+
{
219+
MessageBox(hWnd, L"Failed to load image, select a new one.", L"Application Error", MB_ICONEXCLAMATION | MB_OK);
220+
}
221+
222+
break;
223+
224+
case IDM_ABOUT:
225+
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
226+
break;
227+
case IDM_EXIT:
228+
DestroyWindow(hWnd);
229+
break;
230+
default:
231+
return DefWindowProc(hWnd, message, wParam, lParam);
232+
}
233+
}
234+
break;
235+
case WM_POINTERDOWN:
236+
{
237+
//Redirect input events to the InteractionTracker for input events.
238+
PointerPoint pp = PointerPoint::GetCurrentPoint(GET_POINTERID_WPARAM(wParam));
239+
m_winComp->TryRedirectForManipulation(pp);
240+
break;
241+
}
242+
243+
244+
case WM_PAINT:
245+
{
246+
PAINTSTRUCT ps;
247+
HDC hdc = BeginPaint(hWnd, &ps);
248+
EndPaint(hWnd, &ps);
249+
}
250+
break;
251+
252+
case WM_SIZE:
253+
{
254+
//Update the child HWND to the new size of the parent HWnd.
255+
RECT windowRect;
256+
::GetWindowRect(hWnd, &windowRect);
257+
::SetWindowPos(m_childHWnd, HWND_TOP, 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOZORDER);
258+
if (m_winComp != nullptr)
259+
m_winComp->UpdateViewPort(true);
260+
}
261+
break;
262+
case WM_DESTROY:
263+
PostQuitMessage(0);
264+
break;
265+
default:
266+
return DefWindowProc(hWnd, message, wParam, lParam);
267+
}
268+
return 0;
269+
}
270+
271+
// Message handler for about box.
272+
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
273+
{
274+
UNREFERENCED_PARAMETER(lParam);
275+
switch (message)
276+
{
277+
case WM_INITDIALOG:
278+
return (INT_PTR)TRUE;
279+
280+
case WM_COMMAND:
281+
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
282+
{
283+
EndDialog(hDlg, LOWORD(wParam));
284+
return (INT_PTR)TRUE;
285+
}
286+
break;
287+
}
288+
return (INT_PTR)FALSE;
289+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#include "resource.h"
4+
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)