473,789 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Forcing a dialog box on top when the current form does not have focus.

3 New Member
Here is my problem, I have a Windows form (which may in the future be switched to WPF form) that gets minimized and hidden to the tray. At a set time an event is fired in a new thread which shows a dialog box that needs to be displayed on top of any current application windows for the user to interact with.

I've spent several hours researching and playing with various methods trying to get this to work. I would prefer not to resort to direct win32 API calls, but if I need to, its a possibility I haven't ruled out. (I'm currently using C# on Windows Vista SP1)

Any ideas on how to do this?
Aug 6 '08 #1
6 2617
Curtis Rutland
3,256 Recognized Expert Specialist
Perhaps you can create your own dialog form that has it's TopMost property set to true. Then just launch that when you need to.
Aug 6 '08 #2
codedlogic
3 New Member
Nope... doesn't work. If the parent form does not have focus, the dialog (even with topmost set to true) doesn't automatically get focus over top of other windows (firefox for example).
Aug 7 '08 #3
Curtis Rutland
3,256 Recognized Expert Specialist
Hmm. Well, that's no good. I'd never tried it, it was just an idea I had.
Aug 7 '08 #4
codedlogic
3 New Member
Hmm. Well, that's no good. I'd never tried it, it was just an idea I had.
No problem,

I finally figured out a solution which involves hitting the unmanaged User32.DLL, not the prettiest solution when your writting in .NET, but it gets the job done.

C# functions to get and set the focus of the window on top of all the other windows:
Expand|Select|Wrap|Line Numbers
  1.         //     CLR   wrapping of unmanaged functions
  2.  
  3.         public static int GetWindowHandle(System.String WindowTitle)
  4.         {
  5.             //a return value of 0 indicates that the function did not find the window
  6.             return FindWindow(null, WindowTitle);
  7.         }
  8.  
  9.         public static void SetWindowFocus(int windowHandle)
  10.         {
  11.             SetForegroundWindow(windowHandle);
  12.         }
  13.  
  14.  
  15.         //DLL external functions hitting User32.dll
  16.  
  17.         [DllImport("User32.dll")]
  18.         private static extern Int32 FindWindow(String lpClassName, String lpWindowName);
  19.  
  20.  
  21.         [DllImport("User32.dll")]
  22.         private static extern Boolean SetForegroundWindow( Int32 hWnd );
  23.  
  24.  
  25.  
Aug 7 '08 #5
Curtis Rutland
3,256 Recognized Expert Specialist
Good to know. I'll probably use that solution myself.
Aug 7 '08 #6
Plater
7,872 Recognized Expert Expert
What happens if you toss a MessageBox In there? Those darn things love to popup over the top of everything else. And clicking the "ok" button them will force your application into focus.
Aug 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4751
by: Dalan | last post by:
I designed a dialog box with a combo to select individual vendors from a form and its related data for print ouput. Though the dialog box seems to work okay, I apparently do not have the filtering code behind the OnOpen Event Procedure of the report structured correctly. Anyone's assistance will be appreciated, although I would like to stay on the same track. Here is what I have done: 1. Created a new vendor query (qryVendorRpt) with...
2
12558
by: aaj | last post by:
Hi all I have a small but rather annoying problem with continuos forms, and am wondering if anyone can suggest a method of getting over it. The front end is Access 2002 with the BE being SQL Server 2000. I have a continuous bound form that is populated from a small recordset when the form opens. The form has lots of other bits, but my problem is with a single text box and an on-click event.
1
11588
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
3
2755
by: Gordan A Ziza | last post by:
Hello everyone, We are developing a MDI application and what we would require is the following: 1. To open a MDI child form as Form1 2. To open another MDI child form as Form2 that would act as a dialog form for the Form2 3. Form2 must not prevent any other MDI forms from opening or otherwise prevent application from working properly
1
1363
by: pw | last post by:
Hi, I have a form (with an ActiveX control on it - don't know if that is the problem) and I can not see the dialog/message boxes. There is an error with my form and I can not see what it is because it's behind the form. I can not move the form out of the way either. The form is not modal, it's not a pop-up, and it's not a dialog box either.
0
3893
by: Ralstoj | last post by:
Hi I am programing in Autocad with VB Autodesk have not given users access to new note function in Autocad CIVIL3d API. I am trying to work round this by creating notes using the sendkey command in Vb. I can get the add note dialog box to come up ok but it does not have focus as I believe it is a modeless dialog box as it gets focus when you move the mouse cursor over it. What I am after is a VB eample on how to send key strokes to the...
11
5297
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok / dangerous? How can I force shutdown code within the dialog's Form.FormClosed event run? Zytan
5
2944
by: GraffixNYC | last post by:
We have a model dialog box(well a bunch of them) and it seems that when you cancel one of the in our application it will activate and bring the focus to another open window (not in our application) anyone know why this is and how to correct it? it should set the focus to our application and not "activate" another window and make that window have the focus
11
2382
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have realized that despite suggestions to use DHTML-based modal dialogs are very common? there is not a single fully functional reliable copyright-free cross-browser alternative to say MsgBox (VBScript) or showModalDialog (IE). This way such suggestions up to...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.