├── .gitattributes ├── .gitignore ├── AnimateBitmapLayerdChidWindow.rc ├── AnimateBitmapLayerdChidWindow.sln ├── AnimateBitmapLayerdChidWindow.vcxproj ├── AnimateBitmapLayerdChidWindow.vcxproj.filters ├── LICENSE.TXT ├── Source.cpp ├── Source.h ├── WhiteFlowers.jpg ├── manifest.xml └── resource.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /AnimateBitmapLayerdChidWindow.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/AnimateBitmapLayerdChidWindow/c1c0a3fe332b223928d9f4b904c6e32e7eacb48b/AnimateBitmapLayerdChidWindow.rc -------------------------------------------------------------------------------- /AnimateBitmapLayerdChidWindow.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25123.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AnimateBitmapLayerdChidWindow", "AnimateBitmapLayerdChidWindow.vcxproj", "{D327119E-D676-4F87-B0AF-08D64AE6AC1A}" 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 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x64.ActiveCfg = Debug|x64 17 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x64.Build.0 = Debug|x64 18 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Debug|x86.Build.0 = Debug|Win32 20 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x64.ActiveCfg = Release|x64 21 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x64.Build.0 = Release|x64 22 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x86.ActiveCfg = Release|Win32 23 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /AnimateBitmapLayerdChidWindow.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {D327119E-D676-4F87-B0AF-08D64AE6AC1A} 23 | Win32Proj 24 | AnimateBitmapLayerdChidWindow 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v142 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v142 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v142 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v142 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | false 75 | 76 | 77 | true 78 | false 79 | 80 | 81 | false 82 | false 83 | 84 | 85 | false 86 | false 87 | 88 | 89 | 90 | 91 | 92 | Level3 93 | Disabled 94 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 95 | MultiThreadedDebug 96 | 97 | 98 | Windows 99 | true 100 | 101 | 102 | false 103 | 104 | 105 | 106 | 107 | 108 | 109 | Level3 110 | Disabled 111 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions) 112 | MultiThreadedDebug 113 | 114 | 115 | Windows 116 | true 117 | 118 | 119 | false 120 | 121 | 122 | 123 | 124 | Level3 125 | 126 | 127 | MaxSpeed 128 | true 129 | true 130 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 131 | MultiThreaded 132 | 133 | 134 | Windows 135 | true 136 | true 137 | No 138 | 139 | 140 | false 141 | 142 | 143 | 144 | 145 | Level3 146 | 147 | 148 | MaxSpeed 149 | true 150 | true 151 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 152 | MultiThreaded 153 | 154 | 155 | Windows 156 | true 157 | true 158 | No 159 | 160 | 161 | false 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /AnimateBitmapLayerdChidWindow.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | ソース ファイル 20 | 21 | 22 | 23 | 24 | ヘッダー ファイル 25 | 26 | 27 | ヘッダー ファイル 28 | 29 | 30 | 31 | 32 | リソース ファイル 33 | 34 | 35 | 36 | 37 | リソース ファイル 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /LICENSE.TXT: -------------------------------------------------------------------------------- 1 | MIT License (MIT) 2 | 3 | Copyright (c) 2021 kenjinote (hack.jp) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Source.cpp: -------------------------------------------------------------------------------- 1 | //#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 2 | 3 | #pragma comment(lib, "D2d1.lib") 4 | #pragma comment(lib, "Dcomp.lib") 5 | #pragma comment(lib, "Dwmapi.lib") 6 | 7 | // 8 | // AnimateLayeredChildWindow.cpp 9 | // 10 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 11 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 12 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 13 | // PARTICULAR PURPOSE. 14 | // 15 | // Copyright (c) Microsoft Corporation. All rights reserved 16 | 17 | // Instructions: Click the thumnail image to animate the transition 18 | // of the child window from thumbsize to fullsize. Click the child 19 | // window again to reset. 20 | 21 | #include "Source.h" 22 | 23 | #define TIMER_ID 100 24 | 25 | /****************************************************************** 26 | * * 27 | * The application entry point. * 28 | * * 29 | ******************************************************************/ 30 | 31 | int WINAPI WinMain( 32 | HINSTANCE /* hInstance */, 33 | HINSTANCE /* hPrevInstance */, 34 | LPSTR /* lpCmdLine */, 35 | int /* nCmdShow */ 36 | ) 37 | { 38 | // Ignore the return value because we want to run the program even in the 39 | // unlikely event that HeapSetInformation fails. 40 | //HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); 41 | if (SUCCEEDED(CoInitialize(NULL))) 42 | { 43 | { 44 | DemoApp app; 45 | 46 | if (SUCCEEDED(app.InitializeMainWindow()) && SUCCEEDED(app.InitializeLayeredChildWindow())) 47 | { 48 | app.RunMessageLoop(); 49 | } 50 | } 51 | CoUninitialize(); 52 | } 53 | 54 | return 0; 55 | } 56 | 57 | /****************************************************************** 58 | * * 59 | * DemoApp::DemoApp constructor * 60 | * * 61 | * Initialize member data. * 62 | * * 63 | ******************************************************************/ 64 | 65 | DemoApp::DemoApp() : 66 | m_dpiX(0), 67 | m_dpiY(0), 68 | m_childOffsetX(20), 69 | m_childOffsetY(40), 70 | m_hwndMain(NULL), 71 | m_hwndLayeredChild(NULL), 72 | m_pDevice(NULL), 73 | m_pCompTarget(NULL), 74 | m_pRenderTarget(NULL), 75 | m_pBitmap(NULL), 76 | m_pD2DFactory(NULL), 77 | m_pWICFactory(NULL) 78 | { 79 | } 80 | 81 | /****************************************************************** 82 | * * 83 | * Release resources. * 84 | * * 85 | ******************************************************************/ 86 | 87 | DemoApp::~DemoApp() 88 | { 89 | SafeRelease(&m_pDevice); 90 | SafeRelease(&m_pCompTarget); 91 | SafeRelease(&m_pRenderTarget); 92 | SafeRelease(&m_pBitmap), 93 | SafeRelease(&m_pD2DFactory); 94 | SafeRelease(&m_pWICFactory); 95 | } 96 | 97 | /******************************************************************* 98 | * * 99 | * Create the application window. * 100 | * * 101 | *******************************************************************/ 102 | 103 | HRESULT DemoApp::InitializeMainWindow() 104 | { 105 | HRESULT hr = S_OK; 106 | 107 | // Initialize device-independent resources, such 108 | // as the Direct2D factory. 109 | hr = CreateDeviceIndependentResources(); 110 | if (SUCCEEDED(hr)) 111 | { 112 | // Register the main window class. 113 | WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; 114 | wcex.style = 0; 115 | wcex.lpfnWndProc = DemoApp::MainWndProc; 116 | wcex.cbClsExtra = 0; 117 | wcex.cbWndExtra = sizeof(LONG_PTR); 118 | wcex.hInstance = HINST_THISCOMPONENT; 119 | wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 120 | wcex.lpszMenuName = NULL; 121 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 122 | wcex.lpszClassName = L"DirectCompDemoApp"; 123 | 124 | RegisterClassEx(&wcex); 125 | 126 | RECT rect = { }; 127 | SetRect(&rect, 0, 0, 640, 480); 128 | AdjustWindowRect(&rect, WS_OVERLAPPED | WS_SYSMENU, FALSE); 129 | 130 | // Create the main application window. 131 | // 132 | 133 | // Because the CreateWindow function takes its size in pixels, we 134 | // obtain the system DPI and use it to scale the window size. 135 | HDC hdc = GetDC(NULL); 136 | if (hdc) 137 | { 138 | m_dpiX = GetDeviceCaps(hdc, LOGPIXELSX); 139 | m_dpiY = GetDeviceCaps(hdc, LOGPIXELSY); 140 | ReleaseDC(NULL, hdc); 141 | } 142 | 143 | float width = static_cast(rect.right - rect.left); 144 | float height = static_cast(rect.bottom - rect.top); 145 | 146 | m_hwndMain = CreateWindow( 147 | L"DirectCompDemoApp", 148 | L"DirectComposition Demo Application", 149 | WS_OVERLAPPED | WS_SYSMENU, 150 | CW_USEDEFAULT, 151 | CW_USEDEFAULT, 152 | static_cast(ceil(width * m_dpiX / 96.f)), 153 | static_cast(ceil(height * m_dpiY / 96.f)), 154 | NULL, 155 | NULL, 156 | HINST_THISCOMPONENT, 157 | this 158 | ); 159 | } 160 | 161 | hr = m_hwndMain ? S_OK : E_FAIL; 162 | if (SUCCEEDED(hr)) 163 | { 164 | // Create and initialize the DirectCompositoin objects. 165 | hr = InitializeDirectCompositionObjects(); 166 | } 167 | 168 | if (SUCCEEDED(hr)) 169 | { 170 | ShowWindow(m_hwndMain, SW_SHOWNORMAL); 171 | UpdateWindow(m_hwndMain); 172 | } 173 | 174 | return hr; 175 | } 176 | 177 | /******************************************************************* 178 | * * 179 | * Create the layered child window. * 180 | * * 181 | /******************************************************************/ 182 | 183 | HRESULT DemoApp::InitializeLayeredChildWindow() 184 | { 185 | int thumbWidth = 48; 186 | int thumbHeight = 32; 187 | 188 | HRESULT hr = S_OK; 189 | 190 | WNDCLASSEXW wcex; 191 | wcex.cbSize = sizeof(wcex); 192 | wcex.style = 0; 193 | wcex.lpfnWndProc = DemoApp::ChildWndProc; 194 | wcex.cbClsExtra = 0; 195 | wcex.cbWndExtra = 0; 196 | wcex.hInstance = HINST_THISCOMPONENT; 197 | wcex.hIcon = NULL; 198 | wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 199 | wcex.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); 200 | wcex.lpszMenuName = NULL; 201 | wcex.lpszClassName = L"DCompLayeredChildWindow"; 202 | wcex.hIconSm = NULL; 203 | 204 | if (!RegisterClassExW(&wcex)) 205 | { 206 | return FALSE; 207 | } 208 | 209 | m_hwndLayeredChild = CreateWindowEx(WS_EX_LAYERED, 210 | L"DCompLayeredChildWindow", 211 | NULL, 212 | WS_CHILD | WS_CLIPSIBLINGS, 213 | 0, 214 | 0, 215 | static_cast(ceil(640.0f * m_dpiX / 96.0f)), 216 | static_cast(ceil(480.0f * m_dpiY / 96.0f)), 217 | m_hwndMain, 218 | NULL, 219 | HINST_THISCOMPONENT, 220 | this); 221 | 222 | hr = m_hwndLayeredChild ? S_OK : E_FAIL; 223 | if (SUCCEEDED(hr)) 224 | { 225 | // Set the opacity and transparency color key of the layered 226 | // child window. 227 | if (!SetLayeredWindowAttributes(m_hwndLayeredChild, 0, 255, LWA_ALPHA)) 228 | { 229 | hr = HRESULT_FROM_WIN32(GetLastError()); 230 | } 231 | } 232 | 233 | if (SUCCEEDED(hr)) 234 | { 235 | // While the child window is fullsize, load the bitmap resource and 236 | // render it to the child window. 237 | hr = CreateDeviceResources(); 238 | } 239 | 240 | if (SUCCEEDED(hr)) 241 | { 242 | // Reduce the window to thumbsize. 243 | MoveWindow(m_hwndLayeredChild, m_childOffsetX, m_childOffsetY, 244 | thumbWidth, thumbHeight, TRUE); 245 | ShowWindow(m_hwndLayeredChild, SW_SHOWNORMAL); 246 | UpdateWindow(m_hwndLayeredChild); 247 | } 248 | 249 | return hr; 250 | } 251 | 252 | /****************************************************************** 253 | * * 254 | * This method creates the DirectComposition device object and * 255 | * and the composition target object. These objects endure for * 256 | * the lifetime of the application. * 257 | * * 258 | ******************************************************************/ 259 | 260 | HRESULT DemoApp::InitializeDirectCompositionObjects() 261 | { 262 | HRESULT hr = S_OK; 263 | 264 | // Create a DirectComposition device object. 265 | hr = DCompositionCreateDevice(nullptr, __uuidof(IDCompositionDevice), 266 | reinterpret_cast(&m_pDevice)); 267 | 268 | if (SUCCEEDED(hr)) 269 | { 270 | // Create the composition target object. 271 | hr = m_pDevice->CreateTargetForHwnd(m_hwndMain, TRUE, &m_pCompTarget); 272 | } 273 | 274 | return hr; 275 | } 276 | 277 | 278 | /****************************************************************** 279 | * * 280 | * This method is used to create resources which are not bound * 281 | * to any device. Their lifetime effectively extends for the * 282 | * duration of the app. * 283 | * * 284 | ******************************************************************/ 285 | 286 | HRESULT DemoApp::CreateDeviceIndependentResources() 287 | { 288 | HRESULT hr = CoCreateInstance( 289 | CLSID_WICImagingFactory, 290 | NULL, 291 | CLSCTX_INPROC_SERVER, 292 | IID_PPV_ARGS(&m_pWICFactory) 293 | ); 294 | 295 | if (SUCCEEDED(hr)) 296 | { 297 | // Create a Direct2D factory. 298 | hr = D2D1CreateFactory( 299 | D2D1_FACTORY_TYPE_SINGLE_THREADED, 300 | &m_pD2DFactory 301 | ); 302 | } 303 | 304 | return hr; 305 | } 306 | 307 | /****************************************************************** 308 | * * 309 | * This method creates the D2D bitmap that the application gives * 310 | * to DirectComposition to be composed. * 311 | * * 312 | ******************************************************************/ 313 | 314 | HRESULT DemoApp::CreateDeviceResources() 315 | { 316 | HRESULT hr = S_OK; 317 | 318 | RECT rc; 319 | GetClientRect(m_hwndLayeredChild, &rc); 320 | 321 | D2D1_SIZE_U size = D2D1::SizeU( 322 | rc.right - rc.left, 323 | rc.bottom - rc.top 324 | ); 325 | 326 | // Create a Direct2D render target. 327 | hr = m_pD2DFactory->CreateHwndRenderTarget( 328 | D2D1::RenderTargetProperties(), 329 | D2D1::HwndRenderTargetProperties(m_hwndLayeredChild, size), 330 | &m_pRenderTarget 331 | ); 332 | 333 | if (SUCCEEDED(hr)) 334 | { 335 | hr = LoadResourceD2DBitmap( 336 | m_pRenderTarget, 337 | m_pWICFactory, 338 | L"WHITEFLOWERS", 339 | L"IMAGE", 340 | &m_pBitmap 341 | ); 342 | } 343 | 344 | return hr; 345 | } 346 | 347 | /****************************************************************** 348 | * * 349 | * Discard device-specific resources. * 350 | * * 351 | ******************************************************************/ 352 | 353 | void DemoApp::DiscardDeviceResources() 354 | { 355 | SafeRelease(&m_pRenderTarget); 356 | SafeRelease(&m_pBitmap); 357 | } 358 | 359 | /****************************************************************** 360 | * * 361 | * The main window's message loop. * 362 | * * 363 | ******************************************************************/ 364 | 365 | void DemoApp::RunMessageLoop() 366 | { 367 | MSG msg; 368 | 369 | while (GetMessage(&msg, NULL, 0, 0)) 370 | { 371 | TranslateMessage(&msg); 372 | DispatchMessage(&msg); 373 | } 374 | } 375 | 376 | /****************************************************************** 377 | * * 378 | * The main window's message handler. * 379 | * * 380 | ******************************************************************/ 381 | 382 | LRESULT CALLBACK DemoApp::MainWndProc(HWND hwnd, UINT message, 383 | WPARAM wParam, LPARAM lParam) 384 | { 385 | LRESULT result = 0; 386 | 387 | if (message == WM_CREATE) 388 | { 389 | LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; 390 | DemoApp *pDemoApp = (DemoApp *)pcs->lpCreateParams; 391 | 392 | ::SetWindowLongPtrW( 393 | hwnd, 394 | GWLP_USERDATA, 395 | (LONG_PTR)pDemoApp 396 | ); 397 | 398 | result = 1; 399 | } 400 | else 401 | { 402 | DemoApp *pDemoApp = (DemoApp*)GetWindowLongPtrW( 403 | hwnd, 404 | GWLP_USERDATA 405 | ); 406 | 407 | bool wasHandled = false; 408 | 409 | if (pDemoApp) 410 | { 411 | switch (message) 412 | { 413 | 414 | case WM_DISPLAYCHANGE: 415 | { 416 | InvalidateRect(hwnd, NULL, FALSE); 417 | } 418 | wasHandled = true; 419 | result = 0; 420 | break; 421 | 422 | case WM_DESTROY: 423 | { 424 | PostQuitMessage(0); 425 | pDemoApp->DiscardDeviceResources(); 426 | } 427 | wasHandled = true; 428 | result = 1; 429 | break; 430 | } 431 | } 432 | 433 | if (!wasHandled) 434 | { 435 | result = DefWindowProc(hwnd, message, wParam, lParam); 436 | } 437 | } 438 | 439 | return result; 440 | } 441 | 442 | /****************************************************************** 443 | * * 444 | * The layered child window's message handler. * 445 | * * 446 | ******************************************************************/ 447 | 448 | LRESULT CALLBACK DemoApp::ChildWndProc(HWND hwnd, UINT message, 449 | WPARAM wParam, LPARAM lParam) 450 | { 451 | LRESULT result = 0; 452 | 453 | if (message == WM_CREATE) 454 | { 455 | LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam; 456 | DemoApp *pDemoApp = (DemoApp *)pcs->lpCreateParams; 457 | 458 | ::SetWindowLongPtrW( 459 | hwnd, 460 | GWLP_USERDATA, 461 | (LONG_PTR)pDemoApp 462 | ); 463 | 464 | result = 1; 465 | } 466 | else 467 | { 468 | DemoApp *pDemoApp = (DemoApp *)GetWindowLongPtrW( 469 | hwnd, 470 | GWLP_USERDATA 471 | ); 472 | 473 | bool wasHandled = false; 474 | 475 | if (pDemoApp) 476 | { 477 | switch (message) 478 | { 479 | case WM_PAINT: 480 | { 481 | pDemoApp->OnChildRender(); 482 | ValidateRect(hwnd, NULL); 483 | } 484 | wasHandled = true; 485 | result = 0; 486 | break; 487 | 488 | case WM_LBUTTONDOWN: 489 | { 490 | HRESULT hr = S_OK; 491 | static BOOL fThumbsize = TRUE; 492 | 493 | // If the child window is already fullsize, reset 494 | // the visual tree and return the child window 495 | // to thumbsize and move it to its initial location. 496 | if (!fThumbsize) 497 | { 498 | pDemoApp->m_pCompTarget->SetRoot(NULL); 499 | hr = pDemoApp->m_pDevice->Commit(); 500 | 501 | MoveWindow(pDemoApp->m_hwndLayeredChild, 502 | pDemoApp->m_childOffsetX, 503 | pDemoApp->m_childOffsetY, 48, 32, TRUE); 504 | 505 | pDemoApp->OnChildRender(); 506 | } 507 | else 508 | { 509 | // Cloak the child window. 510 | BOOL fCloak = TRUE; 511 | DwmSetWindowAttribute(pDemoApp->m_hwndLayeredChild, 512 | DWMWA_CLOAK, 513 | &fCloak, 514 | sizeof(fCloak)); 515 | 516 | pDemoApp->OnChildClick(); 517 | } 518 | fThumbsize = !fThumbsize; 519 | } 520 | wasHandled = true; 521 | result = 0; 522 | break; 523 | 524 | case WM_TIMER: 525 | { 526 | // Uncloak the child window. 527 | BOOL fCloak = FALSE; 528 | DwmSetWindowAttribute(pDemoApp->m_hwndLayeredChild, 529 | DWMWA_CLOAK, 530 | &fCloak, 531 | sizeof(fCloak)); 532 | KillTimer(pDemoApp->m_hwndLayeredChild, TIMER_ID); 533 | } 534 | wasHandled = true; 535 | result = 0; 536 | break; 537 | } 538 | } 539 | 540 | if (!wasHandled) 541 | { 542 | result = DefWindowProc(hwnd, message, wParam, lParam); 543 | } 544 | } 545 | 546 | return result; 547 | } 548 | 549 | 550 | /****************************************************************** 551 | * * 552 | * Draws a bitmap in the layered child window. * 553 | * * 554 | ******************************************************************/ 555 | 556 | HRESULT DemoApp::OnChildRender() 557 | { 558 | HRESULT hr = S_OK; 559 | 560 | // Retrieve the size of the render target. 561 | D2D1_SIZE_F size = m_pRenderTarget->GetSize(); 562 | 563 | m_pRenderTarget->BeginDraw(); 564 | 565 | // Draw a bitmap scaled to fill the window. 566 | m_pRenderTarget->DrawBitmap( 567 | m_pBitmap, 568 | D2D1::RectF(0.0f, 0.0f, size.width, size.height) 569 | ); 570 | 571 | hr = m_pRenderTarget->EndDraw(); 572 | 573 | if (hr == D2DERR_RECREATE_TARGET) 574 | { 575 | hr = S_OK; 576 | DiscardDeviceResources(); 577 | } 578 | 579 | return hr; 580 | } 581 | 582 | /****************************************************************** 583 | * * 584 | * Handles a mouse click in the layered child window by animating * 585 | * the transition from a thumbsize window to a fullsize window. * 586 | * * 587 | ******************************************************************/ 588 | 589 | HRESULT DemoApp::OnChildClick() 590 | { 591 | int fullWidth = 640; 592 | int fullHeight = 480; 593 | HRESULT hr = S_OK; 594 | 595 | IDCompositionVisual *pVisual = nullptr; 596 | IUnknown* pSurface = nullptr; 597 | 598 | hr = m_pDevice->CreateVisual(&pVisual); 599 | if (SUCCEEDED(hr)) 600 | { 601 | hr = m_pDevice->CreateSurfaceFromHwnd(m_hwndLayeredChild, &pSurface); 602 | } 603 | 604 | if (SUCCEEDED(hr)) 605 | { 606 | hr = pVisual->SetContent(pSurface); 607 | } 608 | 609 | if (SUCCEEDED(hr)) 610 | { 611 | hr = m_pCompTarget->SetRoot(pVisual); 612 | } 613 | 614 | if (SUCCEEDED(hr)) 615 | { 616 | // Position the visual at the same location as the 617 | // the child window. 618 | hr = pVisual->SetOffsetX(static_cast(m_childOffsetX)); 619 | if (SUCCEEDED(hr)) 620 | { 621 | hr = pVisual->SetOffsetY(static_cast(m_childOffsetY)); 622 | } 623 | } 624 | 625 | IDCompositionAnimation *pAnimateX = NULL; 626 | IDCompositionAnimation *pAnimateY = NULL; 627 | 628 | if (SUCCEEDED(hr)) 629 | { 630 | // Create the animation objects. 631 | hr = m_pDevice->CreateAnimation(&pAnimateX); 632 | if (SUCCEEDED(hr)) 633 | { 634 | hr = m_pDevice->CreateAnimation(&pAnimateY); 635 | } 636 | } 637 | 638 | IDCompositionAnimation *pAnimateScale = NULL; 639 | IDCompositionScaleTransform *pScale = NULL; 640 | 641 | if (SUCCEEDED(hr)) 642 | { 643 | hr = m_pDevice->CreateAnimation(&pAnimateScale); 644 | } 645 | 646 | if (SUCCEEDED(hr)) 647 | { 648 | // Create the scale transform object. 649 | hr = m_pDevice->CreateScaleTransform(&pScale); 650 | } 651 | 652 | if (SUCCEEDED(hr)) 653 | { 654 | // Calculate the X and Y offsets that will position the child window 655 | // in the center of the main window's client area. 656 | RECT rcParent = { }; 657 | RECT rcChild = { }; 658 | GetClientRect(m_hwndMain, &rcParent); 659 | GetClientRect(m_hwndLayeredChild, &rcChild); 660 | float endValX = rcParent.right / 2.0f - rcChild.right / 2.0f; 661 | float endValY = rcParent.bottom / 2.0f - rcChild.bottom / 2.0f; 662 | 663 | // Build the animation functions that will move the visual to the 664 | // center of the main window's client area. 665 | pAnimateX->AddCubic( 666 | 0.0f, 667 | static_cast(m_childOffsetX), 668 | endValX - m_childOffsetX, 669 | 0.0f, 670 | 0.0f); 671 | pAnimateX->End(0.9f, endValX); 672 | 673 | pAnimateY->AddCubic( 674 | 0.0f, 675 | static_cast(m_childOffsetY), 676 | endValY - m_childOffsetY, 677 | 0.0f, 678 | 0.0f); 679 | pAnimateY->End(0.9f, endValY); 680 | 681 | // Associate the animation objects with the offset properties of 682 | // the visual. 683 | hr = pVisual->SetOffsetX(pAnimateX); 684 | if (SUCCEEDED(hr)) 685 | { 686 | hr = pVisual->SetOffsetY(pAnimateY); 687 | } 688 | } 689 | 690 | if (SUCCEEDED(hr)) 691 | { 692 | // Commit the visual tree. 693 | hr = m_pDevice->Commit(); 694 | 695 | // Give the animation a chance to run. 696 | Sleep(900); 697 | } 698 | 699 | if (SUCCEEDED(hr)) 700 | { 701 | // Align the visual with the upper-left corner of the 702 | // parent window's client area. 703 | pVisual->SetOffsetX(0.0); 704 | pVisual->SetOffsetY(0.0); 705 | 706 | // Enlarge the child window to fill the main window. 707 | if (!MoveWindow(m_hwndLayeredChild, 0, 0, fullWidth, fullHeight, TRUE)) 708 | { 709 | hr = HRESULT_FROM_WIN32(GetLastError()); 710 | } 711 | } 712 | 713 | if (SUCCEEDED(hr)) 714 | { 715 | // Add animation primitives that define the animation object function 716 | // used to scale up the child window's bitmap. 717 | pAnimateScale->AddCubic( 718 | 0.0f, // offset from beginning of animation function, in seconds 719 | 0.0f, // constant coefficient 720 | 1.0f, // linear coefficient 721 | 0.0f, // quadratic coefficient 722 | 0.0f); // cubic coefficient 723 | pAnimateScale->End(1.0f, 1.0f); 724 | 725 | // Find the center of the child window. 726 | RECT rcChild = { }; 727 | GetClientRect(m_hwndLayeredChild, &rcChild); 728 | float centerX = rcChild.right / 2.0f; 729 | float centerY = rcChild.bottom / 2.0f; 730 | 731 | // Scale from the center point of the child window's bitmap. 732 | pScale->SetCenterX(centerX); 733 | pScale->SetCenterY(centerY); 734 | 735 | // Use the same animation object to animate the X and Y scale 736 | // factors. 737 | pScale->SetScaleX(pAnimateScale); 738 | pScale->SetScaleY(pAnimateScale); 739 | 740 | // Set the Transform property of the visual to use the scale 741 | // transform. 742 | hr = pVisual->SetTransform(pScale); 743 | } 744 | 745 | if (SUCCEEDED(hr)) 746 | { // Commit the visual tree. 747 | hr = m_pDevice->Commit(); 748 | 749 | // Use a WM_TIMER message in the child window procedure 750 | // to uncloak the child window. 751 | SetTimer(m_hwndLayeredChild, TIMER_ID, 1000, NULL); 752 | } 753 | 754 | SafeRelease(&pAnimateX); 755 | SafeRelease(&pAnimateY); 756 | SafeRelease(&pVisual); 757 | SafeRelease(&pAnimateScale); 758 | SafeRelease(&pScale); 759 | 760 | return hr; 761 | } 762 | 763 | 764 | /****************************************************************** 765 | * * 766 | * This method will create a Direct2D bitmap from an application * 767 | * resource. * 768 | * * 769 | ******************************************************************/ 770 | 771 | HRESULT DemoApp::LoadResourceD2DBitmap( 772 | ID2D1RenderTarget *pRenderTarget, 773 | IWICImagingFactory *pIWICFactory, 774 | PCWSTR resourceName, 775 | PCWSTR resourceType, 776 | ID2D1Bitmap **ppBitmap 777 | ) 778 | { 779 | HRESULT hr = S_OK; 780 | IWICBitmapDecoder *pDecoder = NULL; 781 | IWICBitmapFrameDecode *pSource = NULL; 782 | IWICStream *pStream = NULL; 783 | IWICFormatConverter *pConverter = NULL; 784 | 785 | HRSRC imageResHandle = NULL; 786 | HGLOBAL imageResDataHandle = NULL; 787 | void *pImageFile = NULL; 788 | DWORD imageFileSize = 0; 789 | 790 | // Locate the resource. 791 | imageResHandle = FindResourceW(HINST_THISCOMPONENT, resourceName, resourceType); 792 | 793 | hr = imageResHandle ? S_OK : E_FAIL; 794 | if (SUCCEEDED(hr)) 795 | { 796 | // Load the resource. 797 | imageResDataHandle = LoadResource(HINST_THISCOMPONENT, imageResHandle); 798 | 799 | hr = imageResDataHandle ? S_OK : E_FAIL; 800 | } 801 | 802 | if (SUCCEEDED(hr)) 803 | { 804 | // Lock it to get a system memory pointer. 805 | pImageFile = LockResource(imageResDataHandle); 806 | 807 | hr = pImageFile ? S_OK : E_FAIL; 808 | } 809 | 810 | if (SUCCEEDED(hr)) 811 | { 812 | // Calculate the size. 813 | imageFileSize = SizeofResource(HINST_THISCOMPONENT, imageResHandle); 814 | 815 | hr = imageFileSize ? S_OK : E_FAIL; 816 | } 817 | 818 | if (SUCCEEDED(hr)) 819 | { 820 | // Create a WIC stream to map onto the memory. 821 | hr = pIWICFactory->CreateStream(&pStream); 822 | } 823 | 824 | if (SUCCEEDED(hr)) 825 | { 826 | // Initialize the stream with the memory pointer and size. 827 | hr = pStream->InitializeFromMemory( 828 | reinterpret_cast(pImageFile), 829 | imageFileSize 830 | ); 831 | } 832 | 833 | if (SUCCEEDED(hr)) 834 | { 835 | // Create a decoder for the stream. 836 | hr = pIWICFactory->CreateDecoderFromStream( 837 | pStream, 838 | NULL, 839 | WICDecodeMetadataCacheOnLoad, 840 | &pDecoder 841 | ); 842 | } 843 | 844 | if (SUCCEEDED(hr)) 845 | { 846 | // Create the initial frame. 847 | hr = pDecoder->GetFrame(0, &pSource); 848 | } 849 | 850 | if (SUCCEEDED(hr)) 851 | { 852 | // Convert the image format to 32bppPBGRA 853 | // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED). 854 | hr = pIWICFactory->CreateFormatConverter(&pConverter); 855 | } 856 | 857 | if (SUCCEEDED(hr)) 858 | { 859 | hr = pConverter->Initialize( 860 | pSource, 861 | GUID_WICPixelFormat32bppPBGRA, 862 | WICBitmapDitherTypeNone, 863 | NULL, 864 | 0.f, 865 | WICBitmapPaletteTypeMedianCut 866 | ); 867 | } 868 | 869 | if (SUCCEEDED(hr)) 870 | { 871 | // Create a Direct2D bitmap from the WIC bitmap. 872 | hr = pRenderTarget->CreateBitmapFromWicBitmap( 873 | pConverter, 874 | NULL, 875 | ppBitmap 876 | ); 877 | } 878 | 879 | SafeRelease(&pDecoder); 880 | SafeRelease(&pSource); 881 | SafeRelease(&pStream); 882 | SafeRelease(&pConverter); 883 | 884 | return hr; 885 | } -------------------------------------------------------------------------------- /Source.h: -------------------------------------------------------------------------------- 1 | // 2 | // AnimateLayeredChildWindow.h 3 | // 4 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 5 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 6 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 7 | // PARTICULAR PURPOSE. 8 | // 9 | // Copyright (c) Microsoft Corporation. All rights reserved 10 | 11 | #pragma once 12 | 13 | #define _WIN32_WINNT 0x06000000 14 | // Modify the following definitions if you need to target a platform prior to the ones specified below. 15 | // Refer to MSDN for the latest info on corresponding values for different platforms. 16 | #ifndef WINVER // Allow use of features specific to Windows 7 or later. 17 | #define WINVER 0x0700 // Change this to the appropriate value to target other versions of Windows. 18 | #endif 19 | 20 | #ifndef _WIN32_WINNT // Allow use of features specific to Windows 7 or later. 21 | #define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows. 22 | #endif 23 | 24 | #ifndef UNICODE 25 | #define UNICODE 26 | #endif 27 | 28 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used items from Windows headers 29 | 30 | // Windows Header Files: 31 | #include 32 | #include 33 | 34 | // C RunTime Header Files 35 | #include 36 | 37 | // DirectComposition Header File 38 | #include 39 | 40 | // Direct2D Header Files 41 | #include 42 | #include 43 | 44 | // Desktop Window Manager (DWM) Header File 45 | #include 46 | 47 | 48 | /****************************************************************** 49 | * * 50 | * Macros * 51 | * * 52 | ******************************************************************/ 53 | template 54 | inline void 55 | SafeRelease( 56 | Interface** ppInterfaceToRelease 57 | ) 58 | { 59 | if (*ppInterfaceToRelease != NULL) 60 | { 61 | (*ppInterfaceToRelease)->Release(); 62 | 63 | (*ppInterfaceToRelease) = NULL; 64 | } 65 | } 66 | 67 | #ifndef HINST_THISCOMPONENT 68 | EXTERN_C IMAGE_DOS_HEADER __ImageBase; 69 | #define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) 70 | #endif 71 | 72 | /****************************************************************** 73 | * * 74 | * DemoApp * 75 | * * 76 | ******************************************************************/ 77 | 78 | class DemoApp 79 | { 80 | public: 81 | DemoApp(); 82 | ~DemoApp(); 83 | 84 | HRESULT InitializeMainWindow(); 85 | HRESULT InitializeLayeredChildWindow(); 86 | 87 | void RunMessageLoop(); 88 | 89 | private: 90 | HRESULT InitializeDirectCompositionObjects(); 91 | 92 | HRESULT CreateDeviceIndependentResources(); 93 | HRESULT CreateDeviceResources(); 94 | void DiscardDeviceResources(); 95 | 96 | HRESULT OnChildClick(); 97 | HRESULT OnChildRender(); 98 | 99 | HRESULT LoadResourceD2DBitmap( 100 | ID2D1RenderTarget* pRenderTarget, 101 | IWICImagingFactory* pIWICFactory, 102 | PCWSTR resourceName, 103 | PCWSTR resourceType, 104 | ID2D1Bitmap** ppBitmap 105 | ); 106 | 107 | static LRESULT CALLBACK MainWndProc( 108 | HWND hWnd, 109 | UINT message, 110 | WPARAM wParam, 111 | LPARAM lParam 112 | ); 113 | 114 | static LRESULT CALLBACK ChildWndProc( 115 | HWND hWnd, 116 | UINT message, 117 | WPARAM wParam, 118 | LPARAM lParam 119 | ); 120 | 121 | private: 122 | int m_dpiX; 123 | int m_dpiY; 124 | int m_childOffsetX; 125 | int m_childOffsetY; 126 | 127 | HWND m_hwndMain; 128 | HWND m_hwndLayeredChild; 129 | 130 | IDCompositionDevice* m_pDevice; 131 | IDCompositionTarget* m_pCompTarget; 132 | ID2D1HwndRenderTarget* m_pRenderTarget; 133 | ID2D1Factory* m_pD2DFactory; 134 | ID2D1Bitmap* m_pBitmap; 135 | IWICImagingFactory* m_pWICFactory; 136 | 137 | }; 138 | -------------------------------------------------------------------------------- /WhiteFlowers.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/AnimateBitmapLayerdChidWindow/c1c0a3fe332b223928d9f4b904c6e32e7eacb48b/WhiteFlowers.jpg -------------------------------------------------------------------------------- /manifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 27 | 28 | 29 | 30 | 31 | true 32 | PerMonitorV2 33 | 34 | 35 | -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/AnimateBitmapLayerdChidWindow/c1c0a3fe332b223928d9f4b904c6e32e7eacb48b/resource.h --------------------------------------------------------------------------------