如何在不用Form等单元(包括KOL等控件)的情况下,弹出一个有标题的输入框?(类似EDIT 但有标题)
找了好久都找不到例子 高人指点一下吧,谢谢!delphi7下输入代码program Main;uses
  Windows,Messages;Var
  s:string;begin
   s := '输入框标题';   //在这如何弹出一个以上面为标题的输入框   //然后MessageBox弹出输入的内容
   MessageBox(0,PChar(输入的内容),'ok',0);
end.

解决方案 »

  1.   

    program Project1;uses
      Forms,Dialogs,windows;{$R *.res}
    var
      value:string;
    begin
      //Application.Initialize;
      //Application.Run;
      if InputQuery('输入框','请输入内容',value) then
      begin
        MessageBox(0,pchar(value),pchar('标题'),0);
      end;
    end.
      

  2.   

    谢谢一楼,不过你貌似没看懂我的问题...有高人能不用form吗 用MessageBox可能实现吗?
      

  3.   

    function InputQuery(const ACaption, APrompt: string;
      var Value: string): Boolean;
    var
      Form: TForm;
      Prompt: TLabel;
      Edit: TEdit;
      DialogUnits: TPoint;
      ButtonTop, ButtonWidth, ButtonHeight: Integer;晕哦哥们,你看这里是怎么声明的就知道了吗....
      

  4.   

    唉,真佩服楼主,现在我去掉那个forms,照样可以
    program Project1;uses
      Dialogs,windows;{$R *.res}
    var
      value:string;
    begin
      if InputQuery('输入框','请输入内容',value) then
      begin
        MessageBox(0,pchar(value),pchar('标题'),0);
      end;
    end.
      

  5.   

    InputQuery仍然使用了TForm类的。看来楼主是希望用纯WindowsAPI画一个输入框,并自己处理键盘消息。以下代码,修改自《InsideVCL》一书,修改得简陋一些,消息的处理、键值的处理只供演示
    program PMyWindowClass;uses
      Windows,
      Messages,
      SysUtils;type
      TMyWindow = class(TObject)
      private
        { Private declarations }
        WindowClass: WndClass;
        hWindow: HWnd;
        AMessage: TMsg;
        FAppName : String;
        FWndProc : TFNWndProc;    function WinRegister : Boolean; virtual;
        procedure CreateMyWindow;
      public
        { Public declarations }
        constructor Create;
        destructor Destroy; override;
        procedure WinCreate; virtual;
        procedure MyRun;    property ApplicationName : String read FAppName write FAppName;
        property WindowProcedure : TFNWndProc read FWndProc write FWndProc;
      end;const
      AppName = 'MyClassDemo';var
      myWindow : TMyWindow;
      Text : String = '';
    { TMyWindow }constructor TMyWindow.Create;
    beginend;destructor TMyWindow.Destroy;
    begin
      inherited;
    end;procedure TMyWindow.CreateMyWindow;
    begin
      hWindow := CreateWindow(AppName, '请按键...注:修改自《Inside VCL》',
                  ws_OverlappedWindow, cw_UseDefault, cw_UseDefault,
                  400, 60, 0, 0, system.MainInstance, nil);  if hWindow <> 0 then begin
        ShowWindow(hWindow, CmdShow);
        ShowWindow(hWindow, SW_SHOW);
        UpdateWindow(hWindow);
      end;
    end;procedure TMyWindow.WinCreate;
    begin
      if WinRegister then
      begin
        CreateMyWindow;
      end;
    end;function TMyWindow.WinRegister : Boolean;
    begin
      WindowClass.Style := cs_hRedraw or cs_vRedraw;
      WindowClass.lpfnWndProc := FWndProc;
      WindowClass.cbClsExtra := 0;
      WindowClass.cbWndExtra := 0;
      WindowClass.hInstance := system.MainInstance;
      WindowClass.hIcon := LoadIcon(0, idi_Application);
      WindowClass.hCursor := LoadCursor(0, idc_Arrow);
      WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
      WindowClass.lpszMenuName := nil;
      WindowClass.lpszClassName := PChar(FAppName);  Result := RegisterClass(WindowClass) <> 0;
    end;//
    //Window Message Handling Procedure
    //
    function WindowProc(Window: HWnd; AMessage: UINT; WParam : WPARAM;
                        LParam: LPARAM): LRESULT; stdcall; export;  var
         dc : hdc;
         ps : TPaintStruct;
         r : TRect;begin
      WindowProc := 0;  case AMessage of
        WM_CHAR:
          begin
             Text := Text + char(Byte(Wparam));
             dc := GetDC(Window);
             GetClientRect(Window,r);
             DrawText(dc,PChar(Text),-1,r, DT_SINGLELINE);
             ReleaseDC(Window, dc);
          end;
        WM_PAINT :
          begin
             dc := BeginPaint(Window,ps);
             GetClientRect(Window,r);
             DrawText(dc,PChar(Text),-1,r, DT_SINGLELINE);
             EndPaint(Window,ps);
             Exit;
          end;
        wm_Destroy:
          begin
             PostQuitMessage(0);
             Exit;
          end;
      end;  WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
    end;procedure TMyWindow.MyRun;
    begin
      while GetMessage(AMessage, 0, 0, 0) do begin
        TranslateMessage(AMessage);
        DispatchMessage(AMessage);
      end;
      Halt(AMessage.wParam);
    end;begin
      myWindow := TMyWindow.Create;
      myWindow.ApplicationName := AppName;
      myWindow.WindowProcedure := TFNWndProc(@WindowProc);
      myWindow.WinCreate;
      try
        myWindow.MyRun;
      finally
        FreeAndNil(myWindow);
      end;
    end.