Link to home
Start Free TrialLog in
Avatar of vladh
vladhFlag for Canada

asked on

Force input and focus to daughter form

Hi Everyone,

My app creates a secondary form for input. I need to make sure that while this secondary form is active, the user couldn't click on the primary form (displayed right behind the daughter form). Setting the secondary form to AlwaysOnTop alone doesn't help - the form remains on top but I can still go back and click things/change settings on the main form behind it.

Any tips/ideas are appreciated.

Thanks
Vladimir
Avatar of inthe
inthe

hi,
show the form modal

ie:

my_second_form.showmodal;

this stops the user form getting to the form below.
Avatar of vladh

ASKER

inthe,

My app has 3 daughter forms. Your suggestion worked great for 2 of them, but the third one consistently blows up when I click a button to close it. All three forms are almost identical. When I click OK button on the bad one, it generates access violation on the ShowModal in the FormCreate method; not on the OKBtnClick!
Any suggestions?
Thanks
Vlad
To keep on top and allways focusable... I found in past next trick on net :

8<--------

Handling WM_ENABLE and WM_WINDOWPOSCHANGING messages as follow will keep the window always on top.

procedure TAlwaysOnTopForm.WMEnable(var Message: TWMEnable);
begin
 inherited;
 if Visible and not Message.Enabled then
 begin
   SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0,
     SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE);
   EnableWindow(Handle, True);
   Application.NormalizeAllTopMosts;
   SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0,
     SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE);
 end;
end;

procedure TAlwaysOnTopForm.WMWindowPosChanging(var Message: TWMWindowPosMsg);
begin
 inherited;
 if Visible then
   with Message.WindowPos^ do
   begin
     if (flags and SWP_NOZORDER) = 0 then
       hwndInsertAfter := HWND_TOP;
   end;
end;
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
Avatar of vladh

ASKER

inthe,

Your solution almost worked - for 2 forms out of three. The third one totally refused to work this way and I can find no explanation for its misterious behaviour - all three forms are very similar.

Looks like ShowModal is a cool idea but I'll have to put it on the backburner until I figure out what went wrong with it.

Thanks anyway
Vlad
Avatar of vladh

ASKER

Geo,

Simple, cheap and a VERY effective trick! Thanks :)
Vlad
My pleasure.
Geo