Link to home
Start Free TrialLog in
Avatar of eYes
eYes

asked on

how to let it get focus?

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TMyEdit = class(TEdit)
  protected
    procedure createparams(var params: Tcreateparams); override;
  end;

var
  Form1: TForm1;
  tmp: TMyEdit;

implementation

{$R *.DFM}
procedure TMyEdit.createparams(var params: Tcreateparams);
begin
  inherited createparams(params);
  params.exstyle := params.exstyle or WS_EX_TOOLWINDOW;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not assigned(lst) then
  begin
    tmp := tmylist.Create(application);
    tmp.ParentWindow := getdesktopwindow;
    tmp.Text := 'Test';
    setwindowpos(tmp.handle, HWND_TOP, 50, 50, tmp.width, tmp.height,
                             SWP_SHOWWINDOW or SWP_NOCOPYBITS);
  end;
end;

end.

while i run this, it can show the edit on the desktop, but the edit can't get focus.
how can i let it get focus?
Avatar of Epsylon
Epsylon

Just use:

tmp := TMyEdit.Create(Self);
InsertControl(tmp);
And use

tmp.Left := 50;
tmp.Top := 50;

to position it.
Avatar of eYes

ASKER

i want it show on desktop not in form.
I don't think you can, unfortunately.  Create a transparent form and set that as the parent of the TEdit.  That'll get round the problem.

Apart from that, I'm afraid I can't help!

John.
You can only do this by using a form so why not size the form to the size of your editbox.
Avatar of RBertora
Following..
Or, to suggest a completly different alernative:  Use the active desktop to put a <textArea> on the wallpaper.

GL
Mike
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This looks exactly the same, but works.  (Make a Form1 with a Button1 on it and use this code.)

/////////////////////////////

procedure TForm1.Button1Click(Sender: TObject);
var
      frmNew      :      TForm;
  txtNew      :      TEdit;
begin
      frmNew:=TForm.Create(Application);
  With frmNew do begin
        BorderStyle:=bsNone;
    Width:=200;
    Height:=30;
    Top:=50;
    Left:=50;
      End;
  txtNew:=TEdit.Create(Application);
  With txtNew do begin
        ParentWindow:=frmNew.Handle;
    Width:=200;
    Height:=30;
            Left:=0;
    Top:=0;
  End;
  frmNew.Show;
end;

/////////////////////////////

This is the best I can think of...

John. :-)
Avatar of eYes

ASKER

i want to write a combobox like component. add my own control (such as stringgrid, listview, treeview...etc) as combo list box. if i put that in a form, while user select in the combo list box and his form lost focus(the title bar become gray), what a strange combobox!
also i cant set it's parent to form, because form maybe clip the list box.

any idea?
So you don't want what you originally asked for, yeah?
Try this then.  (ComboBoxes don't clip to forms!)

procedure TForm1.Button1Click(Sender: TObject);
var
      frmNew : TForm;
  cboNew : TComboBox;
begin
      frmNew:=TForm.Create(Application);
  With frmNew do begin
        BorderStyle:=bsNone;
    Width:=200;
    Height:=30;
    Top:=50;
    Left:=50;
      End;
  cboNew:=TComboBox.Create(Application);
  With cboNew do begin
        ParentWindow:=frmNew.Handle;
    Width:=200;
    Height:=30;
            Left:=0;
    Top:=0;
  End;
  frmNew.Height:=cboNew.Height;
  cboNew.Items.Add('Item 1');
  cboNew.Items.Add('Item 2');
  cboNew.Items.Add('Item 3');
  cboNew.Items.Add('Item 4');
  cboNew.Items.Add('Item 5');
  frmNew.Show;
end;
huh huh, anybody realized that I already gave the solution?
Avatar of eYes

ASKER

thanks a lot
Mike : Yours was different.  Did you look at his code running and then compare it to yours?  Besides, he keeps asking for other stuff!
Jaymol, of course did I look at it. I copied it to my current project and tried out what I thought what could be the solution and it was...

The question for the other stuff raised only because of the suggested solution to use a form.

eYes, I have already written an own combo box. If you need further help on this then ask another question and I'll be there. You can also download a component called TColorPickerButton from www.lischke-online.de where I also use a standalone popup window very similar to the popup of a combobox. Look through the code to get important ideas (mouse capture, message handling etc.).

Ciao, Mike
Okay, okay...just a question.  Don't get arsey!!