How to make non-modal MessageBox pop-ups for Unity project - c#

Gday,
I am currently doing a small Unity project where the game takes place on the desktop, we have a creature that communicates with the player. It is currently severely limited with how it acts/reacts due to the only way that I can figure out how to make popups in the windows system style is through the use of the MessageBox function which is Modal (it suspends the application from running until the MessageBox has been answered or closed).
So I was wondering if there was any way to get the same effect without it suspending the entire application, I've tried looking into Forms however I can't get it to recognise it as a thing in VisualStudios. I have also looked at GUI.Window however doesn't create a window that looks like a Windows style popup.
What do yall reckon?
(Thankyou in advance)

In general, trying to mix Unity and WinForms is a really bad idea. They were built around completely different design philosophies and if you keep going down this path, they're going to keep fighting each other.
The best option here would be to create your own lookalike windows in-game. That would require quite a bit of work and infrastructure to set up at the beginning, but it would also give you full control over the style and behaviour of the dialogs.

Browse the asset store for assets that solve the problem for you. There are a number of dialog type assets you can grab and plug into your unity project to get you running quickly. A lot of them mimic windows features like moving around, scrolling or X to close.

Related

CefSharp WinForms browser hosted within WPF WinFormsHost

I'm currently working on moving out kiosk software that runs Awesomium away and instead onto CefSharp.
Our main application is written in WPF and this work is using v45 of CefSharp
I'm aware that the WPF control has some serious performance issues, when compared side-by-side with the WinForms version hosted in a WindowsFormsHost, the smoothness of transitions etc is MUCH better.
To that end I'm looking to stick with this approach of embedding the WinForms ChromiumWebBrowser inside a WindowsFormsHost on the WPF window. This all works and however I'm having issues with getting touch support to work.
Our kiosks have touch screens and run Windows 7 / 8.1, the touch works flawlessly with the WPF control, however when using the WinForms embedded one touch doesn't work at-all.
As well as touch not working it also steals all Keyboard events and consumes them internally it seems, as none of my event handlers ever fire on the main WPF window.
If anyone has any ideas or can point me in the correct direction to try and solve this it would be hugely appreciated!
Thanks
The scenario your talking about is not well supported and as such there is not a lot of information. A lot of the problem your are seeing are likely because CEF is running it's message loop in a separate thread. If you turn MultiThreadedMessageLoop off, then you become responsible for calling Cef.DoMessageLoopWork(). I recently added a rough demo the WinForms Example. You can likely port this to WPF, though I've never tried.
https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.Example/CefExample.cs#L76
https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.WinForms.Example/Program.cs#L37
You are in somewhat uncharted territory there, so you'll have to do most of the leg work yourself.
For reference there are some ways to improve the WPF performance. They come with their own set of drawbacks though. See https://github.com/cefsharp/CefSharp/blob/cefsharp/45/CefSharp.Example/CefExample.cs#L58

Best way to pass metadata between XNA & WPF for a level editor

I have a pre-existing game in XNA that I've unfortunately lost the level editor code for. Before it used to run as a separate .exe, but I've done the work to modify the game so that it can be paused to run a level editor in the game itself. I'd like to use WPF to actually do the level editing as it seems well-suited to the task, but I don't know the best way to pass information between the two systems.
My XNA game spawns a WPF Window and I've registered events with the XNA game such that when I click a Button on the WPF Window, the XNA game receives the ClickEvent and responds appropriately. This worked wonderfully for placing objects that require no initialization data other than position (things like statues), which I simply interpret in XNA directly. However, now I have objects that have more information that the user defines in the WPF editor (e.g. starting enemy health) and I'm not sure of the best way to route the information across to XNA. I'm especially trying to keep in mind that eventually, I'll want to make it so that I can click an object in the game to edit it "in-line" (or at least make it appear that way to the person using the level editor). So essentially, I'll need to be able to set the WPF control values based on information stored in XNA when the user clicks on an object in XNA.
Here's what I've thought of so far, but none of these were as straight forward as I'd like them to be and so I'm not sure that I'm going down the right path.
Override RoutedEventArgs to include the extra metadata that I need such that when the event is raised from WPF and picked up by XNA, all of the extra information is there already.
This seems to be an ok approach, but doesn't really help me at all when I want to go the other way around.
Also, I could be misunderstanding how this works, but it seems like I needed to add a bunch of generic EventHandler code to my XNA game that was not required for the "statue" case.
Override the Button class to attach the extra metadata I need and then access it via sender or RoutedEventArgs.OriginalSender
This seems like one of the easier approaches, but feels a bit forced. The information doesn't really belong as part of the Button.
I'm not sure how this will work for passing the information back from XNA to WPF.
Get the information via sender.Parent or RoutedEventArgs.OriginalSender.Parent, which will require casting it to the appropriate WPF UI element.
This seems relatively easy, but is kind of ugly. It basically means putting a bunch of regular C# style properties that get their value set when things like ComboBoxes have a change/selection event.
This seems easier to go the other way with than making a custom Button, but I haven't spend serious time looking at it yet.
Any help / direction would be appreciated. I'm also happy to post any relevant code snippets, but the game is quite large and the WPF implementation so far is extremely basic, so I'm not sure what would be helpful.

