原神兑换码生成器c++实现

代码:

#include <iostream>
#include <random>
#include <string>
#include <windows.h>

using namespace std;

const unsigned char x [ 36 ] = {
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J',
    'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U',
    'V', 'W', 'X', 'Y', 'Z',
    '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
};

HWND hEditOutput , hEditInput , hButton , hStaticText;

LRESULT CALLBACK WndProc (HWND hWnd , UINT msg , WPARAM wParam , LPARAM lParam) {
    switch ( msg ) {
    case WM_CREATE:
        // 创建静态文本
        hStaticText = CreateWindow (L"STATIC" , L"输入生成的兑换码个数" , WS_CHILD | WS_VISIBLE ,
            10 , 10 , 200 , 30 , hWnd , NULL , NULL , NULL);

        // 创建输入编辑框
        hEditInput = CreateWindowEx (WS_EX_CLIENTEDGE , L"EDIT" , L"" , WS_CHILD | WS_VISIBLE | ES_NUMBER | ES_AUTOHSCROLL ,
            10 , 40 , 200 , 30 , hWnd , NULL , NULL , NULL);

        // 创建输出编辑框
        hEditOutput = CreateWindowEx (WS_EX_CLIENTEDGE , L"EDIT" , L"" , WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY ,
            10 , 80 , 370 , 200 , hWnd , NULL , NULL , NULL);

        // 创建按钮
        hButton = CreateWindow (L"BUTTON" , L"生成兑换码" , WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
            220 , 40 , 160 , 30 , hWnd , NULL , NULL , NULL);
        break;
    case WM_COMMAND:
        if ( ( HWND ) lParam == hButton && HIWORD (wParam) == BN_CLICKED ) { // 处理按钮点击事件
            int textLength = GetWindowTextLength (hEditInput);
            if ( textLength > 0 ) {
                wchar_t * buffer = new wchar_t [ textLength + 1 ];
                GetWindowText (hEditInput , buffer , textLength + 1);
                int a = _wtoi (buffer); // 将输入的文本转换为整数

                SendMessage (hEditOutput , WM_SETTEXT , NULL , ( LPARAM ) L""); // 清空输出框

                random_device rd;
                mt19937 gen (rd ());

                for ( int i = 0; i < a; i++ ) {
                    string code = "";
                    for ( int j = 0; j < 12; j++ ) {
                        code += x [ gen () % 36 ];
                    }
                    code += "\r\n";
                    SendMessageA (hEditOutput , EM_REPLACESEL , TRUE , ( LPARAM ) code.c_str ());
                }
                delete [ ] buffer; // 释放内存
            }
        }
        break;
    case WM_DESTROY:
        PostQuitMessage (0);
        break;
    default:
        return DefWindowProc (hWnd , msg , wParam , lParam);
    }
    return 0;
}

int WINAPI WinMain (HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd) {
    // 注册窗口类
    WNDCLASS wc = { 0 };
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = L"MainWindowClass";
    RegisterClass (&wc);

    // 创建窗口
    HWND hWnd = CreateWindow (L"MainWindowClass" , L"原神兑换码生成器" , WS_OVERLAPPEDWINDOW ,
        CW_USEDEFAULT , CW_USEDEFAULT , 400 , 340 , NULL , NULL , hInstance , NULL);

    // 显示窗口
    ShowWindow (hWnd , nShowCmd);
    UpdateWindow (hWnd);

    MSG msg;
    while ( GetMessage (&msg , NULL , 0 , 0) ) {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    return int (0); msg.wParam;
}

效果:

还是有一些瑕疵,就是生成的兑换码长度不一,望大佬指点

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值