Minimum program

zhaozj2021-02-17  40

Program TestWindow;

Uses Windows, Messages;

Var Winclass: Twndclassa; INST, HANDLE, Button1, Label1, Edit1: Integer; MSG: TMSG; HFONT: Integer

{Checks if typed password is 'Amigreen' and shows Message} procedure CheckPassword; var Textlength: Integer; Text: PChar; begin TextLength: = GetWindowTextLength (Edit1); if TextLength = 8 then begin GetMem (Text, TextLength 1); GetWindowText (Edit1, Text, TextLength 1); if Text = 'Amigreen' Then Begin MessageBoxa (Handle, 'Password Is Correct.', 'Password Check', MB_OK); FreeMem (Text, TextLength 1); EXIT; End; MessageBoxa (Handle, 'Password Is IncorRect.', 'Password Check', MB_OK);

{Custom WindowProc function} function WindowProc (hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall; begin Result: = DefWindowProc (hWnd, uMsg, wParam, lParam); {Checks for messages} if (lParam = Button1) and (UMSG = WM_COMMAND) THEN CHECKPASSWORD; IF umsg = wm_destroy the Halt; End;

begin {** Register Custom WndClass **} Inst: = hInstance; with WinClass do begin style: = CS_CLASSDC or CS_PARENTDC; lpfnWndProc: = @WindowProc; hInstance: = Inst; hbrBackground: = color_btnface 1; lpszClassname: = 'AG_TESTWINDOW' Hcursor: = loadingcursor (0, IDC_ARROW); End; {with} registerclass (winclass);

{** Create Main Window **} Handle: = CreateWindowEx (WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'Amigreen TestWindow 1.00', WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU, 363, 278, 305, 65, 0, 0, Inst, nil) ; {** Create a button **} Button1: = CreateWindow ('Button', 'OK', WS_Visible or WS_Child OR BS_PUSHLIKE OR BS_TEXT, 216, 8, 75, 25, HANDLE, 0, INST, NIL); {* * Create a label (static) **} label1: = CreateWindow ('static', '', ws_visible or ws_child or ss_left, 8, 12, 76, 13, handle, 0, inst, nil); {** CREATE AN Edit Field **} Edit1: = CREATEWINDOWEX (WS_EX_CLIENTEDGE, 'Edit', '', ws_child or ws_visible or ws_border or es_password, 88, 8, 121, 21, handle, 0, inst, nil);

{** Create Font Handle **} hFont: = CreateFont (-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');

{Change Fonts} IF HFONT <> 0 THEN SENDMESSAGE (Button1, WM_SETFONT, HFONT, 0); SendMessage (Label1, WM_SETFONT, HFONT, 0); SendMessage (Edit1, WM_SETFONT, HFONT, 0); End; {Change Label TEXT} setWindowText (Label1, 'Enter Password:'); {set the focus to the edit control} setfocus (edit1);

UpdateWindow (Handle);

{** Message loop **} While (GetMessage (MSG, Handle, 0, 0)) DO Begin TranslateMessage (MSG); DISPATCHMESSAGE (MSG); end; {with} end.

转载请注明原文地址:https://www.9cbs.com/read-30431.html

New Post(0)