Advertisement
HEX0x29A

InputBoxNumeric

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