Advertisement
HEX0x29A

InputQueryEx (with MaxLength)

Mar 4th, 2014
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.26 KB | None | 0 0
  1. //InputQueryEx (with MaxLength)
  2. //Coded by HEX0x29A
  3. function InputQueryEx(Caption: string; Prompt: string;
  4.                       var Value: string; MaxLength: integer): Boolean;
  5. type
  6.   PThreadParam = ^TThreadParam;
  7.   TThreadParam = packed record
  8.     dwLength : DWORD;
  9.     dwParent : DWORD;
  10.     szCaption: string;
  11.   end;
  12. var
  13.   Param  : TThreadParam;
  14.   hThread: DWORD;
  15.  
  16.   procedure InputQueryThreadProc(Param: Pointer); stdcall;
  17.   var
  18.     wnd, tmp: HWND;
  19.   begin
  20.     wnd := 0;
  21.     repeat
  22.       Application.ProcessMessages;
  23.       tmp := FindWindow('TInputQueryForm', PWideChar(WideString(PThreadParam(Param).szCaption)));
  24.       if tmp <> 0 then
  25.       begin
  26.         if GetParent(tmp) = PThreadParam(Param).dwParent then
  27.         begin
  28.           wnd := FindWindowEx(tmp, 0, 'TEdit', nil);
  29.           if wnd <> 0 then
  30.           begin
  31.             SendMessage(wnd, EM_LIMITTEXT, PThreadParam(Param).dwLength, 0);
  32.           end;
  33.         end;
  34.       end;
  35.     until wnd <> 0;
  36.     ExitThread(0);
  37.   end;
  38.  
  39. begin
  40.   with Param do
  41.   begin
  42.     dwParent  := Application.ActiveFormHandle;
  43.     dwLength  := MaxLength;
  44.     szCaption := Caption;
  45.   end;
  46.   CreateThread(nil, 0, @InputQueryThreadProc, @Param, 0, hThread);
  47.   Result := InputQuery(Caption, Prompt, Value);
  48. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement