| 61 | static HWND logoOwnerWindow = nullptr; |
| 62 | |
| 63 | void ShowSplash(HINSTANCE hInstance) |
| 64 | { |
| 65 | WNDCLASS wc = {0}; |
| 66 | wc.lpfnWndProc = DefWindowProc; |
| 67 | wc.hInstance = hInstance; |
| 68 | wc.hCursor = LoadCursor(nullptr, IDC_ARROW); |
| 69 | wc.lpszClassName = c_szSplashClass; |
| 70 | RegisterClass(&wc); |
| 71 | |
| 72 | // image |
| 73 | CImage img; // объект изображения |
| 74 | |
| 75 | CHAR path[MAX_PATH]; |
| 76 | |
| 77 | GetModuleFileName(nullptr, path, MAX_PATH); |
| 78 | |
| 79 | std::string splash_path{path}; |
| 80 | splash_path = splash_path.erase(splash_path.find_last_of('\\'), splash_path.size() - 1); |
| 81 | splash_path += "\\splash.png"; |
| 82 | |
| 83 | HRESULT hr = img.Load(splash_path.c_str()); // загрузка сплеша |
| 84 | |
| 85 | if (FAILED(hr) || img.IsNull()) // если картинки нет на диске, то грузим из ресурсов |
| 86 | { |
| 87 | img.Destroy(); |
| 88 | if (IStream* pStream = CreateStreamOnResource(MAKEINTRESOURCE(IDB_PNG1), TEXT("PNG"))) |
| 89 | { |
| 90 | img.Load(pStream); |
| 91 | pStream->Release(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // фиксируем ширину картинки |
| 96 | // фиксируем высоту картинки |
| 97 | const int splashWidth = img.GetWidth(); |
| 98 | const int splashHeight = img.GetHeight(); |
| 99 | |
| 100 | const HWND hwndOwner = CreateWindow(c_szSplashClass, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); |
| 101 | const HWND hWnd = CreateWindowEx(WS_EX_LAYERED, c_szSplashClass, nullptr, WS_POPUP, 0, 0, 0, 0, hwndOwner, nullptr, hInstance, nullptr); |
| 102 | |
| 103 | if (!hWnd) |
| 104 | return; |
| 105 | |
| 106 | const HDC hdcScreen = GetDC(nullptr); |
| 107 | const HDC hDC = CreateCompatibleDC(hdcScreen); |
| 108 | |
| 109 | HBITMAP hBmp = CreateCompatibleBitmap(hdcScreen, splashWidth, splashHeight); |
| 110 | const HBITMAP hbmpOld = (HBITMAP)SelectObject(hDC, hBmp); |
| 111 | |
| 112 | // рисуем картиночку |
| 113 | for (int i = 0; i < img.GetWidth(); i++) |
| 114 | { |
| 115 | for (int j = 0; j < img.GetHeight(); j++) |
| 116 | { |
| 117 | BYTE* ptr = (BYTE*)img.GetPixelAddress(i, j); |
| 118 | ptr[0] = ((ptr[0] * ptr[3]) + 127) / 255; |
| 119 | ptr[1] = ((ptr[1] * ptr[3]) + 127) / 255; |
| 120 | ptr[2] = ((ptr[2] * ptr[3]) + 127) / 255; |
no test coverage detected