#include once "window9.bi"

Type InputBox_
  As MSG msg
  As HWND hWnd,hwnd1,hwnd2,hwnd3
  As String*1024 mess
  As BOOL flag
  as DEVMODE dm(0)
  As HFONT font,font1
  As Integer size
End Type

Function InputBox(ByVal Caption As String, ByVal Message As String="Enter text:", ByVal DefaultString As String="", ByVal flag As Integer=0, ByVal flag2 As Integer=0) As String Export
  Dim InputBox_ As InputBox_
  InputBox_.dm(0).dmSize = sizeof(DEVMODE)
  EnumDisplaySettings( 0, ENUM_CURRENT_SETTINGS, @InputBox_.dm(0))
  InputBox_.hWnd  = CreateWindowEx(0, "#32770", Caption, WS_TILED Or WS_VISIBLE, InputBox_.dm(0).dmPelsWidth/2-155, InputBox_.dm(0).dmPelsHeight/2-70, 310, 130, 0, 0, 0, 0 )
  InputBox_.hWnd1 = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", DefaultString, WS_CHILD Or WS_VISIBLE Or flag, 10, 33, 275, 25, InputBox_.hwnd,0,0,0)
  InputBox_.hWnd2 = CreateWindowEx(0, "Button", "OK", WS_CHILD Or WS_VISIBLE, 106, 65, 80, 25, InputBox_.hwnd,0,0,0)
  InputBox_.hWnd3 = CreateWindowEx(0, "Static", Message, WS_CHILD Or WS_VISIBLE, 10, 10, 275, 20, InputBox_.hwnd,0,0,0)
  InputBox_.size  = -MulDiv(10, GetDeviceCaps(CreateDC("DISPLAY",0,0,0), LOGPIXELSY), 72)
  InputBox_.font  = CreateFont(InputBox_.size,0,0,0,0,1,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH Or FF_DONTCARE,"Times New Roman")
  SendMessage(InputBox_.hWnd3,WM_SETFONT,Cast(WPARAM,InputBox_.font),0)
  InputBox_.font1 = CreateFont(InputBox_.size,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH Or FF_DONTCARE,"Times New Roman")
  SendMessage(InputBox_.hWnd2,WM_SETFONT,Cast(WPARAM,InputBox_.font1),0)
  SendMessage(InputBox_.hWnd1,WM_SETFONT,Cast(WPARAM,InputBox_.font1),0)

  While GetMessage(@InputBox_.msg, 0, 0, 0 )
    TranslateMessage(@InputBox_.msg )
    DispatchMessage(@InputBox_.msg )
    Select Case InputBox_.msg.hwnd
      Case InputBox_.hWnd2
        Select Case InputBox_.msg.message
          Case WM_LBUTTONDOWN
            SendMessage(InputBox_.hWnd1,WM_GETTEXT,1024,Cast(LPARAM ,@InputBox_.mess))
            Function= InputBox_.mess
            DestroyWindow(InputBox_.hWnd)
            InputBox_.flag=0
            Exit Function
        End Select
      Case InputBox_.hWnd1
        If InputBox_.msg.message=WM_LBUTTONDOWN Then
          If flag2<>0 Then
            If InputBox_.flag=0 Then
              InputBox_.flag=1
              SetWindowText(InputBox_.hWnd1,@"")
            EndIf
          EndIf
        EndIf
    End Select
  Wend
End Function
