first commit
This commit is contained in:
@@ -0,0 +1,230 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <process.h>
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
|
||||
#define IDI_MAIN 1
|
||||
#define ID_MAC 101
|
||||
#define ID_GEN 102
|
||||
#define ID_STATUS 103
|
||||
|
||||
static void StartBGM(void)
|
||||
{
|
||||
mciSendStringW(L"open poemstear.mp3 type mpegvideo alias bgm", NULL, 0, NULL);
|
||||
mciSendStringW(L"play bgm repeat", NULL, 0, NULL);
|
||||
}
|
||||
|
||||
static void StopBGM(void)
|
||||
{
|
||||
mciSendStringW(L"close bgm", NULL, 0, NULL);
|
||||
}
|
||||
|
||||
static void generate(const char* mac, char* out, int sz)
|
||||
{
|
||||
char conv[256]; memset(conv,0,sizeof(conv));
|
||||
int ci = 0, i;
|
||||
for (i = 0; mac[i] && ci < 250; i++) {
|
||||
char c = (char)toupper(mac[i]);
|
||||
if (c == '-' || c == ' ') continue;
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
int v = c - 'A' + 1;
|
||||
conv[ci++] = (v / 10) + '0';
|
||||
conv[ci++] = (v % 10) + '0';
|
||||
} else if (c >= '0' && c <= '9') {
|
||||
conv[ci++] = c;
|
||||
}
|
||||
}
|
||||
int len = (int)strlen(conv);
|
||||
for (i = 0; i < len && i < sz - 1; i++)
|
||||
out[i] = conv[len - 1 - i];
|
||||
out[(len < sz) ? len : sz - 1] = 0;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK SetChildFont(HWND hh, LPARAM ff)
|
||||
{
|
||||
SendMessageW(hh, WM_SETFONT, (WPARAM)ff, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static HFONT hfTitle, hfBody;
|
||||
static HBRUSH hbrDark, hbrDarker, hbrAccent;
|
||||
static HPEN hpBorder;
|
||||
|
||||
static void InitTheme(void)
|
||||
{
|
||||
hbrDark = CreateSolidBrush(RGB(32, 32, 32));
|
||||
hbrDarker = CreateSolidBrush(RGB(22, 22, 22));
|
||||
hbrAccent = CreateSolidBrush(RGB(0, 120, 212));
|
||||
hpBorder = CreatePen(PS_SOLID, 1, RGB(0, 120, 212));
|
||||
NONCLIENTMETRICSW nm = {sizeof(nm)};
|
||||
SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(nm), &nm, 0);
|
||||
nm.lfMenuFont.lfHeight = -22;
|
||||
nm.lfMenuFont.lfWeight = FW_SEMIBOLD;
|
||||
hfTitle = CreateFontIndirectW(&nm.lfMenuFont);
|
||||
nm.lfMenuFont.lfHeight = -15;
|
||||
nm.lfMenuFont.lfWeight = FW_NORMAL;
|
||||
hfBody = CreateFontIndirectW(&nm.lfMenuFont);
|
||||
}
|
||||
|
||||
static HWND CreateMetroButton(HWND parent, LPCWSTR text, int x, int y, int w, int h, int id)
|
||||
{
|
||||
return CreateWindowW(L"BUTTON", text,
|
||||
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT|BS_OWNERDRAW,
|
||||
x, y, w, h, parent, (HMENU)id, NULL, NULL);
|
||||
}
|
||||
|
||||
static void DrawMetroButton(HWND hBtn, LPDRAWITEMSTRUCT dis)
|
||||
{
|
||||
wchar_t txt[64];
|
||||
GetWindowTextW(hBtn, txt, 64);
|
||||
int pressed = (dis->itemState & ODS_SELECTED);
|
||||
int hot = (dis->itemState & ODS_HOTLIGHT);
|
||||
HBRUSH br = pressed ? CreateSolidBrush(RGB(0, 90, 170))
|
||||
: hot ? CreateSolidBrush(RGB(0, 105, 190))
|
||||
: hbrAccent;
|
||||
FillRect(dis->hDC, &dis->rcItem, br);
|
||||
if (!pressed && !hot) DeleteObject(br);
|
||||
SetBkMode(dis->hDC, TRANSPARENT);
|
||||
SetTextColor(dis->hDC, RGB(255,255,255));
|
||||
SelectObject(dis->hDC, hfTitle);
|
||||
DrawTextW(dis->hDC, txt, -1, &dis->rcItem, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM w, LPARAM l)
|
||||
{
|
||||
static HWND hm, hg, hs;
|
||||
switch (msg) {
|
||||
case WM_CREATE: {
|
||||
InitTheme();
|
||||
/* Metro dark background */
|
||||
SetClassLongPtrW(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)hbrDark);
|
||||
|
||||
HWND h = CreateWindowW(L"STATIC", L"Resource Center License Generator",
|
||||
WS_CHILD|WS_VISIBLE|SS_CENTER, 20, 20, 400, 36, hWnd, NULL, NULL, NULL);
|
||||
SendMessageW(h, WM_SETFONT, (WPARAM)hfTitle, 1);
|
||||
|
||||
CreateWindowW(L"STATIC", L"MAC ADDRESS",
|
||||
WS_CHILD|WS_VISIBLE, 25, 75, 120, 22, hWnd, NULL, NULL, NULL);
|
||||
|
||||
hm = CreateWindowExW(WS_EX_CLIENTEDGE, L"EDIT", L"",
|
||||
WS_CHILD|WS_VISIBLE|WS_BORDER|ES_UPPERCASE|ES_AUTOHSCROLL|ES_CENTER,
|
||||
150, 72, 250, 30, hWnd, (HMENU)ID_MAC, NULL, NULL);
|
||||
|
||||
hg = CreateMetroButton(hWnd, L"GENERATE LICENSE", 90, 125, 260, 38, ID_GEN);
|
||||
|
||||
hs = CreateWindowW(L"STATIC", L"",
|
||||
WS_CHILD|WS_VISIBLE|SS_CENTER,
|
||||
20, 180, 400, 50, hWnd, (HMENU)ID_STATUS, NULL, NULL);
|
||||
|
||||
SendMessageW(hm, WM_SETFONT, (WPARAM)hfBody, 1);
|
||||
SendMessageW(hs, WM_SETFONT, (WPARAM)hfBody, 1);
|
||||
|
||||
SetFocus(hm);
|
||||
StartBGM();
|
||||
return 0;
|
||||
}
|
||||
case WM_DRAWITEM:
|
||||
if (w == ID_GEN) DrawMetroButton(hg, (LPDRAWITEMSTRUCT)l);
|
||||
return 0;
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(w) == ID_GEN) {
|
||||
char mac[64] = {0};
|
||||
GetWindowTextA(hm, mac, sizeof(mac));
|
||||
if (!mac[0]) {
|
||||
SetWindowTextW(hs, L"Please enter a MAC address");
|
||||
FlashWindow(hWnd, TRUE);
|
||||
return 0;
|
||||
}
|
||||
char lic[256];
|
||||
generate(mac, lic, sizeof(lic));
|
||||
if (!lic[0]) {
|
||||
SetWindowTextW(hs, L"Invalid MAC address");
|
||||
FlashWindow(hWnd, TRUE);
|
||||
return 0;
|
||||
}
|
||||
FILE* f = fopen("res_center.lic", "w");
|
||||
if (f) {
|
||||
fprintf(f, "%s", lic);
|
||||
fclose(f);
|
||||
wchar_t wlic[380];
|
||||
swprintf(wlic, 380, L"LICENSE GENERATED\nCopy res_center.lic to config\\lic\\\nKey: %hs", lic);
|
||||
SetWindowTextW(hs, wlic);
|
||||
} else {
|
||||
SetWindowTextW(hs, L"ERROR: Cannot write file");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
case WM_CTLCOLORSTATIC:
|
||||
case WM_CTLCOLOREDIT:
|
||||
case WM_CTLCOLORBTN: {
|
||||
HDC hdc = (HDC)w;
|
||||
SetBkColor(hdc, RGB(45, 45, 45));
|
||||
SetTextColor(hdc, RGB(255, 255, 255));
|
||||
return (LRESULT)hbrDarker;
|
||||
}
|
||||
case WM_DESTROY:
|
||||
StopBGM();
|
||||
Sleep(200);
|
||||
if (hfTitle) DeleteObject(hfTitle);
|
||||
if (hfBody) DeleteObject(hfBody);
|
||||
if (hbrDark) DeleteObject(hbrDark);
|
||||
if (hbrDarker) DeleteObject(hbrDarker);
|
||||
if (hbrAccent) DeleteObject(hbrAccent);
|
||||
if (hpBorder) DeleteObject(hpBorder);
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_NCHITTEST:
|
||||
return DefWindowProcW(hWnd, msg, w, l);
|
||||
}
|
||||
return DefWindowProcW(hWnd, msg, w, l);
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hi, HINSTANCE hp, LPSTR cmd, int show)
|
||||
{
|
||||
(void)hp; (void)cmd; (void)show;
|
||||
WNDCLASSW wc = {0};
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = hi;
|
||||
wc.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
|
||||
wc.hbrBackground = CreateSolidBrush(RGB(32, 32, 32));
|
||||
wc.lpszClassName = L"RCKeygenWnd";
|
||||
wc.hIcon = LoadIconW(hi, MAKEINTRESOURCEW(IDI_MAIN));
|
||||
wc.style = CS_HREDRAW|CS_VREDRAW;
|
||||
RegisterClassW(&wc);
|
||||
|
||||
int sw = GetSystemMetrics(SM_CXSCREEN), sh = GetSystemMetrics(SM_CYSCREEN);
|
||||
int ww = 480, wh = 270;
|
||||
|
||||
/* Enable drop shadow (Win10+) */
|
||||
HMODULE dui = LoadLibraryW(L"user32.dll");
|
||||
if (dui) {
|
||||
typedef BOOL (WINAPI *SetWindowCompositionAttribute_t)(HWND, void*);
|
||||
SetWindowCompositionAttribute_t fn = (SetWindowCompositionAttribute_t)
|
||||
GetProcAddress(dui, "SetWindowCompositionAttribute");
|
||||
if (fn) {
|
||||
/* dark mode support */
|
||||
}
|
||||
FreeLibrary(dui);
|
||||
}
|
||||
|
||||
HWND hWnd = CreateWindowExW(0, L"RCKeygenWnd", L"ResCenter Keygen v2.0",
|
||||
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_VISIBLE,
|
||||
(sw-ww)/2, (sh-wh)/2, ww, wh, NULL, NULL, hi, NULL);
|
||||
|
||||
/* dark title bar (Win10 1809+) */
|
||||
BOOL dark = TRUE;
|
||||
DwmSetWindowAttribute(hWnd, 19 /*DWMWA_USE_IMMERSIVE_DARK_MODE*/,
|
||||
&dark, sizeof(dark));
|
||||
DwmSetWindowAttribute(hWnd, 20 /*DWMWA_USE_IMMERSIVE_DARK_MODE before 20H1*/,
|
||||
&dark, sizeof(dark));
|
||||
|
||||
MSG msg;
|
||||
while (GetMessageW(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user