Disable other software besides Chrome

I need to write a program that forces Google Chrome to be in the front and disable all other actions like opening another program etc... I just need to have Google Chrome in front of the screen and that's all. I can't allow other programs to pop up.
Any ideas how it can be done?
Thank you!
Im pretty sure as far as you can get is a popup window that has no scrollbar or top bar, and can't be resized, but JS wont let you manipulate stuff outside the current window, just like you cant auto-click links inside an iframe
I highly doubt this is possible in Windows, and if it is it won't be ethical if used on home PCs. Will this be a kiosk style app?
You can control what appears in the browser to some extent, such as scrollbar-less windows but much more than that is impossible.
Definitely not ethical at all but applications such as Fortress 101 can do this. I have done similar things in the past using C and the Win32 API. I won't write the code for you but I basically did the following:
Find the desktop and hide it
Find and hide the taskbar
Find and destroy the start button
Capture special keypresses and prevent them from working as expected
You would also need to poll a process list because even doing all of that doesn't prevent the user from downloading a file and executing it. Thus if you found a new application in the process list, you could destroy it.
You could do this using user32.dll with C# but such an application would better be left to commercial software packages.

Setting focus on control causes windows tool bar to appear

When I set focus on a text box, on a forms load event in Windows Mobile 5.0, the Windows tool bar appears even though my form is maximized.
When I do not set the focus on the text box the form opens maximized. I do not want the windows tool bar appearing.
How do I prevent this from happening?
TThe start bar in WinMo is actually not part of your app - it is a separate process managed by the Shell and it really wants to always be on top. Trying to get your app above it goes against the design goals of WinMo (though it's a common thing to want to do).
I'd recommend doing some searching and reading on "kiosk mode" to garner what knowledge you can from others who have been down this road, but what you're seeing is that the StartBar is getting set topmost.
Raffaelle Limosani has a pretty decent blog entry that covers kiosk mode, so it's a good place to start (take a look at the other blogs he links to as well).
The toolbar at the top is actually a separate window, and it has a habit of appearing when not wanted over top of a full-screen ("kiosk" mode) app. For example, if you ShowDialog a second full-screen window from the first, the Start window flickers up for a split second before going away.
The only way I ever found of dealing with it was to hack into the API and actually make the Start window hidden while my application was open. This is a big potential problem, because if your app crashes without making the Start window visible again, it will stay invisible until you reset the device (or run you app again successfully).
I'd advice against doing this unless you absolutely have to. As ctacke points out, this would be an example of an app not playing nicely with Windows Mobile.

Is WPF still relevant and can I use it in my C# windows application?

I have a process which I break into multiple processes and even when using threading it takes a very long time to complete.
I'd like to give the user an indication of the status of the execution in a cute way (for each process % complete). Maybe betting on the right horse will ease the pain :)
I found this project long ago: A Guided Tour of WPF (XAML)
I have two questions:
This article was written in 2007. Is there better way to achieve this graphic effect?
I have not understood yet, how the application is started, so I'd like to know if I can integrate such "window" in my window application?
Adam Robinson pointed out that the second question is not clear:
The application generates a window as in the picture below - I like to know if it possible to insert it in my "normal" windows application.
This article was written in 2007, is there better way to achieve this graphic effect?
WPF is the current "best" (or at least most feature-rich) way to develop a Windows Application for the desktop.
I have not understood yet, how the application is started, so I'd like to know if I can
integrate such "window" in my window application?
Make your application a WPF Application. This will automatically give you an application, Window class, and everything else you need to get started. Making a WPF application is just like any other application, except that you need to start the message pump, create the application, setup your startup window, etc. The "WPF Application" template in Visual Studio does all of that for you...
Until you understand what all is happening, I'd recommend starting with that, and customizing from there.
If you choose to stick with a win form for the main app, you can still host the desired window/control via an ElementHostControl. (hosts wpf inside winform).
Blessings,
Jeff

Categories

Resources