views:

431

answers:

7

Hi,

When window A is show, I want to show another none-modal popup window B, but:

  1. I don't want window A to become inactive due to window B becomes the front window;
  2. I want that when window B is focused, I pull down a combo box control on window A with one click (generally you have to click twice, one for moving the focus to window A and the second for pulling down the combo box);

As you can see, the window B that I want is something like a more usable popup window like a popup menu (which is less a obstacle than a general none-modal window when you want it to get away by clicking on any other part of the parent window).

Am I clear on my question? Thank you.

+3  A: 

I'm not sure if I understood you correctly, but "form behaving like popup menu" sounds as if you could use Mustangpeak's DropDownForm.

Ulrich Gerhardt
Thank you Ulrich, Mustangpeak's DropDownForm is good, it implements the popup window, however, you'll find that the caller form's title bar become inactive when I click on a control inside the DropDownForm. Moreover, if you have a combo box on the caller form, when the input focus is in a control in the drop down form, your first click on the combox does not pull download it.Anyway, I can take use of Mustangpeak's DropDownForm, although it's not as usable as I expected.
Edwin
A: 

I can use this to not lose focus:

SetWindowPos(Form2.Handle, HWND_TOP, 0, 0, 0, 0,
  SWP_SHOWWINDOW or SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOMOVE);

The second part I didn't understand very well.

SaCi
+1  A: 

In order to prevent a window from getting focus, you must either specify the WS_EX_NOACTIVATE extended window style (Windows 2000 and up) or handle WM_MOUSEACTIVATE and return MA_NOACTIVATE.

Koro
Thanks Koro, I want the second to get focus but does not make the caller form's title bar become inactive.
Edwin
A: 

SpTBXFormPopupMenu from the spTBXLib does the job.

Go to http://www.silverpointdevelopment.com/sptbxlib/index.htm and look for "Form Popup"

The key seems to be that the container 'popuped' must inherit TPopupMenu. But the handling is very complex, you can see it by yourself in the code. My recommendation is to use it as is from the package because Robert Lee has done a wonderful job.

loursonwinny
I know this already, that's similar to what I want but it does not meet the two requirements I described in my question.
Edwin
A: 

The easiest solution I had found for "1" is to send a WM_NCACTIVATE to the calling form as soon as the popup-form gets activated (in a WM_ACTIVATE handler), so that the calling form would draw its caption with the active colors. You'll have to have a reference for the calling form in the popup-form to achieve this.

For "2", you can release the popup form in the same WM_ACTIVATE handler, this won't eat the clicks that goes to the calling form.

So sth. like this should go to the popup-form;

type
  TForm2 = class(TForm)
    [..]
  private
    FOwner: TForm;
    procedure WmActivate(var Msg: TWMActivate); message WM_ACTIVATE;
  public
    constructor Create(AOwner: TComponent); override;

[...]
constructor TForm2.Create(AOwner: TComponent);
begin
  if not (AOwner is TForm) then
    raise Exception.Create('Owner should be TForm');
  FOwner := TForm(AOwner);
  inherited;
end;

procedure TForm2.WmActivate(var Msg: TWMActivate);
begin
  SendMessage(FOwner.Handle, WM_NCACTIVATE, Ord(Msg.Active <> WA_INACTIVE), 0);
  inherited;
  if Msg.Active = WA_INACTIVE then
    Release;
end;

and supply the calling form as the owner of the popup-form;

procedure TForm1.Button1Click(Sender: TObject);
var
  PopForm: TForm2;
begin
  PopForm := TForm2.Create(Self);
  [..]


FWIW, I agree with both loursonwinny and Ulrich. IMO a popup-form is more complicated then it seems. Though in the case of SpTBXFormPopupMenu you'd have to install two libraries, TB2K and SpTBXLib. At least browsing the sources could hint on what could get involved.

Sertac Akyuz
A: 

I found one that does almost exactly what I want: TAdvStickyPopupMenu

Edwin
I think that does not quite answer the question. Would you elaborate a bit how does it achieve the "1" and "2" in the question.
Sertac Akyuz
@Sertac, maybe it's hard for me to explain, but I'll try ;)first I can use any control including a tpanel or a tframe into the TAdvStickyPopupMenu, so I can use it as the popup container for my tpanel (simulate a form), and clicking on the tpanel does not hide the menu, so I can simulate a popup form.How this approach achieves the "1" and "2" in the question?
Edwin
When you popup the menu (with a simulated form on it), you'll *feel like you are still working on the parent form*, that means there is *no switching needed* between the popup form and the parent form. by switching I mean the extra mouse click need to focus the form before you can operate on the controls on the form.if you compare it with the dropdownform and the SpTbx dropdown mentioned above, you'll find the difference.And if you use Gmail, try the labels pull down popup form, you will understand what I mean.
Edwin
Thank you for the explanations. With a quick look at TAdvStickyPopupMenu I thought you've changed your requirements on the way and went for a different route, while my answer (http://stackoverflow.com/questions/2178494/2192590#2192590) did in fact fulfilled the requirement with the question. Well, maybe I somehow misunderstood the question in the first place, so if you're able to *edit* your answer in anyway SO will allow me to undo my down-vote. Thanks again.
Sertac Akyuz
HI Sertac, I think in the first place I didn't describe my question well, I thought to fulfill my requirement I need to use the popup forms, so I directly asked the initial question but the actually my explanations here are the ultimate requirements... I can select your reply as the answer, but will your approach prevent the popup form from being getting user input? you know I need to use a TList control on the popup form to allow users to choose one value.
Edwin
Either it works as the way you wanted or not is for you to test and decide. <g> Then you can --edit your answer so that I can undo my down-vote (f.i. add "more details in the comments"), --if the mentioned answer satisfies your needs accept it, or --leave this as it is. :-)
Sertac Akyuz
A: 

Hi folks,

I found the solution myself here. Thank you all!:

Keep Window Inactive In Appearance Even When Activated

Edwin