├── .gitignore ├── LICENSE ├── SplashImage.sln └── SplashImage ├── Program.cs ├── SplashImage.csproj ├── app.manifest └── packages.config /.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 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2019 Shaojun Li 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | -------------------------------------------------------------------------------- /SplashImage.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29020.237 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SplashImage", "SplashImage\SplashImage.csproj", "{E151E81F-BA20-4645-809D-20B527DAD2AD}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E151E81F-BA20-4645-809D-20B527DAD2AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E151E81F-BA20-4645-809D-20B527DAD2AD}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E151E81F-BA20-4645-809D-20B527DAD2AD}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E151E81F-BA20-4645-809D-20B527DAD2AD}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F2755128-B904-4753-960D-4542D319B9B8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SplashImage/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Diagnostics; 4 | using System.Runtime.InteropServices; 5 | using Lsj.Util.Win32.Structs; 6 | using Lsj.Util.Win32.Enums; 7 | using static Lsj.Util.Win32.User32; 8 | using static Lsj.Util.Win32.Gdi32; 9 | using static Lsj.Util.Win32.Gdiplus; 10 | using static Lsj.Util.Win32.Structs.BLENDFUNCTION; 11 | using Lsj.Util.Win32.Marshals; 12 | 13 | namespace SplashImage 14 | { 15 | public class Program 16 | { 17 | /// 18 | /// Splash File Name 19 | /// 20 | private const string SplashFile = "SplashScreen.png"; 21 | 22 | /// 23 | /// Image Width 24 | /// 25 | private const int ImageWidth = 780; 26 | 27 | /// 28 | /// Image Height 29 | /// 30 | private const int ImageHeight = 522; 31 | 32 | /// 33 | /// Window Class 34 | /// 35 | private const string WindowClass = "Splash Image"; 36 | 37 | /// 38 | /// Window Name 39 | /// 40 | private const string WindowName = "Splash Image"; 41 | 42 | 43 | /// 44 | /// Window Handle 45 | /// 46 | private static IntPtr _window; 47 | 48 | /// 49 | /// Window Rectangle 50 | /// 51 | private static RECT _windowRectangle; 52 | 53 | /// 54 | /// Window Size 55 | /// 56 | private static SIZE _windowSize; 57 | 58 | /// 59 | /// Screen DC 60 | /// 61 | private static readonly IntPtr _screenDC = GetDC(IntPtr.Zero); 62 | 63 | /// 64 | /// Window DC 65 | /// 66 | private static IntPtr _windowDC; 67 | 68 | /// 69 | /// Memory DC 70 | /// 71 | private static IntPtr _memoryDC = IntPtr.Zero; 72 | 73 | /// 74 | /// GDI+ Splash Image 75 | /// 76 | private static IntPtr _splashImage; 77 | 78 | /// 79 | /// GDI+ Graphics 80 | /// 81 | private static IntPtr _graphics; 82 | 83 | /// 84 | /// Memory Bitmap For SplashImage 85 | /// 86 | private static IntPtr _memoryBitmap = IntPtr.Zero; 87 | 88 | /// 89 | /// GDI+ Token 90 | /// 91 | private static UIntPtr _gdipToken = UIntPtr.Zero; 92 | 93 | public static void Main(string[] args) 94 | { 95 | try 96 | { 97 | var hInstance = Process.GetCurrentProcess().Handle; 98 | 99 | using var marshal = new StringToIntPtrMarshaler(WindowClass); 100 | var wndclass = new WNDCLASSEX 101 | { 102 | cbSize = (uint)Marshal.SizeOf(typeof(WNDCLASSEX)), 103 | style = ClassStyles.CS_DBLCLKS, 104 | lpfnWndProc = WindowProc, 105 | cbClsExtra = 0, 106 | cbWndExtra = 0, 107 | hInstance = hInstance, 108 | hIcon = LoadIcon(hInstance, SystemIcons.IDI_APPLICATION), 109 | hCursor = LoadCursor(IntPtr.Zero, SystemCursors.IDC_ARROW), 110 | hbrBackground = (IntPtr)BackgroundColors.COLOR_WINDOW, 111 | lpszMenuName = IntPtr.Zero, 112 | lpszClassName = marshal.GetPtr(), 113 | }; 114 | 115 | if (RegisterClassEx(ref wndclass) != 0) 116 | { 117 | _window = CreateWindowEx(WindowStylesEx.WS_EX_LAYERED, WindowClass, WindowName, WindowStyles.WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, 118 | CW_USEDEFAULT, CW_USEDEFAULT, IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero); 119 | if (_window != IntPtr.Zero) 120 | { 121 | _windowDC = GetDC(_window); 122 | 123 | SetPositionAndSize(); 124 | ShowWindow(_window, ShowWindowCommands.SW_SHOWNORMAL); 125 | 126 | var startupInput = new GdiplusStartupInput 127 | { 128 | GdiplusVersion = 1, 129 | DebugEventCallback = IntPtr.Zero, 130 | SuppressBackgroundThread = false, 131 | SuppressExternalCodecs = false, 132 | }; 133 | if (GdiplusStartup(out _gdipToken, ref startupInput, out _) == GpStatus.Ok && GdipLoadImageFromFile(SplashFile, out _splashImage) == GpStatus.Ok) 134 | { 135 | DrawImage(); 136 | while (GetMessage(out var msg, IntPtr.Zero, 0, 0) != 0) 137 | { 138 | try 139 | { 140 | TranslateMessage(ref msg); 141 | DispatchMessage(ref msg); 142 | } 143 | catch (Exception) 144 | { 145 | throw; 146 | } 147 | } 148 | } 149 | else 150 | { 151 | //TODO: throw GDI+ Error 152 | } 153 | } 154 | else 155 | { 156 | throw new Win32Exception(Marshal.GetLastWin32Error()); 157 | } 158 | } 159 | else 160 | { 161 | throw new Win32Exception(Marshal.GetLastWin32Error()); 162 | } 163 | 164 | } 165 | finally 166 | { 167 | ReleaseAllResource(); 168 | } 169 | } 170 | 171 | /// 172 | /// Set Window Position And Size 173 | /// 174 | /// 175 | private static void SetPositionAndSize(int dpi = 0) 176 | { 177 | var screenLeft = 0; 178 | var screenTop = 0; 179 | var screenWidth = GetSystemMetrics(SystemMetric.SM_CXSCREEN); 180 | var screenHeight = GetSystemMetrics(SystemMetric.SM_CYSCREEN); 181 | 182 | var monitor = MonitorFromWindow(_window, MonitorDefaultFlags.MONITOR_DEFAULTTONULL); 183 | if (monitor != null) 184 | { 185 | var info = new MONITORINFOEX(); 186 | info.cbSize = (uint)Marshal.SizeOf(info); 187 | if (GetMonitorInfo(monitor, ref info)) 188 | { 189 | screenLeft = info.rcMonitor.left; 190 | screenTop = info.rcMonitor.top; 191 | screenWidth = info.rcMonitor.right - info.rcMonitor.left; 192 | screenHeight = info.rcMonitor.bottom - info.rcMonitor.top; 193 | } 194 | } 195 | 196 | if (dpi == 0) 197 | { 198 | var osVersion = Environment.OSVersion.Version; 199 | if (osVersion > new Version(10, 0, 1607)) 200 | { 201 | dpi = (int)GetDpiForWindow(_window); 202 | } 203 | else 204 | { 205 | dpi = GetDeviceCaps(_windowDC, DeviceCapIndexes.LOGPIXELSX); 206 | } 207 | } 208 | 209 | 210 | var windowWidth = ImageWidth * dpi / 96; 211 | var windowHeight = ImageHeight * dpi / 96; 212 | 213 | SetWindowPos(_window, HWND_TOPMOST, (screenWidth - windowWidth) / 2 + screenLeft, (screenHeight - windowHeight) / 2 + screenTop, windowWidth, windowHeight, 0); 214 | GetWindowRect(_window, out _windowRectangle); 215 | _windowSize = new SIZE { cx = _windowRectangle.right - _windowRectangle.left, cy = _windowRectangle.bottom - _windowRectangle.top }; 216 | } 217 | 218 | /// 219 | /// Draw Image 220 | /// 221 | private static void DrawImage() 222 | { 223 | if (_memoryDC != IntPtr.Zero) 224 | { 225 | DeleteDC(_memoryDC); 226 | } 227 | if (_memoryBitmap != IntPtr.Zero) 228 | { 229 | DeleteObject(_memoryBitmap); 230 | } 231 | 232 | _memoryDC = CreateCompatibleDC(_windowDC); 233 | _memoryBitmap = CreateCompatibleBitmap(_windowDC, _windowSize.cx, _windowSize.cy); 234 | SelectObject(_memoryDC, _memoryBitmap); 235 | if (GdipCreateFromHDC(_memoryDC, out _graphics) == GpStatus.Ok && GdipDrawImageRectI(_graphics, _splashImage, 0, 0, _windowSize.cx, _windowSize.cy) == GpStatus.Ok) 236 | { 237 | var ptSrc = new POINT 238 | { 239 | x = 0, 240 | y = 0, 241 | }; 242 | var ptDes = new POINT 243 | { 244 | x = _windowRectangle.left, 245 | y = _windowRectangle.top, 246 | }; 247 | var blendFunction = new BLENDFUNCTION 248 | { 249 | AlphaFormat = AC_SRC_ALPHA, 250 | BlendFlags = 0, 251 | BlendOp = AC_SRC_OVER, 252 | SourceConstantAlpha = 255, 253 | }; 254 | if (UpdateLayeredWindow(_window, _screenDC, ref ptDes, ref _windowSize, _memoryDC, ref ptSrc, 0, ref blendFunction, UpdateLayeredWindowFlags.ULW_ALPHA)) 255 | { 256 | return; 257 | } 258 | else 259 | { 260 | throw new Win32Exception(Marshal.GetLastWin32Error()); 261 | } 262 | } 263 | } 264 | 265 | /// 266 | /// Release All Resource 267 | /// 268 | private static void ReleaseAllResource() 269 | { 270 | if (_gdipToken != null) 271 | { 272 | GdiplusShutdown(_gdipToken); 273 | } 274 | DeleteObject(_memoryBitmap); 275 | DeleteDC(_memoryDC); 276 | ReleaseDC(_window, _windowDC); 277 | ReleaseDC(IntPtr.Zero, _screenDC); 278 | } 279 | 280 | /// 281 | /// Window Proc 282 | /// 283 | /// 284 | /// 285 | /// 286 | /// 287 | /// 288 | private static IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, UIntPtr wParam, IntPtr lParam) 289 | { 290 | try 291 | { 292 | switch (msg) 293 | { 294 | case WindowsMessages.WM_DESTROY: 295 | PostQuitMessage(0); 296 | return IntPtr.Zero; 297 | case WindowsMessages.WM_DPICHANGED: 298 | SetPositionAndSize((int)(wParam.ToUInt32() >> 16)); 299 | DrawImage(); 300 | return IntPtr.Zero; 301 | case WindowsMessages.WM_NCHITTEST: 302 | var result = DefWindowProc(hWnd, msg, wParam, lParam); 303 | return result == (IntPtr)HitTestResults.HTCAPTION ? (IntPtr)HitTestResults.HTNOWHERE : result; 304 | default: 305 | return DefWindowProc(hWnd, msg, wParam, lParam); 306 | } 307 | } 308 | catch 309 | { 310 | //The finally in Main won't run if exception is thrown in this method. 311 | //This may be because this method was called by system code. 312 | //So we must handle exception here. 313 | DestroyWindow(_window); 314 | return IntPtr.Zero; 315 | } 316 | } 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /SplashImage/SplashImage.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | net45 4 | true 5 | 8.0 6 | 7 | WinExe 8 | 9 | app.manifest 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SplashImage/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | PerMonitorV2 55 | true/pm 56 | 57 | 58 | 59 | 60 | 61 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /SplashImage/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------