tags:

views:

507

answers:

4

I have done a global mouse event in my windows application. When i click the center button of my mouse, i want to make a particular form topmost...

There are some applications which runs in the full screen mode, so i need to do this, in order to make my form visible to the users, because this is the only way to view it. Since Alt + Tab is disabled. This is a Kiosk application.

I tried using Topmost = true for that particular form and I tried using below code...But no use. I am not getting my form in front.

  [DllImport("User32.dll")]
  public static extern Int32 SetForegroundWindow(int hWnd);  

  [DllImport("user32.dll")]
  public static extern int FindWindow(string lpClassName, string  lpWindowName);         

     private void BringToFront(string className,string CaptionName)
    {
        SetForegroundWindow(FindWindow(className,CaptionName));
    }

The global hotkey which has to trigger this form to bring front is working perfectly.

How to make my form come front ??? Thanks.

+1  A: 

Not my thing but have you tried messing with:

this.BringToFront();

this.Activate();
A: 

You need set the fullscreen form's topmost to false, then continue on.

choudeshell
A: 

You may not be calling your BringToFront method correctly. For the FindWindow API function, lpClassName would be your application's name (e.g. "MyApplication.exe"), while lpWindowName refers to the caption in the particular form's title bar (e.g. "Form1"). Usually with FindWindow you pass in one or the other, eg:

FindWindow("MyApplication.exe", null);
// or
FindWindow(null, "Form1");

I'm not sure what happens when you pass both.

You may also just need to do something simple to achieve this, like calling the particular form's Activate() method.

MusiGenesis
I tried the above, but not working...
Anuya
I think you should post some additional code. I'm not sure what you're doing exactly to be in kiosk mode. Showing forms and changing their position in the z-stack is pretty easy and basic in Windows, but you may be doing something weird.
MusiGenesis
@MusiGenesis, i cannot post my whole code here, since there are lot.Yes it is weird for me too... There will be another application running on my system in full screen mode. I need a way to show my form to the user when user clicks the mouse center button. I tested my mouse center button as global event, by adding a "HI" message box. and it is working perfectly.The only thing is, i need to show my form now.Note :: My code to show the form is not in the same form, it is in different place. Does that make any problem ??
Anuya
@karthik: no, I think your problem is with the *other* application running in full screen mode. It's probably somehow preventing any of your forms from showing up. The message box is a different matter - that's sort of a global Windows function, and message boxes often show up on top of kiosk apps. How does this other application do kiosk mode?
MusiGenesis
@MusiGenesis, my doubt is if the application running in full screen mode prevents my form to appear on top... how can i do alt + tab to bring my forms on top of that ?? Is there a way to show my form using global windows function as you said like message box ?
Anuya
@karthik: that's almost impossible for me to say without knowing what this application is and how it achieves the kiosk effect (and what version of Windows this is). Windows is really fundamentally *not* built to work in kiosk mode, so there are different ways of doing it, most (if not all) of which are weird hacks.
MusiGenesis
Message boxes show up on top of a kiosk app because they're created and shown by the OS itself, and can't be "prevented" in any way by the kiosk app.
MusiGenesis
+2  A: 

get the handle of the window and do this

SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE| SWP_SHOWWINDOW);

Andrew Keith
@Andrew Keith, i tried that, but still no fruits.
Anuya