a mega cool windows xp app

feat: add fake qrcode

dunkirk.sh 93d890be 2401993a

verified
.cache/clangd/index/main.cpp.47C66B394CD74271.idx

This is a binary file and will not be displayed.

.cache/clangd/index/qr.h.B46974D52593BF02.idx

This is a binary file and will not be displayed.

+11 -1
CMakeLists.txt
···
# Target Windows XP compatibility
add_definitions(-DWINVER=0x0501)
add_definitions(-D_WIN32_WINNT=0x0501)
+
add_definitions(-D_WIN32_WINNT_WIN2K=0x0500)
+
add_definitions(-DMINGW_HAS_SECURE_API=1)
+
+
# Disable threading to avoid mcfgthread dependency
+
add_compile_options(-fno-threadsafe-statics)
+
add_compile_options(-D_GLIBCXX_HAS_GTHREADS=0)
add_executable(HelloWorldApp WIN32 main.cpp)
target_link_libraries(HelloWorldApp user32 gdi32)
-
# Minimal static linking
+
# Include current directory for headers
+
target_include_directories(HelloWorldApp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
+
+
# Minimal static linking and avoid threading dependencies
target_link_options(HelloWorldApp PRIVATE
-static-libgcc
-static-libstdc++
+
-static
-Wl,--subsystem,windows:5.01
)
+82 -12
flake.nix
···
'';
buildPhase = ''
+
export LDFLAGS="-static -static-libgcc -static-libstdc++"
cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_SYSTEM_NAME=Windows \
-DCMAKE_C_COMPILER=$CC \
-
-DCMAKE_CXX_COMPILER=$CXX .
+
-DCMAKE_CXX_COMPILER=$CXX \
+
-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" .
make VERBOSE=1
'';
···
deploy-to-xp = pkgs.writeShellScriptBin "deploy-to-xp" ''
XP_DIR="$HOME/Documents/xp-drive"
mkdir -p "$XP_DIR"
-
cp ${self'.packages.hello-world-app}/bin/HelloWorld.exe "$XP_DIR/"
-
echo "Deployed HelloWorld.exe to $XP_DIR"
+
+
# Handle Windows file locking by using a temporary name first
+
TEMP_NAME="HelloWorld_new.exe"
+
OLD_NAME="HelloWorld_old.exe"
+
FINAL_NAME="HelloWorld.exe"
+
+
echo "Deploying to $XP_DIR..."
+
+
# Copy to temporary name first
+
if cp ${self'.packages.hello-world-app}/bin/HelloWorld.exe "$XP_DIR/$TEMP_NAME"; then
+
echo "✓ Copied new version as $TEMP_NAME"
+
+
# If the original exists, try to rename it
+
if [ -f "$XP_DIR/$FINAL_NAME" ]; then
+
if mv "$XP_DIR/$FINAL_NAME" "$XP_DIR/$OLD_NAME" 2>/dev/null; then
+
echo "✓ Backed up old version as $OLD_NAME"
+
else
+
echo "⚠ Warning: Could not backup old version (file may be in use)"
+
echo " Close the application on XP and try again, or manually rename files"
+
echo " New version is available as: $TEMP_NAME"
+
exit 1
+
fi
+
fi
+
+
# Move temp to final name
+
if mv "$XP_DIR/$TEMP_NAME" "$XP_DIR/$FINAL_NAME"; then
+
echo "✓ Deployed HelloWorld.exe successfully"
+
+
# Clean up old backup if it exists
+
if [ -f "$XP_DIR/$OLD_NAME" ]; then
+
rm -f "$XP_DIR/$OLD_NAME" 2>/dev/null || echo " (Old backup file remains)"
+
fi
+
else
+
echo "✗ Failed to finalize deployment"
+
exit 1
+
fi
+
else
+
echo "✗ Failed to copy new version"
+
exit 1
+
fi
+
+
echo ""
+
echo "Deployment complete! 🎉"
+
echo "You can now run the updated application on XP"
'';
setup-dev = pkgs.writeShellScriptBin "setup-dev" ''
echo "Setting up development environment for Zed..."
# Get the proper MinGW headers - use the known path from our build
+
GCC_BASE="/nix/store/l2gk3vvpdf33jf3gnfljyyx3dgwks8zp-i686-w64-mingw32-stage-final-gcc-debug-10.3.0/i686-w64-mingw32"
+
SYS_INCLUDE="$GCC_BASE/sys-include"
MINGW_MAIN_INCLUDE="/nix/store/hhbkp872dkayzd2qxfhkdc4rgn393g52-mingw-w64-i686-w64-mingw32-9.0.0-dev/include"
+
MCFGTHREAD_INCLUDE="/nix/store/21c6w351iwpblnfz2m9v3ssvxcmqsz7h-mcfgthreads-i686-w64-mingw32-git-dev/include"
+
CPP_INCLUDE="$GCC_BASE/include/c++/10.3.0"
+
CPP_TARGET_INCLUDE="$CPP_INCLUDE/i686-w64-mingw32"
-
# Verify it exists, if not try to find it dynamically
+
# Verify paths exist
+
if [ ! -f "$SYS_INCLUDE/stdlib.h" ]; then
+
echo "Error: Could not find C standard library at $SYS_INCLUDE"
+
exit 1
+
fi
+
if [ ! -f "$MINGW_MAIN_INCLUDE/windows.h" ]; then
-
echo "Static path not found, searching dynamically..."
-
MINGW_MAIN_INCLUDE=$(i686-w64-mingw32-gcc -v -E - < /dev/null 2>&1 | sed -n '/mingw-w64.*-dev\/include/p' | head -1 | awk '{print $2}')
-
-
if [ -z "$MINGW_MAIN_INCLUDE" ] || [ ! -f "$MINGW_MAIN_INCLUDE/windows.h" ]; then
-
echo "Error: Could not find proper MinGW headers with windows.h"
-
exit 1
-
fi
+
echo "Error: Could not find MinGW headers at $MINGW_MAIN_INCLUDE"
+
exit 1
+
fi
+
+
if [ ! -f "$CPP_INCLUDE/vector" ]; then
+
echo "Error: Could not find C++ standard library at $CPP_INCLUDE"
+
exit 1
+
fi
+
+
if [ ! -f "$MCFGTHREAD_INCLUDE/mcfgthread/gthread.h" ]; then
+
echo "Error: Could not find mcfgthread headers at $MCFGTHREAD_INCLUDE"
+
exit 1
fi
# Create simplified .clangd config to avoid intrinsics issues
···
- -std=c++17
- -fno-builtin
- -D__NO_INLINE__
+
- -isystem
+
- $SYS_INCLUDE
- -isystem
- $MINGW_MAIN_INCLUDE
+
- -isystem
+
- $MCFGTHREAD_INCLUDE
+
- -isystem
+
- $CPP_INCLUDE
+
- -isystem
+
- $CPP_TARGET_INCLUDE
Remove:
- -I*/gcc/*/include
EOF
···
EOF
echo "Generated simplified .clangd config and compile_commands.json"
+
echo "Using C standard library: $SYS_INCLUDE"
echo "Using MinGW headers: $MINGW_MAIN_INCLUDE"
+
echo "Using mcfgthread headers: $MCFGTHREAD_INCLUDE"
+
echo "Using C++ headers: $CPP_INCLUDE"
echo ""
-
echo "This avoids GCC intrinsics that cause clang issues"
+
echo "This includes complete C/C++ standard libraries and Win32 APIs"
echo "Restart Zed for the changes to take effect"
'';
+99 -10
main.cpp
···
#include <windows.h>
+
#include "qr.h"
#define ID_ABOUT 1001
#define ID_EXIT 1002
+
#define ID_GENERATE_QR 1003
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
+
+
// Global QR code instance - static allocation, no new/delete
+
QRCode g_qrCode;
+
BOOL g_hasQrCode = FALSE;
+
char g_qrText[256] = "Hello World!";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
const char* CLASS_NAME = "HelloWorldWindow";
···
// Create menu
HMENU hMenu = CreateMenu();
-
HMENU hSubMenu = CreatePopupMenu();
-
AppendMenu(hSubMenu, MF_STRING, ID_ABOUT, "&About");
-
AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL);
-
AppendMenu(hSubMenu, MF_STRING, ID_EXIT, "E&xit");
-
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "&Help");
+
// Tools menu
+
HMENU hToolsMenu = CreatePopupMenu();
+
AppendMenu(hToolsMenu, MF_STRING, ID_GENERATE_QR, "&Generate QR Pattern");
+
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hToolsMenu, "&Tools");
+
+
// Help menu
+
HMENU hHelpMenu = CreatePopupMenu();
+
AppendMenu(hHelpMenu, MF_STRING, ID_ABOUT, "&About");
+
AppendMenu(hHelpMenu, MF_SEPARATOR, 0, NULL);
+
AppendMenu(hHelpMenu, MF_STRING, ID_EXIT, "E&xit");
+
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hHelpMenu, "&Help");
SetMenu(hwnd, hMenu);
···
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
+
case WM_SIZE:
+
// Trigger repaint when window is resized
+
InvalidateRect(hwnd, NULL, TRUE);
+
return 0;
+
case WM_DESTROY:
+
// No cleanup needed for static allocation
PostQuitMessage(0);
return 0;
···
RECT rect;
GetClientRect(hwnd, &rect);
-
// Center the text
-
SetTextAlign(hdc, TA_CENTER);
-
SetBkMode(hdc, TRANSPARENT);
-
TextOut(hdc, rect.right / 2, rect.bottom / 2 - 10, "Hello World!", 12);
+
if (g_hasQrCode) {
+
// Draw QR code - calculate size based on window
+
int qrSize = QRCode_GetSize();
+
int moduleSize = 8;
+
int qrPixelSize = qrSize * moduleSize;
+
+
// Center horizontally and vertically with some padding
+
int startX = (rect.right - qrPixelSize) / 2;
+
int startY = (rect.bottom - qrPixelSize - 80) / 2; // Leave space for text
+
+
QRCode_DrawToHDC(&g_qrCode, hdc, startX, startY, moduleSize);
+
+
// Draw text below QR code
+
SetTextAlign(hdc, TA_CENTER);
+
SetBkMode(hdc, TRANSPARENT);
+
int textLen = 0;
+
while (g_qrText[textLen]) textLen++; // Calculate length
+
TextOut(hdc, rect.right / 2, startY + qrPixelSize + 20,
+
g_qrText, textLen);
+
+
// Add disclaimer
+
const char* disclaimer = "(Visual demo - not scannable)";
+
int disclaimerLen = 0;
+
while (disclaimer[disclaimerLen]) disclaimerLen++;
+
TextOut(hdc, rect.right / 2, startY + qrPixelSize + 40,
+
disclaimer, disclaimerLen);
+
} else {
+
// Default view - center in current window size
+
SetTextAlign(hdc, TA_CENTER);
+
SetBkMode(hdc, TRANSPARENT);
+
int centerY = rect.bottom / 2;
+
TextOut(hdc, rect.right / 2, centerY - 10, "Hello World!", 12);
+
TextOut(hdc, rect.right / 2, centerY + 10,
+
"Use Tools > Generate QR Pattern", 32);
+
}
EndPaint(hwnd, &ps);
return 0;
···
"Version: 1.0.0\n"
"Built by: Kieran Klukas\n\n"
"A simple Win32 application\n"
-
"compatible with Windows XP";
+
"compatible with Windows XP\n\n"
+
"Features:\n"
+
"- QR Pattern Generation (visual demo)\n"
+
"- XP Compatible Design\n"
+
"- Pure Win32 API";
MessageBox(hwnd, aboutText, "About Hello World App",
MB_OK | MB_ICONINFORMATION);
+
break;
+
}
+
case ID_GENERATE_QR: {
+
// Simple input dialog using InputBox simulation
+
if (MessageBox(hwnd, "Generate QR code pattern for current text?\n\n(Note: This creates a visual QR-like pattern for demo purposes,\nnot a scannable QR code)\n\nClick OK to use default text,\nor Cancel to cycle through presets.",
+
"Generate QR Pattern", MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL) {
+
+
// For now, use a simple preset - in a real app you'd want a proper input dialog
+
const char* presets[] = {
+
"Hello World!",
+
"https://github.com/taciturnaxolotl/shortwave",
+
"Made with love by Kieran Klukas",
+
"Windows XP Forever!",
+
"QR codes are cool!"
+
};
+
+
static int presetIndex = 0;
+
const char* selectedText = presets[presetIndex % 5];
+
presetIndex++;
+
+
// Copy selected text to global buffer
+
int i = 0;
+
while (selectedText[i] && i < 255) {
+
g_qrText[i] = selectedText[i];
+
i++;
+
}
+
g_qrText[i] = '\0';
+
}
+
+
// Generate new QR code - no new/delete, just reinitialize
+
QRCode_Init(&g_qrCode, g_qrText);
+
g_hasQrCode = TRUE;
+
+
// Refresh the window
+
InvalidateRect(hwnd, NULL, TRUE);
break;
}
case ID_EXIT:
+176
qr.h
···
+
#pragma once
+
#include <windows.h>
+
+
#define QR_SIZE 21
+
#define MAX_TEXT_LEN 256
+
+
// Pure C struct for QR code - no C++ classes
+
typedef struct {
+
BOOL modules[QR_SIZE][QR_SIZE];
+
char text[MAX_TEXT_LEN];
+
} QRCode;
+
+
// Function prototypes
+
void QRCode_Init(QRCode* qr, const char* inputText);
+
void QRCode_GeneratePattern(QRCode* qr);
+
void QRCode_AddFinderPattern(QRCode* qr, int x, int y);
+
BOOL QRCode_IsReserved(int x, int y);
+
void QRCode_DrawToHDC(QRCode* qr, HDC hdc, int startX, int startY, int moduleSize);
+
int QRCode_GetSize(void);
+
const char* QRCode_GetText(QRCode* qr);
+
+
// Implementation
+
void QRCode_Init(QRCode* qr, const char* inputText) {
+
int x, y, i;
+
+
// Initialize modules array
+
for (y = 0; y < QR_SIZE; y++) {
+
for (x = 0; x < QR_SIZE; x++) {
+
qr->modules[y][x] = FALSE;
+
}
+
}
+
+
// Copy text (safe copy)
+
i = 0;
+
while (inputText[i] && i < MAX_TEXT_LEN - 1) {
+
qr->text[i] = inputText[i];
+
i++;
+
}
+
qr->text[i] = '\0';
+
+
// Generate pattern
+
QRCode_GeneratePattern(qr);
+
}
+
+
void QRCode_GeneratePattern(QRCode* qr) {
+
int i, x, y;
+
unsigned int hash = 0;
+
unsigned char textBytes[MAX_TEXT_LEN];
+
int textLen = 0;
+
+
// Add finder patterns (corners)
+
QRCode_AddFinderPattern(qr, 0, 0);
+
QRCode_AddFinderPattern(qr, QR_SIZE - 7, 0);
+
QRCode_AddFinderPattern(qr, 0, QR_SIZE - 7);
+
+
// Add timing patterns
+
for (i = 8; i < QR_SIZE - 8; i++) {
+
qr->modules[6][i] = (i % 2 == 0) ? TRUE : FALSE;
+
qr->modules[i][6] = (i % 2 == 0) ? TRUE : FALSE;
+
}
+
+
// Convert text to bytes and calculate length
+
while (qr->text[textLen] && textLen < MAX_TEXT_LEN - 1) {
+
textBytes[textLen] = (unsigned char)qr->text[textLen];
+
textLen++;
+
}
+
+
// Add format information (fake but realistic looking)
+
// These would normally encode error correction level and mask pattern
+
qr->modules[8][0] = TRUE;
+
qr->modules[8][1] = FALSE;
+
qr->modules[8][2] = TRUE;
+
qr->modules[8][3] = TRUE;
+
qr->modules[8][4] = FALSE;
+
qr->modules[8][5] = TRUE;
+
+
// Add data in a more realistic zigzag pattern
+
int bitIndex = 0;
+
BOOL upward = TRUE;
+
+
for (x = QR_SIZE - 1; x > 0; x -= 2) {
+
if (x == 6) x--; // Skip timing column
+
+
for (i = 0; i < QR_SIZE; i++) {
+
y = upward ? (QR_SIZE - 1 - i) : i;
+
+
// Fill two columns (right to left)
+
for (int col = 0; col < 2; col++) {
+
int currentX = x - col;
+
if (currentX >= 0 && !QRCode_IsReserved(currentX, y)) {
+
// Use text data in a more structured way
+
BOOL bit = FALSE;
+
if (bitIndex < textLen * 8) {
+
int byteIndex = bitIndex / 8;
+
int bitPos = 7 - (bitIndex % 8);
+
bit = (textBytes[byteIndex] >> bitPos) & 1;
+
bitIndex++;
+
} else {
+
// Padding pattern
+
bit = ((currentX + y) % 3 == 0) ? TRUE : FALSE;
+
}
+
qr->modules[y][currentX] = bit;
+
}
+
}
+
}
+
upward = !upward;
+
}
+
}
+
+
void QRCode_AddFinderPattern(QRCode* qr, int x, int y) {
+
int dx, dy;
+
BOOL dark;
+
+
for (dy = 0; dy < 7; dy++) {
+
for (dx = 0; dx < 7; dx++) {
+
if (x + dx < QR_SIZE && y + dy < QR_SIZE) {
+
dark = (dx == 0 || dx == 6 || dy == 0 || dy == 6 ||
+
(dx >= 2 && dx <= 4 && dy >= 2 && dy <= 4)) ? TRUE : FALSE;
+
qr->modules[y + dy][x + dx] = dark;
+
}
+
}
+
}
+
}
+
+
BOOL QRCode_IsReserved(int x, int y) {
+
// Check if position is part of finder patterns
+
if ((x < 9 && y < 9) ||
+
(x >= QR_SIZE - 8 && y < 9) ||
+
(x < 9 && y >= QR_SIZE - 8)) {
+
return TRUE;
+
}
+
+
// Check timing patterns
+
if (x == 6 || y == 6) {
+
return TRUE;
+
}
+
+
// Check format information areas
+
if ((x < 9 && y == 8) || (x == 8 && y < 9)) {
+
return TRUE;
+
}
+
if ((x >= QR_SIZE - 8 && y == 8) || (x == 8 && y >= QR_SIZE - 7)) {
+
return TRUE;
+
}
+
+
return FALSE;
+
}
+
+
void QRCode_DrawToHDC(QRCode* qr, HDC hdc, int startX, int startY, int moduleSize) {
+
HBRUSH blackBrush = CreateSolidBrush(RGB(0, 0, 0));
+
HBRUSH whiteBrush = CreateSolidBrush(RGB(255, 255, 255));
+
int x, y;
+
RECT rect;
+
+
for (y = 0; y < QR_SIZE; y++) {
+
for (x = 0; x < QR_SIZE; x++) {
+
rect.left = startX + x * moduleSize;
+
rect.top = startY + y * moduleSize;
+
rect.right = startX + (x + 1) * moduleSize;
+
rect.bottom = startY + (y + 1) * moduleSize;
+
+
FillRect(hdc, &rect, qr->modules[y][x] ? blackBrush : whiteBrush);
+
}
+
}
+
+
DeleteObject(blackBrush);
+
DeleteObject(whiteBrush);
+
}
+
+
int QRCode_GetSize(void) {
+
return QR_SIZE;
+
}
+
+
const char* QRCode_GetText(QRCode* qr) {
+
return qr->text;
+
}