├── back.png ├── icon.ico ├── koma1.png ├── koma2.png ├── koma3.png ├── koma4.png ├── koma5.png ├── koma6.png ├── koma7.png ├── koma8.png ├── koma9.png ├── koma10.png ├── koma11.png ├── koma12.png ├── resource.h ├── installer.ism ├── hakoirimusume.rc ├── privacy.md ├── LICENSE.TXT ├── hakoirimusume.sln ├── README.md ├── hakoirimusume.vcxproj.filters ├── .gitattributes ├── .gitignore ├── hakoirimusume.vcxproj └── Source.cpp /back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/back.png -------------------------------------------------------------------------------- /icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/icon.ico -------------------------------------------------------------------------------- /koma1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma1.png -------------------------------------------------------------------------------- /koma2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma2.png -------------------------------------------------------------------------------- /koma3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma3.png -------------------------------------------------------------------------------- /koma4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma4.png -------------------------------------------------------------------------------- /koma5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma5.png -------------------------------------------------------------------------------- /koma6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma6.png -------------------------------------------------------------------------------- /koma7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma7.png -------------------------------------------------------------------------------- /koma8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma8.png -------------------------------------------------------------------------------- /koma9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma9.png -------------------------------------------------------------------------------- /koma10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma10.png -------------------------------------------------------------------------------- /koma11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma11.png -------------------------------------------------------------------------------- /koma12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/koma12.png -------------------------------------------------------------------------------- /resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/resource.h -------------------------------------------------------------------------------- /installer.ism: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/installer.ism -------------------------------------------------------------------------------- /hakoirimusume.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjinote/hakoirimusume/HEAD/hakoirimusume.rc -------------------------------------------------------------------------------- /privacy.md: -------------------------------------------------------------------------------- 1 | ## Privacy Policy 2 | 3 | The app "Hakoiri Musume" respects your privacy and is designed to be used safely and securely without collecting any personal data. 4 | 5 | --- 6 | 7 | ### 1. Data Collection 8 | 9 | This app **does not collect, store, or transmit any user data**, including but not limited to: 10 | 11 | - Personal information such as name, address, phone number, or email 12 | - Gameplay history or progress 13 | - Device information, location data, or IP address 14 | 15 | --- 16 | 17 | ### 2. Store Analytics 18 | 19 | Basic aggregated data provided by app stores (such as installation numbers or crash reports) may be used **internally** to improve the app’s quality. However, **this data is never shared with third parties**. 20 | 21 | --- 22 | 23 | ### 3. Ads and Tracking 24 | 25 | This app **does not contain any advertisements, analytics tools, or tracking mechanisms**. 26 | 27 | --- 28 | 29 | ### 4. Policy Changes 30 | 31 | If there are any future changes to the app that affect user privacy, this policy will be updated accordingly. Major changes will be announced within the app or on the app store listing. 32 | 33 | --- 34 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /hakoirimusume.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}") = "hakoirimusume", "hakoirimusume.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hakoirimusume 2 | 3 | ![image](https://github.com/user-attachments/assets/70a46d20-0134-43ac-949f-69118eafc1ed) 4 | 5 | ### 🔹Basic Rules of "Hakoiri Musume" (The Damsel in the Box) 6 | 7 | "Hakoiri Musume" is a classic sliding block puzzle game from Japan. It looks simple at first glance, but it’s surprisingly deep and addictive. 8 | 9 | --- 10 | 11 | ### 🔹The Rules 12 | 13 | - The puzzle is played on a **rectangular board**, typically 5 rows by 4 columns. 14 | - Various blocks (representing the daughter, retainers, obstacles, etc.) are placed inside the board to start. 15 | - The blocks come in different sizes: **1×1, 1×2, 2×1, and 2×2**. 16 | - Blocks can be **slid vertically or horizontally**, but not diagonally or by jumping. 17 | - Blocks cannot be moved outside the board or over each other. 18 | 19 | --- 20 | 21 | ### 🔹The Goal 22 | 23 | - The main objective is to **slide the largest block** (usually representing the "daughter" or "princess") **to the designated exit**, typically at the **bottom center** of the board. 24 | 25 | --- 26 | 27 | ### 🔹Tips for Playing 28 | 29 | - Carefully move the smaller blocks to **make space for the large block to move**. 30 | - The fewer moves you use, the better. 31 | - Like a game of chess or shogi, it’s possible to get into a “deadlock” state—so **planning ahead and trial-and-error are key**. 32 | 33 | --- 34 | 35 | It’s intuitive to play but really tests your brain, making it fun for both kids and adults! 36 | Have you tried playing it before? 37 | -------------------------------------------------------------------------------- /hakoirimusume.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 | リソース ファイル 44 | 45 | 46 | リソース ファイル 47 | 48 | 49 | リソース ファイル 50 | 51 | 52 | リソース ファイル 53 | 54 | 55 | リソース ファイル 56 | 57 | 58 | リソース ファイル 59 | 60 | 61 | リソース ファイル 62 | 63 | 64 | リソース ファイル 65 | 66 | 67 | リソース ファイル 68 | 69 | 70 | リソース ファイル 71 | 72 | 73 | リソース ファイル 74 | 75 | 76 | -------------------------------------------------------------------------------- /.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 364 | /installer/LogFiles 365 | /installer/MsixPackage/installer/installer_x86.msix 366 | -------------------------------------------------------------------------------- /hakoirimusume.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 | hakoirimusume 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v143 32 | Unicode 33 | 34 | 35 | Application 36 | false 37 | v143 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v143 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v143 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 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | Level3 89 | Disabled 90 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 91 | MultiThreadedDebug 92 | 93 | 94 | Windows 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | Level3 107 | Disabled 108 | _DEBUG;_WINDOWS;%(PreprocessorDefinitions) 109 | MultiThreadedDebug 110 | 111 | 112 | Windows 113 | true 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | Level3 123 | 124 | 125 | MaxSpeed 126 | true 127 | true 128 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 129 | MultiThreaded 130 | 131 | 132 | Windows 133 | true 134 | true 135 | No 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | Level3 145 | 146 | 147 | MaxSpeed 148 | true 149 | true 150 | NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 151 | MultiThreaded 152 | 153 | 154 | Windows 155 | true 156 | true 157 | No 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | // DPI認識のためのヘッダーを追加 7 | #include 8 | 9 | // Direct2DおよびWICのライブラリをリンク 10 | #pragma comment(lib, "d2d1.lib") 11 | #pragma comment(lib, "dwrite.lib") 12 | #pragma comment(lib, "windowscodecs.lib") 13 | 14 | #include "resource.h" // リソース定義ファイル (IDB_PNG1など) 15 | 16 | // インターフェースポインターを安全に解放するマクロ 17 | template inline void SafeRelease(T** ppT) 18 | { 19 | if (*ppT != NULL) 20 | { 21 | (*ppT)->Release(); 22 | *ppT = NULL; 23 | } 24 | } 25 | 26 | TCHAR szClassName[] = TEXT("Window"); 27 | 28 | // 論理単位 (DIP) での定義 29 | // Direct2Dはこれらの値をDIPとして扱い、DPIに応じて自動的にスケーリングします。 30 | #define MASU_WIDTH_DIP 32 31 | #define MASU_HEIGHT_DIP 32 32 | 33 | #define X_NUM 10 34 | #define Y_NUM 12 35 | 36 | // ウィンドウの論理サイズ (DIP) 37 | #define WINDOW_WIDTH_DIP (MASU_WIDTH_DIP * X_NUM) 38 | #define WINDOW_HEIGHT_DIP (MASU_HEIGHT_DIP * Y_NUM) 39 | 40 | // --- DPI グローバル変数 --- 41 | // 現在のDPIスケールファクター (DPI / 96.0)。マウス座標変換に使用。 42 | float g_dpiScale = 1.0f; 43 | 44 | // --- Direct2D/WIC/DWrite グローバル変数 --- 45 | ID2D1Factory* pD2DFactory = nullptr; 46 | IWICImagingFactory* pWICFactory = nullptr; 47 | ID2D1HwndRenderTarget* pRT = nullptr; 48 | ID2D1Bitmap* pBitmap[14] = { nullptr }; // Direct2Dビットマップを格納する配列 49 | ID2D1SolidColorBrush* pTextBrush = nullptr; 50 | IDWriteFactory* pDWriteFactory = nullptr; 51 | IDWriteTextFormat* pTextFormat = nullptr; 52 | 53 | // --- グローバルゲーム変数 (元のコードから維持) --- 54 | int* g_x = nullptr; 55 | int* g_y = nullptr; 56 | int* g_sx = nullptr; 57 | int* g_sy = nullptr; 58 | int* g_imgno = nullptr; 59 | int* g_field = nullptr; 60 | int g_nLast = 0; // 駒の総数 61 | int g_nStage = 1; // 現在のレベル 62 | 63 | // -------------------------------------------------------------------------------- 64 | // --- WIC/Direct2D リソース管理ヘルパー関数 (変更なし) --- 65 | // -------------------------------------------------------------------------------- 66 | 67 | // WICとDirect2Dを使用してリソースからビットマップを読み込む 68 | HRESULT LoadBitmapFromResource( 69 | ID2D1RenderTarget* pRenderTarget, 70 | IWICImagingFactory* pIWICFactory, 71 | HMODULE hModule, 72 | LPCWSTR lpName, 73 | LPCWSTR lpType, 74 | ID2D1Bitmap** ppBitmap 75 | ) 76 | { 77 | HRSRC hResInfo = FindResource(hModule, lpName, lpType); 78 | if (!hResInfo) return E_FAIL; 79 | 80 | DWORD nSize = SizeofResource(hModule, hResInfo); 81 | if (!nSize) return E_FAIL; 82 | 83 | HGLOBAL hResData = LoadResource(hModule, hResInfo); 84 | if (!hResData) return E_FAIL; 85 | 86 | void* pData = LockResource(hResData); 87 | if (!pData) return E_FAIL; 88 | 89 | // IStreamを作成 90 | IStream* pStream = nullptr; 91 | HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); 92 | if (SUCCEEDED(hr)) 93 | { 94 | // リソースデータをストリームに書き込む 95 | hr = pStream->Write(pData, nSize, NULL); 96 | } 97 | 98 | IWICBitmapDecoder* pDecoder = nullptr; 99 | IWICBitmapFrameDecode* pSource = nullptr; 100 | IWICFormatConverter* pConverter = nullptr; 101 | 102 | if (SUCCEEDED(hr)) 103 | { 104 | // ストリームからWICデコーダーを作成 105 | hr = pIWICFactory->CreateDecoderFromStream(pStream, NULL, WICDecodeMetadataCacheOnLoad, &pDecoder); 106 | } 107 | 108 | if (SUCCEEDED(hr)) 109 | { 110 | // 最初のフレームを取得 111 | hr = pDecoder->GetFrame(0, &pSource); 112 | } 113 | 114 | if (SUCCEEDED(hr)) 115 | { 116 | // フォーマットコンバーターを作成 117 | hr = pIWICFactory->CreateFormatConverter(&pConverter); 118 | } 119 | 120 | if (SUCCEEDED(hr)) 121 | { 122 | // RENDER TARGETのピクセルフォーマットに変換 123 | hr = pConverter->Initialize( 124 | pSource, 125 | GUID_WICPixelFormat32bppPBGRA, // D2D1_ALPHA_MODE_PREMULTIPLIED に対応 126 | WICBitmapDitherTypeNone, 127 | NULL, 128 | 0.0, 129 | WICBitmapPaletteTypeCustom 130 | ); 131 | } 132 | 133 | if (SUCCEEDED(hr)) 134 | { 135 | // Direct2Dビットマップを作成 136 | hr = pRenderTarget->CreateBitmapFromWicBitmap(pConverter, NULL, ppBitmap); 137 | } 138 | 139 | // WICオブジェクトの解放 140 | SafeRelease(&pStream); 141 | SafeRelease(&pDecoder); 142 | SafeRelease(&pSource); 143 | SafeRelease(&pConverter); 144 | 145 | return hr; 146 | } 147 | 148 | // ハードウェアに依存するリソースを作成 149 | HRESULT CreateDeviceResources(HWND hWnd) 150 | { 151 | HRESULT hr = S_OK; 152 | 153 | if (!pRT) 154 | { 155 | // 現在のウィンドウのDPIを取得し、RenderTargetPropertiesに明示的に設定します。 156 | UINT dpi = GetDpiForWindow(hWnd); 157 | FLOAT dpiFloat = (FLOAT)dpi; 158 | 159 | RECT rc; 160 | GetClientRect(hWnd, &rc); 161 | 162 | // クライアント領域のサイズ(物理ピクセル)をDirect2Dに渡す 163 | D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top); 164 | 165 | // HWNDレンダーターゲットを作成 166 | // DPIプロパティに現在のDPIを明示的に設定 167 | hr = pD2DFactory->CreateHwndRenderTarget( 168 | D2D1::RenderTargetProperties( 169 | D2D1_RENDER_TARGET_TYPE_DEFAULT, 170 | D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_UNKNOWN), 171 | dpiFloat, // DPI X 172 | dpiFloat // DPI Y 173 | ), 174 | D2D1::HwndRenderTargetProperties(hWnd, size), 175 | &pRT 176 | ); 177 | 178 | if (SUCCEEDED(hr)) 179 | { 180 | // テキストブラシを作成 181 | hr = pRT->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &pTextBrush); 182 | } 183 | 184 | if (SUCCEEDED(hr)) 185 | { 186 | // 全ての画像をDirect2Dビットマップとして読み込む 187 | HMODULE hModule = (HMODULE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); 188 | for (int i = 0; i < 14; i++) 189 | { 190 | hr = LoadBitmapFromResource(pRT, pWICFactory, hModule, MAKEINTRESOURCE(IDB_PNG1 + i), TEXT("PNG"), &pBitmap[i]); 191 | if (FAILED(hr)) break; 192 | } 193 | } 194 | } 195 | return hr; 196 | } 197 | 198 | // ハードウェアに依存するリソースを破棄 199 | void DiscardDeviceResources() 200 | { 201 | SafeRelease(&pRT); 202 | SafeRelease(&pTextBrush); 203 | // **修正**: ビットマップ配列のループ条件を i < 14 に修正 204 | for (int i = 0; i < 14; i++) 205 | { 206 | SafeRelease(&pBitmap[i]); 207 | } 208 | } 209 | 210 | // -------------------------------------------------------------------------------- 211 | // --- ゲームロジック関数 (DIP定数名に合わせて修正) --- 212 | // -------------------------------------------------------------------------------- 213 | 214 | void clear_field(int nNo) 215 | { 216 | for (int xx = 0; xx < g_sx[nNo]; xx++) 217 | { 218 | for (int yy = 0; yy < g_sy[nNo]; yy++) 219 | { 220 | g_field[g_x[nNo] + xx + (g_y[nNo] + yy) * X_NUM] = 0; 221 | } 222 | } 223 | } 224 | 225 | void put_field(int nNo, LPBOOL pbIsWin) 226 | { 227 | for (int xx = 0; xx < g_sx[nNo]; xx++) 228 | { 229 | for (int yy = 0; yy < g_sy[nNo]; yy++) 230 | { 231 | g_field[g_x[nNo] + xx + (g_y[nNo] + yy) * X_NUM] = nNo; 232 | } 233 | } 234 | if (g_x[1] == 3 && g_y[1] == 7)*pbIsWin = TRUE; 235 | } 236 | 237 | BOOL DownKoma(int nNo, int xx, int yy, LPBOOL pbIsWin) 238 | { 239 | for (int i = 0; i < g_sx[nNo]; i++) 240 | { 241 | if (g_field[(g_x[nNo] + i) + (g_y[nNo] + g_sy[nNo]) * X_NUM] != 0) 242 | { 243 | return FALSE; 244 | } 245 | } 246 | clear_field(nNo); 247 | g_y[nNo]++; 248 | put_field(nNo, pbIsWin); 249 | return TRUE; 250 | } 251 | 252 | BOOL UpKoma(int nNo, int xx, int yy, LPBOOL pbIsWin) 253 | { 254 | for (int i = 0; i < g_sx[nNo]; i++) 255 | { 256 | if (g_field[(g_x[nNo] + i) + (g_y[nNo] - 1) * X_NUM] != 0) 257 | { 258 | return FALSE; 259 | } 260 | } 261 | clear_field(nNo); 262 | g_y[nNo]--; 263 | put_field(nNo, pbIsWin); 264 | return TRUE; 265 | } 266 | 267 | BOOL RightKoma(int nNo, int xx, int yy, LPBOOL pbIsWin) 268 | { 269 | for (int i = 0; i < g_sy[nNo]; i++) 270 | { 271 | if (g_field[(g_x[nNo] + g_sx[nNo]) + (g_y[nNo] + i) * X_NUM] != 0) 272 | { 273 | return FALSE; 274 | } 275 | } 276 | clear_field(nNo); 277 | g_x[nNo]++; 278 | put_field(nNo, pbIsWin); 279 | return TRUE; 280 | } 281 | 282 | BOOL LeftKoma(int nNo, int xx, int yy, LPBOOL pbIsWin) 283 | { 284 | for (int i = 0; i < g_sy[nNo]; i++) 285 | { 286 | if (g_field[(g_x[nNo] - 1) + (g_y[nNo] + i) * X_NUM] != 0) 287 | { 288 | return FALSE; 289 | } 290 | } 291 | clear_field(nNo); 292 | g_x[nNo]--; 293 | put_field(nNo, pbIsWin); 294 | return TRUE; 295 | } 296 | 297 | // レベルデータ関数 (変更なし) 298 | void Level1(int* pnLast) { 299 | const int m_x[] = { 0,3,1,7,1,7,3,5,3,5,1,7 }; 300 | const int m_y[] = { 0,1,1,1,5,5,5,5,7,7,9,9 }; 301 | const int m_sx[] = { 0,4,2,2,2,2,2,2,2,2,2,2 }; 302 | const int m_sy[] = { 0,4,4,4,4,4,2,2,2,2,2,2 }; 303 | const int m_imgno[] = { 0,1,2,3,4,5,11,11,11,11,11,11 }; 304 | *pnLast = 12; 305 | for (int i = 0; i < *pnLast; i++) { g_x[i] = m_x[i]; g_y[i] = m_y[i]; g_sx[i] = m_sx[i]; g_sy[i] = m_sy[i]; g_imgno[i] = m_imgno[i]; } 306 | } 307 | void Level2(int* pnLast) { 308 | const int m_x[] = { 0,3,1,5,1,5,1,1,7,7,1,7 }; 309 | const int m_y[] = { 0,1,5,5,7,7,1,3,1,3,9,9 }; 310 | const int m_sx[] = { 0,4,4,4,4,4,2,2,2,2,2,2 }; 311 | const int m_sy[] = { 0,4,2,2,2,2,2,2,2,2,2,2 }; 312 | const int m_imgno[] = { 0,1,6,7,8,9,11,11,11,11,11,11 }; 313 | *pnLast = 12; 314 | for (int i = 0; i < *pnLast; i++) { g_x[i] = m_x[i]; g_y[i] = m_y[i]; g_sx[i] = m_sx[i]; g_sy[i] = m_sy[i]; g_imgno[i] = m_imgno[i]; } 315 | } 316 | void Level3(int* pnLast) { 317 | const int m_x[] = { 0,3,1,7,1,5,1,3,5,7,1,7 }; 318 | const int m_y[] = { 0,1,1,1,7,7,5,5,5,5,9,9 }; 319 | const int m_sx[] = { 0,4,2,2,4,4,2,2,2,2,2,2 }; 320 | const int m_sy[] = { 0,4,4,4,2,2,2,2,2,2,2,2 }; 321 | const int m_imgno[] = { 0,1,2,3,8,9,11,11,11,11,11,11 }; 322 | *pnLast = 12; 323 | for (int i = 0; i < *pnLast; i++) { g_x[i] = m_x[i]; g_y[i] = m_y[i]; g_sx[i] = m_sx[i]; g_sy[i] = m_sy[i]; g_imgno[i] = m_imgno[i]; } 324 | } 325 | void Level4(int* pnLast) { 326 | const int m_x[] = { 0,3,1,7,1,5,1,3,5,7,1,7 }; 327 | const int m_y[] = { 0,1,1,1,5,5,7,7,7,7,9,9 }; 328 | const int m_sx[] = { 0,4,2,2,4,4,2,2,2,2,2,2 }; 329 | const int m_sy[] = { 0,4,4,4,2,2,2,2,2,2,2,2 }; 330 | const int m_imgno[] = { 0,1,2,3,8,9,11,11,11,11,11,11 }; 331 | *pnLast = 12; 332 | for (int i = 0; i < *pnLast; i++) { g_x[i] = m_x[i]; g_y[i] = m_y[i]; g_sx[i] = m_sx[i]; g_sy[i] = m_sy[i]; g_imgno[i] = m_imgno[i]; } 333 | } 334 | void Level5(int* pnLast) { 335 | const int m_x[] = { 0,3,1,7,1,7,3,3,5,1,7 }; 336 | const int m_y[] = { 0,1,1,1,5,5,5,7,7,9,9 }; 337 | const int m_sx[] = { 0,4,2,2,2,2,4,2,2,2,2 }; 338 | const int m_sy[] = { 0,4,4,4,4,4,2,2,2,2,2 }; 339 | const int m_imgno[] = { 0,1,2,3,4,5,10,11,11,11,11 }; 340 | *pnLast = 11; 341 | for (int i = 0; i < *pnLast; i++) { g_x[i] = m_x[i]; g_y[i] = m_y[i]; g_sx[i] = m_sx[i]; g_sy[i] = m_sy[i]; g_imgno[i] = m_imgno[i]; } 342 | } 343 | 344 | //レベル(nLevel)に応じてゲーム画面を初期化する 345 | VOID initGame(int nLevel, int* pnLast) 346 | { 347 | switch (nLevel) 348 | { 349 | case 1:Level1(pnLast); break; 350 | case 2:Level2(pnLast); break; 351 | case 3:Level3(pnLast); break; 352 | case 4:Level4(pnLast); break; 353 | case 5:Level5(pnLast); break; 354 | default:Level1(pnLast); break; 355 | } 356 | for (int i = 0; i < (X_NUM * Y_NUM); i++)g_field[i] = 0; 357 | for (int i = 0; i < X_NUM; i++)g_field[i] = 99; 358 | for (int i = 0; i < X_NUM; i++)g_field[i + 110] = 99; 359 | for (int i = 0; i < Y_NUM; i++)g_field[X_NUM * i] = 99; 360 | for (int i = 0; i < Y_NUM; i++)g_field[9 + X_NUM * i] = 99; 361 | for (int i = 1; i < *pnLast; i++) 362 | { 363 | for (int xx = 0; xx < g_sx[i]; xx++) 364 | { 365 | for (int yy = 0; yy < g_sy[i]; yy++) 366 | { 367 | g_field[g_x[i] + xx + (g_y[i] + yy) * X_NUM] = i; 368 | } 369 | } 370 | } 371 | } 372 | 373 | // -------------------------------------------------------------------------------- 374 | // --- ウィンドウプロシージャ (DPI対応ロジックを追加) --- 375 | // -------------------------------------------------------------------------------- 376 | 377 | LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 378 | { 379 | static BOOL bCapture; 380 | static BOOL bSetTimered; 381 | static BOOL bIsWin = FALSE; 382 | static int nNo; 383 | // マウスイベントの比較用に物理ピクセル座標を保持 384 | static int g_oldx, g_oldy; 385 | HRESULT hr; 386 | 387 | switch (msg) 388 | { 389 | case WM_NCCREATE: 390 | { 391 | // ウィンドウ作成時に初期DPIを取得し、スケールファクターを設定 392 | UINT dpi = GetDpiForWindow(hWnd); 393 | g_dpiScale = (float)dpi / 96.0f; 394 | return DefWindowProc(hWnd, msg, wParam, lParam); 395 | } 396 | 397 | case WM_CREATE: 398 | // Direct2D/WIC/DWrite ファクトリの初期化 (変更なし) 399 | hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &pD2DFactory); 400 | if (FAILED(hr)) return -1; 401 | 402 | hr = CoInitialize(NULL); // WICのためにCOMを初期化 403 | if (FAILED(hr)) return -1; 404 | hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pWICFactory)); 405 | if (FAILED(hr)) return -1; 406 | 407 | hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast(&pDWriteFactory)); 408 | if (FAILED(hr)) return -1; 409 | 410 | // DWrite TextFormatの作成 (フォントサイズはDIPで指定) 411 | hr = pDWriteFactory->CreateTextFormat( 412 | L"Arial", // フォント名 413 | NULL,// フォントコレクション (NULL = システムデフォルト) 414 | DWRITE_FONT_WEIGHT_BOLD,// フォントの太さ 415 | DWRITE_FONT_STYLE_NORMAL,// フォントスタイル 416 | DWRITE_FONT_STRETCH_NORMAL, // フォントストレッチ 417 | 48.0f,// フォントサイズ (DIP) 418 | L"ja-jp",// ロケール 419 | &pTextFormat 420 | ); 421 | if (SUCCEEDED(hr)) 422 | { 423 | pTextFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_CENTER); 424 | pTextFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER); 425 | } 426 | 427 | // ゲームメモリの割り当てと初期化 (変更なし) 428 | g_field = (int*)GlobalAlloc(GMEM_FIXED, sizeof(int) * X_NUM * Y_NUM); 429 | g_x = (int*)GlobalAlloc(GMEM_FIXED, sizeof(int) * Y_NUM); 430 | g_y = (int*)GlobalAlloc(GMEM_FIXED, sizeof(int) * Y_NUM); 431 | g_sx = (int*)GlobalAlloc(GMEM_FIXED, sizeof(int) * Y_NUM); 432 | g_sy = (int*)GlobalAlloc(GMEM_FIXED, sizeof(int) * Y_NUM); 433 | g_imgno = (int*)GlobalAlloc(GMEM_FIXED, sizeof(int) * Y_NUM); 434 | 435 | initGame(g_nStage, &g_nLast); 436 | break; 437 | 438 | case WM_DPICHANGED: 439 | { 440 | // DPIが変更されたときの処理 441 | // wParamの上位ワード(HIWORD)からY軸のDPIを取得。 442 | UINT newDpi = HIWORD(wParam); 443 | g_dpiScale = (float)newDpi / 96.0f; 444 | 445 | // RenderTargetとビットマップを破棄し、新しいDPIで再作成する準備をする 446 | DiscardDeviceResources(); 447 | 448 | // **修正**: 新しいDPIに基づき、クライアント領域が論理サイズ (DIP) にぴったり合うようにウィンドウサイズを再計算 449 | 450 | // 1. 新しいDPIに基づいた必要なクライアントサイズ (物理ピクセル) を計算 451 | int newClientWidthPx = MulDiv(WINDOW_WIDTH_DIP, newDpi, 96); 452 | int newClientHeightPx = MulDiv(WINDOW_HEIGHT_DIP, newDpi, 96); 453 | 454 | // 2. ウィンドウ全体のスタイルと拡張スタイルを取得 455 | DWORD dwStyle = (DWORD)GetWindowLongPtr(hWnd, GWL_STYLE); 456 | DWORD dwExStyle = (DWORD)GetWindowLongPtr(hWnd, GWL_EXSTYLE); 457 | 458 | // 3. 必要なクライアント領域を保持するためのウィンドウ全体のサイズを計算 459 | RECT newWindowRc = { 0, 0, newClientWidthPx, newClientHeightPx }; 460 | 461 | // AdjustWindowRectExForDpiは、クライアント領域 (newWindowRc) を保持するための 462 | // ウィンドウ全体のサイズを計算し、その結果を newWindowRc に書き込みます。 463 | BOOL adjusted = AdjustWindowRectExForDpi(&newWindowRc, dwStyle, FALSE, dwExStyle, newDpi); 464 | 465 | if (adjusted) 466 | { 467 | // lParamが示す推奨矩形から位置情報 (left, top) を取得 468 | RECT* const prcOldWindow = (RECT*)lParam; 469 | 470 | // newWindowRcには、クライアント領域を含むウィンドウ全体の矩形が格納されているため、 471 | // その幅と高さをそのまま利用します。 472 | int finalWidth = newWindowRc.right - newWindowRc.left; 473 | int finalHeight = newWindowRc.bottom - newWindowRc.top; 474 | 475 | // 推奨される位置 (left, top) を使用してウィンドウを再配置 476 | SetWindowPos(hWnd, 477 | NULL, 478 | prcOldWindow->left, // 推奨されたX座標 479 | prcOldWindow->top, // 推奨されたY座標 480 | finalWidth, // 新しいDPIに合わせた正確な幅 481 | finalHeight, // 新しいDPIに合わせた正確な高さ 482 | SWP_NOZORDER | SWP_NOACTIVATE); 483 | } 484 | 485 | InvalidateRect(hWnd, NULL, FALSE); 486 | break; 487 | } 488 | 489 | case WM_SIZE: 490 | { 491 | if (pRT) 492 | { 493 | D2D1_SIZE_U size = D2D1::SizeU(LOWORD(lParam), HIWORD(lParam)); 494 | pRT->Resize(size); 495 | } 496 | InvalidateRect(hWnd, NULL, FALSE); 497 | break; 498 | } 499 | 500 | case WM_LBUTTONDOWN: 501 | if (bIsWin == FALSE) 502 | { 503 | const WORD xPos_px = LOWORD(lParam); // 物理ピクセル座標 504 | const WORD yPos_px = HIWORD(lParam); // 物理ピクセル座標 505 | 506 | // 物理ピクセル座標を論理座標 (DIP) に変換 507 | const float logical_x_f = (float)xPos_px / g_dpiScale; 508 | const float logical_y_f = (float)yPos_px / g_dpiScale; 509 | 510 | // グリッド座標を計算 (マス目のインデックス) 511 | const int grid_x = (int)(logical_x_f / MASU_WIDTH_DIP); 512 | const int grid_y = (int)(logical_y_f / MASU_HEIGHT_DIP); 513 | 514 | // 比較用に物理座標を保持 515 | g_oldx = xPos_px; 516 | g_oldy = yPos_px; 517 | 518 | // 駒の選択はグリッド座標で行う 519 | nNo = g_field[grid_y * X_NUM + grid_x]; 520 | 521 | if (nNo == 99) 522 | { 523 | nNo = 0; 524 | } 525 | else if (nNo) 526 | { 527 | bCapture = TRUE; 528 | SetCapture(hWnd); 529 | } 530 | } 531 | break; 532 | 533 | case WM_MOUSEMOVE: 534 | if (bCapture) 535 | { 536 | if (nNo) 537 | { 538 | const WORD xPos_px = LOWORD(lParam); 539 | const WORD yPos_px = HIWORD(lParam); 540 | 541 | // 移動判定は物理ピクセルで行う。閾値に現在のDPIスケールを適用 542 | const float threshold = 20.0f / 32.0f; 543 | 544 | if ( 545 | yPos_px - g_oldy > MASU_HEIGHT_DIP * g_dpiScale * threshold && DownKoma(nNo, xPos_px, yPos_px, &bIsWin) || 546 | g_oldy - yPos_px > MASU_HEIGHT_DIP * g_dpiScale * threshold && UpKoma(nNo, xPos_px, yPos_px, &bIsWin) || 547 | xPos_px - g_oldx > MASU_WIDTH_DIP * g_dpiScale * threshold && RightKoma(nNo, xPos_px, yPos_px, &bIsWin) || 548 | g_oldx - xPos_px > MASU_WIDTH_DIP * g_dpiScale * threshold && LeftKoma(nNo, xPos_px, yPos_px, &bIsWin) 549 | ) 550 | { 551 | g_oldx = xPos_px; 552 | g_oldy = yPos_px; 553 | InvalidateRect(hWnd, 0, FALSE); // GDIのWM_ERASEBKGND回避のためFALSE 554 | } 555 | } 556 | } 557 | break; 558 | 559 | case WM_LBUTTONUP: 560 | if (bCapture) 561 | { 562 | nNo = 0; 563 | ReleaseCapture(); 564 | bCapture = FALSE; 565 | } 566 | break; 567 | 568 | case WM_TIMER: 569 | // タイマー処理 (変更なし) 570 | KillTimer(hWnd, 0x1234); 571 | g_nStage++; 572 | if (g_nStage >= 6) 573 | { 574 | MessageBox(hWnd, 575 | TEXT("全面クリアーしました。\nあなたはすごい!"), 576 | TEXT("おめでとう!"), 0); 577 | PostMessage(hWnd, WM_CLOSE, 0, 0); 578 | } 579 | else 580 | { 581 | bIsWin = FALSE; 582 | bSetTimered = FALSE; 583 | TCHAR szTitle[64]; 584 | wsprintf(szTitle, TEXT("箱入り娘。(レベル %d)"), g_nStage); 585 | SetWindowText(hWnd, szTitle); 586 | initGame(g_nStage, &g_nLast); 587 | InvalidateRect(hWnd, 0, FALSE); 588 | } 589 | break; 590 | 591 | case WM_PAINT: 592 | { 593 | // Direct2D描画 594 | hr = CreateDeviceResources(hWnd); 595 | if (SUCCEEDED(hr)) 596 | { 597 | PAINTSTRUCT ps; 598 | BeginPaint(hWnd, &ps); 599 | 600 | pRT->BeginDraw(); 601 | 602 | // 背景をクリア (白) 603 | pRT->Clear(D2D1::ColorF(D2D1::ColorF::White)); 604 | 605 | // Direct2DはDIPで描画するため、以下の座標はDIPで計算する 606 | const FLOAT fWindowWidthDIP = (FLOAT)WINDOW_WIDTH_DIP; 607 | const FLOAT fWindowHeightDIP = (FLOAT)WINDOW_HEIGHT_DIP; 608 | const FLOAT fMasuWidthDIP = (FLOAT)MASU_WIDTH_DIP; 609 | const FLOAT fMasuHeightDIP = (FLOAT)MASU_HEIGHT_DIP; 610 | 611 | if (bIsWin == TRUE) 612 | { 613 | // クリアーしたとき「見事」と2秒間表示する 614 | if (pBitmap[12]) 615 | { 616 | // 勝利画面の背景 617 | pRT->DrawBitmap(pBitmap[12], D2D1::RectF(0, 0, fWindowWidthDIP, fWindowHeightDIP)); 618 | } 619 | 620 | // DirectWriteで「見事」を描画 621 | if (pTextBrush && pTextFormat) 622 | { 623 | // D2DはDIPで描画するため、RectFもDIPを使用 624 | pTextBrush->SetColor(D2D1::ColorF(D2D1::ColorF::Black)); 625 | pRT->DrawText( 626 | L"見事!\n次のレベルへ", 627 | (UINT32)wcslen(L"見事!\n次のレベルへ"), 628 | pTextFormat, 629 | D2D1::RectF(0, fWindowHeightDIP / 4.0f, fWindowWidthDIP, fWindowHeightDIP / 2.0f), 630 | pTextBrush 631 | ); 632 | } 633 | 634 | if (!bSetTimered) 635 | { 636 | bSetTimered = TRUE; 637 | SetTimer(hWnd, 0x1234, 1000 * 2, NULL); 638 | } 639 | } 640 | else 641 | { 642 | // 背景画像 (0番) 643 | if (pBitmap[0]) 644 | { 645 | // D2DはDIPで描画するため、RectFもDIPを使用 646 | pRT->DrawBitmap(pBitmap[0], D2D1::RectF(0, 0, fWindowWidthDIP, fWindowHeightDIP)); 647 | } 648 | 649 | // 各駒を描画 650 | for (int i = 1; i < g_nLast; i++) 651 | { 652 | int imgIndex = g_imgno[i]; 653 | if (pBitmap[imgIndex]) 654 | { 655 | // D2DはDIPで描画するため、RectFはDIPで計算する 656 | D2D1_RECT_F destRect = D2D1::RectF( 657 | (FLOAT)g_x[i] * fMasuWidthDIP, 658 | (FLOAT)g_y[i] * fMasuHeightDIP, 659 | (FLOAT)(g_x[i] + g_sx[i]) * fMasuWidthDIP, 660 | (FLOAT)(g_y[i] + g_sy[i]) * fMasuHeightDIP 661 | ); 662 | pRT->DrawBitmap(pBitmap[imgIndex], destRect); 663 | } 664 | } 665 | } 666 | 667 | hr = pRT->EndDraw(); 668 | 669 | // デバイスが消失した場合、リソースを破棄 670 | if (hr == D2DERR_RECREATE_TARGET) 671 | { 672 | hr = S_OK; 673 | DiscardDeviceResources(); 674 | } 675 | 676 | EndPaint(hWnd, &ps); 677 | } 678 | } 679 | break; 680 | 681 | case WM_DESTROY: 682 | KillTimer(hWnd, 0x1234); 683 | 684 | // Direct2D/WIC/DWrite リソースの解放 (変更なし) 685 | DiscardDeviceResources(); 686 | SafeRelease(&pD2DFactory); 687 | SafeRelease(&pWICFactory); 688 | SafeRelease(&pDWriteFactory); 689 | SafeRelease(&pTextFormat); 690 | CoUninitialize(); // COMの終了 691 | 692 | // ゲームメモリの解放 (変更なし) 693 | GlobalFree(g_field); 694 | GlobalFree(g_x); 695 | GlobalFree(g_y); 696 | GlobalFree(g_sx); 697 | GlobalFree(g_sy); 698 | GlobalFree(g_imgno); 699 | 700 | PostQuitMessage(0); 701 | break; 702 | 703 | default: 704 | return DefWindowProc(hWnd, msg, wParam, lParam); 705 | } 706 | return 0; 707 | } 708 | 709 | // -------------------------------------------------------------------------------- 710 | // --- WinMain (DPI対応ロジックを追加) --- 711 | // -------------------------------------------------------------------------------- 712 | 713 | int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPreInst, LPWSTR pCmdLine, int nCmdShow) 714 | { 715 | // **最重要**: プロセス全体のDPI認識コンテキストを設定 716 | // Per-Monitor V2 (モニターごとのDPI変更に反応する最も推奨されるDPIモード) 717 | if (SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == FALSE) 718 | { 719 | } 720 | 721 | MSG msg; 722 | const WNDCLASS wndclass = { 0,WndProc,0,0,hInstance,LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1)),LoadCursor(0,IDC_ARROW),(HBRUSH)(COLOR_WINDOW + 1),0,szClassName }; 723 | if (!RegisterClass(&wndclass)) return 0; 724 | 725 | // 初期DPIを取得し、初期ウィンドウサイズを物理ピクセルで計算 726 | UINT initialDpi = GetDpiForSystem(); // システムの初期DPIを取得 (通常96) 727 | 728 | // 論理サイズ (DIP) を物理ピクセルに変換 729 | int physicalWidth = MulDiv(WINDOW_WIDTH_DIP, initialDpi, 96); 730 | int physicalHeight = MulDiv(WINDOW_HEIGHT_DIP, initialDpi, 96); 731 | 732 | RECT rect; 733 | SetRect(&rect, 0, 0, physicalWidth, physicalHeight); 734 | AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, FALSE); 735 | 736 | const HWND hWnd = CreateWindowEx(0, szClassName, TEXT("箱入り娘。(レベル 1)"), 737 | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU, 738 | CW_USEDEFAULT, 739 | CW_USEDEFAULT, 740 | rect.right - rect.left, 741 | rect.bottom - rect.top, 742 | 0, 0, hInstance, 0); 743 | 744 | if (!hWnd) return 0; 745 | 746 | ShowWindow(hWnd, SW_SHOWDEFAULT); 747 | UpdateWindow(hWnd); 748 | 749 | while (GetMessage(&msg, 0, 0, 0)) 750 | { 751 | TranslateMessage(&msg); 752 | DispatchMessage(&msg); 753 | } 754 | 755 | return (int)msg.wParam; 756 | } 757 | --------------------------------------------------------------------------------