• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Moe

[.net] ShowDialog window hiding behind other windows...

10 posts in this topic

So we've stumbled across something strange at work. We've got a login screen to our application, which is displayed using a ShowDialog() call. For some odd reason, this window sometimes appears behind other windows, which occasionally confuses the users. We've tried using a combination of ShowDialog(), SendToBack(), BringToFront(), and Activate(), and messing with the properties to make it the topmost window, none of which have worked. Previous to the login dialog showing, we have a splash screen that spawns a separate thread and does some things in that thread. My co-worker thinks that the spawned thread is getting the focus, and in doing so our login dialog isn't popping to the front as it should. I have done a bit of googling on the subject, and the most common solution seems to be to call SendToBack() then BringToFront(). Unfortunately, this doesn't seem to work. It works fine when launching the app from the IDE, but not when running it from windows explorer. So, anyone have any thoughts?
0

Share this post


Link to post
Share on other sites
You're not using GetActiveWindow(), GetForegroundWindow() or any such function to get the parent window for the new dialog are you? (Or whatever the .NET equivalents are). That could certainly cause this.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
You're not using GetActiveWindow(), GetForegroundWindow() or any such function to get the parent window for the new dialog are you? (Or whatever the .NET equivalents are). That could certainly cause this.

I don't believe we are. I just did a quick search for both GetActiveWindow and GetForegroundWindow, and didn't find either being called anywhere in the app.
0

Share this post


Link to post
Share on other sites
The TopMost property set to true will work for you but only if you use .Show(), not .ShowDialog().

theTroll
0

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
The TopMost property set to true will work for you but only if you use .Show(), not .ShowDialog().

Apparently this does bring it to the front (as it should), but doesn't give it focus.

0

Share this post


Link to post
Share on other sites
Isn't ShowDialog() modal, so designed to display a form with a parent? Ie ShowDialog(this) would show the modal dialog with "this" as the parent. Perhaps you could get a handle to topmost window using GetForegroundWindow() then use that as the firt parameter to ShowDialog()? Never tried that myself though.

Or as TheTroll said use Show() (which is non-modal) instead with the TopMost property (you can actually set it to true then false just to bring it to top of z order).

To get focus use this.Focus() then this.Activate().

So in other words try
this.TopMost = true;
this.TopMost = false;
this.Focus();
this.Activate();
0

Share this post


Link to post
Share on other sites
I just chatted with my co-worker, and he said he had tried .Focus(), which didn't work. He was able to get it working by messing around with some of the threading stuff that we had in the startup portion of the program. Now, rather than the splash screen starting a thread that does stuff, it all just does it from the main thread.

Thanks for the help guys.
0

Share this post


Link to post
Share on other sites
Hi,

I have been struggling for some time with the same problem as described above, and finally found a solution for this.

When testing my app, I saw that if I gave a mouse click on the splash screen, the Login form would afterwards have the correct focus. The solution is simply to make a codewise mouseclick on the splash (NOT the Login). Put the following in the splash (I also have the Me.Active in the Login Load, but I have not tested if it is necessary):

Declare Function mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) As Long

Const MOUSEEVENT_LeftDown As UInt32 = &H2
Const MOUSEEVENT_LeftUp As UInt32 = &H4


Private Sub Splash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

....
....
....

Me.Activate()
BringFocusByMouseClickHack()

End Sub

Private Sub BringFocusByMouseClickHack()
Try
mouse_event(MOUSEEVENT_LeftDown, 0, 0, 0, 0)
mouse_event(MOUSEEVENT_LeftUp, 0, 0, 0, 0)

Catch
End Try
End Sub

0

Share this post


Link to post
Share on other sites
use SetForegroundWindow http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx inside the form you want to receive focus

[DllImport("user32")]
public static extern int SetForegroundWindow(IntPtr hwnd);

and when the dialog form is shown call the function with the form handle;

void OnShown(object sender, EventArgs e) {
SetForegroundWindow(this.Handle);
}
0

Share this post


Link to post
Share on other sites
Thanks a lot Cryogenic for this response !! It help me a lot !

For those who search the equivalent in VB.NET here it is :

Declare Auto Function SetForegroundWindow Lib "user32" (ByVal hwnd As IntPtr) As Integer

Private Sub OnShown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
SetForegroundWindow(Me.Handle)
End Sub
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0