Link to home
Start Free TrialLog in
Avatar of reddarin
reddarin

asked on

Main Form and New Form and Focus Problem

Hello everyone,

I created two programs and later decided to merge them into one program. That was no problem, I just included the second programs forms and files in the first programs project files through the IDE.

The problem is, when the second form is shown, it refuses to relinquish focus. That is, the second form is on top of the first form and if I click the first form's button in the task bar, it does not come to the front like it should.

Details:

I used setwindow to make the second form show in taskbar.
  SetWindowLong(self.Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
I've tried setting the parent to zero as well as not setting it at all (just going with default).
  //self.ParentWindow := 0;
Project Options correctly identifies the first form as the main form for the project.

reddarin
Avatar of PapaBeer72
PapaBeer72

Hi,

Try code like this for the second form. And don't use the ShowModal method but Show of the second form.


procedure TForm2.FormCreate(Sender: TObject);
var
  StyleEx: LongInt;
begin
  StyleEx := GetWindowLong(Handle, GWL_EXSTYLE);
  SetWindowLong(Handle, GWL_EXSTYLE, StyleEx or WS_EX_APPWINDOW);
end;


Good Coding,
PapaBeer72
Avatar of reddarin

ASKER

Thanks PapaBeer72 but that does not resolve the problem.

It should, because I've seen that in my search to resolve it and I've tried it so I'm glad to see it again as a solution.

Perhaps one of the files is corrupted that the compiler generates? I've tried rebuilding the probject (as opposed to just compiling it) and that doesn't change the problem either.

reddarin
Hi,

Perhaps is the FormStyle of the second form is set to fsStayOnTop or fsMDIChild. Set it to fsNormal if it isn't. Or maybe the first form FormStyle is fsMDIForm which much also be fsNormal.

Good Coding!
PapaBeer72
Hi,

Perhaps is the FormStyle of the second form is set to fsStayOnTop or fsMDIChild. Set it to fsNormal if it isn't. Or maybe the first form FormStyle is fsMDIForm which much also be fsNormal.

Good Coding!
PapaBeer72
Aha... if you navigate back there are two! LOL
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

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
PapaBeer72:

>Perhaps is the FormStyle of the second

Nope, I checked that and even toggled it just to make sure something wasn't screwy with the setting but that was a good suggestion.

geobul:

That did it, thanks!

reddarin
Ah, by the way, I just left the skeleton procedure as created by the IDE:

procedure TfrmMainWB.CreateParams(var Params: TCreateParams);
begin
  inherited;//<-- left off CreateParams(Params);

end;

...and added your two lines:

  Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
  Params.WndParent := GetDesktopWindow;

reddarin
You are welcome :-)

inherited; // is enough of course.

Regards, Geo