把分给我,因为我会给你0距离的帮助。
以下代码修改自Delphi原来的Dialogs单元,如果你想原来一样用,只需将其覆盖原来的函数
即可,否则在使用时,加上uses xInput;
unit xInput;
interface
uses Windows, Messages;
function xInputBox(ACaption, APrompt : String; ADefault: string=''; PwChar:Char=#0): string;
function xInputQuery(ACaption, APrompt: string;
var Value: string; PwChar:Char=#0): Boolean;
implementation
function xInputBox(ACaption, APrompt : String; ADefault: string; PwChar:Char): string;
begin
Result := ADefault;
xInputQuery(ACaption, APrompt, Result);
end;
function xInputQuery(ACaption, APrompt: string; var Value: string; PwChar:Char): Boolean;
var
wClass: TWndClass; // class struct for main window
hFont, // handle of font
hInst, // handle of program (hinstance)
hHandle, // Handle of main window
hOkBtn, // Handle of encrypt button
hCancelBtn, // handle of decrypt button
hEdit, // handle of main edit
hLabel : HWND; // handle of password label
Msg: TMSG; // message struct
dOK, dCancel : Pointer; // default button procedures
ButtonTop, ButtonWidth, ButtonHeight: Integer;
procedure Resize;//移动窗体
var RCT:TRect;
begin
GetWindowRect(hHandle,RCT);
MoveWindow(hEdit,230,5,RCT.Right-RCT.Left-245,24,True);
end;
procedure ShutDown;//关闭
begin
DeleteObject(hFont);
UnRegisterClass('xInputBox',hInst);
ExitProcess(hInst); //end program
end;
//响应消息
function WindowProc(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
// Always pass the message to the Default procedure
Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
case Msg of
WM_SIZE: Resize;
// When buttons are clicked the message is passed to
// the parent window, so we handle it here.
WM_COMMAND: if lParam=hOkBtn then ShutDown
else if lParam=hCancelBtn then ShutDown;
WM_DESTROY: ShutDown;
end;
end;
function OnOk(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
var
i: Integer;
begin
// Always pass the message to the Default procedure
Result:=CallWindowProc(dOk,hWnd,Msg,wParam,lParam);
case Msg of
// If the user presses TAB we're gunna switch the
// focus over to the Decrypt button.
WM_KEYDOWN: if wParam=9 then SetFocus(hCancelBtn);
end;
end;
// This function processes every message sent to the Decrypt Button
function OnCancel(hWnd,Msg,wParam,lParam:Longint):Longint; stdcall;
begin
// Always pass the message to the Default procedure
Result:=CallWindowProc(dCancel,hWnd,Msg,wParam,lParam);
case Msg of
// if the user presses TAB we're gunna switch
// the focus back to the Encrypt button.
WM_KEYDOWN: if wParam=9 then SetFocus(hOkBtn);
end;
end;
begin
Result := False;
if ACaption='' then ACaption := '请输入';
if APrompt='' then APrompt := '请在下面的文本框中输入:';
hInst:=GetModulehandle(nil); // 获取程序句柄
with wClass do
begin
Style:= CS_PARENTDC;
hIcon:= LoadIcon(hInst,'MAINICON');
lpfnWndProc:= @WindowProc;
hInstance:= hInst;
hbrBackground:= COLOR_BTNFACE+1;
lpszClassName:= 'xInputBox';
hCursor:= LoadCursor(0,IDC_ARROW);
end;
// Once our class is registered we
// can start making windows with it
RegisterClass(wClass);
//建立主窗口
hHandle:=CreateWindow(
'xInputBox', // Registered Class Name
PChar(ACaption), // Title of Window
WS_OVERLAPPEDWINDOW or // Basic Window Style
WS_VISIBLE, // Make it Visible
10, 10, 400, 300, // Left Top Width Height
0, 0, // Parent Window and Menu handle
hInst, // Application Instance
nil); // Structure for Creation Data
//创建确定按钮
hOkBtn:=CreateWindow(
'Button', '确定(&O)',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
5,5,65,24,hHandle,0,hInst,nil);
//创建取消按钮
hCancelBtn:=CreateWindow(
'Button', '取消(&C)',
WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
75,5,65,24,hHandle,0,hInst,nil);
//创建输入框
hEdit:=CreateWindowEx(
WS_EX_CLIENTEDGE,
'Edit', '',
WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL or ES_PASSWORD,
230,5,155,24,hHandle,0,hInst,nil);
//创建提示条
hLabel:=CreateWindow(
'Static', PChar(APrompt),
WS_VISIBLE or WS_CHILD or SS_LEFT,
160,10,70,20,hHandle,0,hInst,nil);
//为窗口创建自定字体,否则将使用系统字体
hFont:=CreateFont(-12, 0, 0, 0, //高度 宽度 旋转角度 方向
0, 0, 0, 0, //Weight 斜体 下线 // Strike Out // Italic
DEFAULT_CHARSET, // Char Set
OUT_DEFAULT_PRECIS, // Precision
CLIP_DEFAULT_PRECIS, // Clipping
DEFAULT_QUALITY, // Render Quality
DEFAULT_PITCH or FF_DONTCARE, // Pitch & Family
'宋体'); // Font Name
// Set the fonts for all our controls
SendMessage(hOkBtn,WM_SETFONT,hFont,0);
SendMessage(hCancelBtn,WM_SETFONT,hFont,0);
SendMessage(hEdit,WM_SETFONT,hFont,0);
SendMessage(hLabel,WM_SETFONT,hFont,0);
// Subclass Encrypt Button (assign it a custom WindowProc)
dOk:=Pointer(GetWindowLong(hOkBtn,GWL_WNDPROC));
SetWindowLong(hOkBtn,GWL_WNDPROC,Longint(@OnOk));
// Subclass Decrypt Button
dCancel:=Pointer(GetWindowLong(hCancelBtn,GWL_WNDPROC));
SetWindowLong(hCancelBtn,GWL_WNDPROC,Longint(@OnCancel));
// Focus on first control (otherwise people with no mouse are screwed)
SetFocus(hOkBtn);
// Now we loop GetMessage to process each Message in
// our main window's message list. Every time the main
// window recieves a message its added to the list, so
// this loop here will eventually process it.
while(GetMessage(Msg,hHandle,0,0))do
begin
TranslateMessage(Msg); // Translate any keyboard Msg's
DispatchMessage(Msg); // Send it to our WindowProc
end; // for processing.
end;
end.