├── README.md ├── BaseWindow.sln ├── main.cpp ├── BaseWindow.vcxproj └── .gitignore /README.md: -------------------------------------------------------------------------------- 1 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 2 | 3 | This method is only supported on Windows 11 22H2 and up 4 | -------------------------------------------------------------------------------- /BaseWindow.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29123.88 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BaseWindow", "BaseWindow.vcxproj", "{BA5E5250-AD6E-4E2A-8178-0C199D298C83}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {BA5E5250-AD6E-4E2A-8178-0C199D298C83}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {BA5E5250-AD6E-4E2A-8178-0C199D298C83}.Debug|Win32.Build.0 = Debug|Win32 16 | {BA5E5250-AD6E-4E2A-8178-0C199D298C83}.Release|Win32.ActiveCfg = Release|Win32 17 | {BA5E5250-AD6E-4E2A-8178-0C199D298C83}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D90924F8-0544-4975-B386-416C7F9BA660} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #pragma comment(lib, "Dwmapi.lib") 2 | 3 | #include 4 | #include 5 | 6 | template 7 | class BaseWindow 8 | { 9 | public: 10 | static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 11 | { 12 | DERIVED_TYPE *pThis = NULL; 13 | 14 | if (uMsg == WM_NCCREATE) 15 | { 16 | CREATESTRUCT* pCreate = (CREATESTRUCT*)lParam; 17 | pThis = (DERIVED_TYPE*)pCreate->lpCreateParams; 18 | SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pThis); 19 | 20 | pThis->m_hwnd = hwnd; 21 | } 22 | else 23 | { 24 | pThis = (DERIVED_TYPE*)GetWindowLongPtr(hwnd, GWLP_USERDATA); 25 | } 26 | if (pThis) 27 | { 28 | return pThis->HandleMessage(uMsg, wParam, lParam); 29 | } 30 | else 31 | { 32 | return DefWindowProc(hwnd, uMsg, wParam, lParam); 33 | } 34 | } 35 | 36 | BaseWindow() : m_hwnd(NULL) { } 37 | 38 | BOOL Create( 39 | PCWSTR lpWindowName, 40 | DWORD dwStyle, 41 | DWORD dwExStyle = WS_EX_NOREDIRECTIONBITMAP, 42 | int x = CW_USEDEFAULT, 43 | int y = CW_USEDEFAULT, 44 | int nWidth = CW_USEDEFAULT, 45 | int nHeight = CW_USEDEFAULT, 46 | HWND hWndParent = 0, 47 | HMENU hMenu = 0 48 | ) 49 | { 50 | WNDCLASS wc = {0}; 51 | 52 | wc.lpfnWndProc = DERIVED_TYPE::WindowProc; 53 | wc.hInstance = GetModuleHandle(NULL); 54 | wc.lpszClassName = ClassName(); 55 | 56 | RegisterClass(&wc); 57 | 58 | m_hwnd = CreateWindowEx( 59 | dwExStyle, ClassName(), lpWindowName, dwStyle, x, y, 60 | nWidth, nHeight, hWndParent, hMenu, GetModuleHandle(NULL), this 61 | ); 62 | 63 | return (m_hwnd ? TRUE : FALSE); 64 | } 65 | 66 | HWND Window() const { return m_hwnd; } 67 | 68 | protected: 69 | 70 | virtual PCWSTR ClassName() const = 0; 71 | virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) = 0; 72 | 73 | HWND m_hwnd; 74 | }; 75 | 76 | 77 | class MainWindow : public BaseWindow 78 | { 79 | public: 80 | PCWSTR ClassName() const { return L"Sample Window Class"; } 81 | LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); 82 | }; 83 | 84 | 85 | int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) 86 | { 87 | MainWindow win; 88 | 89 | if (!win.Create(L"Win32 window with Mica", WS_OVERLAPPEDWINDOW)) 90 | { 91 | return 0; 92 | } 93 | 94 | ShowWindow(win.Window(), nCmdShow); 95 | 96 | // Run the message loop. 97 | 98 | MSG msg = { }; 99 | while (GetMessage(&msg, NULL, 0, 0)) 100 | { 101 | TranslateMessage(&msg); 102 | DispatchMessage(&msg); 103 | } 104 | 105 | return 0; 106 | } 107 | 108 | 109 | LRESULT MainWindow::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) 110 | { 111 | switch (uMsg) 112 | { 113 | case WM_CREATE: 114 | { 115 | // Mica 116 | BOOL value = TRUE; 117 | DwmSetWindowAttribute(m_hwnd, DWMWA_USE_HOSTBACKDROPBRUSH, &value, sizeof(value)); 118 | 119 | // DWMSBT_MAINWINDOW - mica 120 | // DWMSBT_TABBEDWINDOW - tabbed 121 | // DWMSBT_TRANSIENTWINDOW - acrylic 122 | DWM_SYSTEMBACKDROP_TYPE backdrop_type = DWMSBT_MAINWINDOW; 123 | DwmSetWindowAttribute(m_hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdrop_type, sizeof(backdrop_type)); 124 | } 125 | return 0; 126 | 127 | case WM_DESTROY: 128 | PostQuitMessage(0); 129 | return 0; 130 | 131 | default: 132 | return DefWindowProc(m_hwnd, uMsg, wParam, lParam); 133 | } 134 | return TRUE; 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /BaseWindow.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {BA5E5250-AD6E-4E2A-8178-0C199D298C83} 15 | BaseWindow 16 | Win32Proj 17 | 18 | 19 | 20 | Application 21 | v143 22 | Unicode 23 | true 24 | 25 | 26 | Application 27 | v143 28 | Unicode 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>16.0.29103.76 42 | 43 | 44 | $(SolutionDir)$(Configuration)\ 45 | $(Configuration)\ 46 | true 47 | MinimumRecommendedRules.ruleset 48 | 49 | 50 | 51 | 52 | $(SolutionDir)$(Configuration)\ 53 | $(Configuration)\ 54 | false 55 | MinimumRecommendedRules.ruleset 56 | 57 | 58 | 59 | 60 | 61 | Disabled 62 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 63 | false 64 | EnableFastChecks 65 | MultiThreadedDebugDLL 66 | 67 | Level3 68 | ProgramDatabase 69 | 70 | 71 | true 72 | Windows 73 | MachineX86 74 | 75 | 76 | 77 | 78 | MaxSpeed 79 | true 80 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 81 | MultiThreadedDLL 82 | true 83 | 84 | Level3 85 | ProgramDatabase 86 | 87 | 88 | true 89 | Windows 90 | true 91 | true 92 | MachineX86 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /.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 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 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 | # Nuget personal access tokens and Credentials 210 | # nuget.config 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd 367 | 368 | # VS Code files for those working on multiple tools 369 | .vscode/* 370 | !.vscode/settings.json 371 | !.vscode/tasks.json 372 | !.vscode/launch.json 373 | !.vscode/extensions.json 374 | *.code-workspace 375 | 376 | # Local History for Visual Studio Code 377 | .history/ 378 | 379 | # Windows Installer files from build outputs 380 | *.cab 381 | *.msi 382 | *.msix 383 | *.msm 384 | *.msp 385 | 386 | # JetBrains Rider 387 | .idea/ 388 | *.sln.iml --------------------------------------------------------------------------------