📄 keygen.dpr
字号:
program Keygen;
uses Windows, Messages;
{$R Keygen.res}
const
IDC_EDIT_NAME = 1001;
IDC_EDIT_CODE = 1002;
IDC_BUTTON_KEYGEN = 1003;
IDC_BUTTON_ABOUT = 1004;
IDC_BUTTON_EXIT = 1005;
IDC_ABOUT_OK = 2001;
IDC_MAINICON = 10001;
IDC_SMALLICON = 10002;
IDC_LOGOICON = 10003;
szMainDlg = 'MainDlg';
szAboutDlg = 'AboutDlg';
szHint = 'More chars needed.';
///如果直接使用IntToStr函数需要引用SysUtils单元,会大量增加最终编译出的可执行文件的大小,这里采用另外的方案
function Int2Str(const i: integer): string;
begin
Str(i, Result);
end;
///运算注册码的关键函数。这里只简单计算用户名的ASCII码的十进制值总和,作为示例。大家可根据各软件的不同算法自行编写。
function GetCode(Username: string): string;
var
tmpInt, iCount: integer;
begin
tmpInt := 0;
if length(Username)<3 then
Result := szHint
else
begin
for iCount := 1 to length(Username) do
tmpInt := tmpInt + ord(Username[iCount]);
Result := Int2Str(tmpInt);//IntToStr();
end;
end;
///“关于”对话框的处理
function AboutDlgProc(hAboutWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
case Msg of
WM_CLOSE:
EndDialog(hAboutWnd, 1);
WM_COMMAND:
if LOWORD(wParam) = IDC_ABOUT_OK then
EndDialog(hAboutWnd, 1);
end;
Result:=0;
end;
///主窗口对话框的处理
function MainDlgProc(hMainDlgWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
Name: array[0..512] of Char;
PaintStruct: TPaintStruct;
PaintDC: HDC;
hSpecFont: HFONT;
begin
case Msg of///处理不同信息
WM_INITDIALOG:///主窗口初始化
begin
SendMessage(hMainDlgWnd, WM_SETICON, ICON_SMALL, LoadIcon(hInstance, MAKEINTRESOURCE(IDC_SMALLICON)));///设置标题栏图标
SetDlgItemText(hMainDlgWnd, IDC_EDIT_CODE, PChar(szHint));///初始化“注册码”编辑框
end;
WM_COMMAND:
begin
case LOWORD(wParam) of
IDC_EDIT_NAME:
if HIWORD(wParam) = EN_CHANGE then///注册码实时运算的关键
begin
GetDlgItemText(hMainDlgWnd, IDC_EDIT_NAME, Name, 255);
SetDlgItemText(hMainDlgWnd, IDC_EDIT_CODE, PChar(GetCode(string(Name))));
end;
end;
end;
WM_PAINT:
begin
PaintDC := BeginPaint(hMainDlgWnd, PaintStruct);
MovetoEx(PaintDC, 10, 140, nil);
LineTo(PaintDC, 325, 140);
MovetoEx(PaintDC, 10, 203, nil);
LineTo(PaintDC, 325, 203);
MovetoEx(PaintDC, 10, 205, nil);
LineTo(PaintDC, 325, 205);
hSpecFont := CreateFont(-11, 0, 0, 0, FW_BOLD, 0, 1, 0, DEFAULT_CHARSET, 0, 0, 0, 0, 'Georgia');
SelectObject(PaintDC, hSpecFont);
SetBkColor(PaintDC, GetSysColor(COLOR_BTNFACE));
SetTextColor(PaintDC,RGB($33,$99,$33));
TextOut(PaintDC, 213, 211, PChar('CoDe bY xnbyte '), 14);
TextOut(PaintDC, 245, 228, PChar('2006-08-08 '), 10);
end;
WM_LBUTTONDBLCLK:///双击弹出“关于”对话框
DialogBoxParam(hInstance, szAboutDlg, hMainDlgWnd, @AboutDlgProc, 0);
WM_CLOSE:
EndDialog(hMainDlgWnd, 1);
end;
Result := 0;
end;
begin
DialogBoxParam(hInstance, szMainDlg, 0, @MainDlgProc, 0);
ExitProcess(0);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -