Last active
August 7, 2026 02:28
-
-
Save whitequark/203f60a101db4bd9f876654eb0c6e837 to your computer and use it in GitHub Desktop.
TEXT="MyCoolSoftware3000" wine installsword.exe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define WIN32_LEAN_AND_MEAN | |
| #include <windows.h> | |
| #include <tchar.h> | |
| #include <msi.h> | |
| #include <stdint.h> | |
| #define MSICALL __declspec(dllexport) __cdecl | |
| COLORREF rgbText = 0xffffff; | |
| LPTSTR pchFontName = _T("Times New Roman"); | |
| INT iFontSizePt = 24; | |
| LPTSTR pchText = _T("InstallSword Wizard"); | |
| BOOL hasBackdrop = TRUE; | |
| void DrawGradient(HWND hWnd, HDC hdc) | |
| { | |
| RECT rc; | |
| GetClientRect(hWnd, &rc); | |
| int i, nBars = (rc.bottom / 8) + 1; | |
| nBars = min(nBars, 60); | |
| COLORREF rgbMax = 0xff0000; | |
| COLORREF prgbBars[60]; | |
| prgbBars[0] = 0; | |
| prgbBars[nBars-1] = rgbMax; | |
| for (i = 1; nBars - 1 > i; i += 1) | |
| prgbBars[i] = RGB( | |
| GetRValue(rgbMax) * i / (nBars - 2), | |
| GetGValue(rgbMax) * i / (nBars - 2), | |
| GetBValue(rgbMax) * i / (nBars - 2) | |
| ); | |
| SelectObject(hdc, GetStockObject(NULL_PEN)); | |
| int32_t nBarHeight = rc.bottom / nBars; | |
| for (i = 1; nBars > i; i += 1) { | |
| HBRUSH hbr = CreateSolidBrush(prgbBars[nBars - i]); | |
| HGDIOBJ h = SelectObject(hdc, hbr); | |
| Rectangle(hdc, 0, (i - 1) * nBarHeight, rc.right + 1, nBarHeight * i + 1); | |
| SelectObject(hdc, h); | |
| DeleteObject(hbr); | |
| } | |
| SelectObject(hdc, GetStockObject(BLACK_BRUSH)); | |
| Rectangle(hdc, 0, (i - 1) * nBarHeight, rc.right + 1, rc.bottom + 1); | |
| } | |
| void DrawTitleText(HWND hWnd, HDC hdc) | |
| { | |
| static HFONT hFont; | |
| if (hFont == NULL) { | |
| LOGFONT lf; | |
| lf.lfQuality = DRAFT_QUALITY; | |
| lf.lfOutPrecision = OUT_TT_ONLY_PRECIS; | |
| lf.lfPitchAndFamily = VARIABLE_PITCH|FF_SWISS; | |
| lf.lfHeight = (GetDeviceCaps(hdc, LOGPIXELSY) * iFontSizePt) / -72; | |
| lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; | |
| lf.lfCharSet = ANSI_CHARSET; | |
| lf.lfWidth = 0; | |
| lf.lfWeight = 700; | |
| if (!hasBackdrop) | |
| lf.lfWeight = 400; | |
| lf.lfItalic = 1; | |
| lf.lfUnderline = 0; | |
| lf.lfEscapement = 0; | |
| lf.lfOrientation = 0; | |
| lf.lfStrikeOut = 0; | |
| _tcsncpy(lf.lfFaceName, pchFontName, sizeof(lf.lfFaceName) / sizeof(TCHAR)); | |
| hFont = CreateFontIndirect(&lf); | |
| } | |
| SelectObject(hdc, hFont); | |
| RECT rcText; | |
| GetClientRect(hWnd, &rcText); | |
| rcText.left = 5; | |
| rcText.top = 5; | |
| DrawText(hdc, pchText, -1, &rcText, DT_CALCRECT); | |
| SetBkMode(hdc, 1); | |
| if (hasBackdrop) | |
| { | |
| SetTextColor(hdc, 0x0000000); | |
| SetBkColor(hdc, 0); | |
| RECT rcBackdrop = rcText; | |
| OffsetRect(&rcBackdrop, 4, 4); | |
| DrawText(hdc, pchText, -1, &rcBackdrop, | |
| DT_EXPANDTABS | DT_NOCLIP | DT_NOPREFIX | DT_WORDBREAK); | |
| } | |
| SetTextColor(hdc, rgbText); | |
| SetBkColor(hdc, 0); | |
| DrawText(hdc, pchText, -1, &rcText, | |
| DT_EXPANDTABS | DT_NOCLIP | DT_NOPREFIX | DT_WORDBREAK); | |
| } | |
| LRESULT CALLBACK MainWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) | |
| { | |
| switch (Msg) { | |
| case WM_PAINT: { | |
| PAINTSTRUCT ps; | |
| HDC hdc = BeginPaint(hWnd, &ps); | |
| DrawGradient(hWnd, hdc); | |
| DrawTitleText(hWnd, hdc); | |
| EndPaint(hWnd, &ps); | |
| return 0; | |
| } | |
| case WM_CLOSE: | |
| DestroyWindow(hWnd); | |
| return 0; | |
| #ifdef DEMO | |
| case WM_DESTROY: | |
| PostQuitMessage(0); | |
| return 0; | |
| #endif | |
| default: | |
| return DefWindowProc(hWnd, Msg, wParam, lParam); | |
| } | |
| } | |
| HWND hWnd, hPrevOwner; | |
| UINT MSICALL ShowBackground(MSIHANDLE hInstall) | |
| { | |
| WNDCLASS wc = {0}; | |
| wc.lpszClassName = _T("InstallSword_Main"); | |
| wc.lpfnWndProc = MainWndProc; | |
| wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); | |
| wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
| if (!RegisterClass(&wc)) | |
| return FALSE; | |
| hWnd = CreateWindowEx(0, wc.lpszClassName, 0, | |
| WS_POPUP|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_GROUP|WS_TABSTOP, | |
| 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), | |
| NULL, NULL, NULL, 0); | |
| if (!hWnd) | |
| return FALSE; | |
| ShowWindow(hWnd, SW_SHOW); | |
| HWND hOwner = hWnd; | |
| MsiSetInternalUI(INSTALLUILEVEL_NOCHANGE, &hOwner); | |
| hPrevOwner = hOwner; | |
| return TRUE; | |
| } | |
| UINT MSICALL HideBackground(MSIHANDLE hInstall) | |
| { | |
| MsiSetInternalUI(INSTALLUILEVEL_NOCHANGE, &hPrevOwner); | |
| DestroyWindow(hWnd); | |
| } | |
| #ifdef DEMO | |
| int WINAPI _tWinMain( | |
| HINSTANCE hInstance, | |
| HINSTANCE hPrevInstance, | |
| LPTSTR lpCmdLine, | |
| int nShowCmd | |
| ) | |
| { | |
| LPTSTR pchTextEnv = _tgetenv(_T("TEXT")); | |
| if (pchTextEnv != NULL) | |
| pchText = pchTextEnv; | |
| ShowBackground(0); | |
| MSG msg; | |
| while (GetMessage(&msg, 0, 0, 0)) | |
| DispatchMessage(&msg); | |
| return 0; | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment