Windows GUI in Directx/OGL

Started by
13 comments, last by TheQuestion 16 years, 4 months ago
Hello Guys, I have a very simple question but possibly with a very complex answer. In a full screen directx/ogl application (possibly a game), how can I show regular windows GUI components? For example how can I show just a blank windows form? Would it be possible to transfer the control to the new form (including with the mouse) so that user can interact, click buttons, write on a textbox while the game is still being shown in the background? I may come off as a bit clueless, but I have spent the past 3 months on this topic. I know it involves DLL injection/API hooking and I DO have a working program (hook in any dx8/dx9 game - dx10/ogl not yet implemented, draw on the screen such as fps, handle all the lost devices, so on so on). I can hook into all important methods such as createdevice, createadditionalswapchain, present, clear, so on. I have spent a long time for this and I finally got it to work a few days ago for all dx8/dx9. My initial purpose was to of course draw a winform on the screen (it'd also be amazing if I could do it in C#, maybe transfer the control over to C# from unmanaged dll file, pass the device pointer, draw, and pass it back as C++ is very hard). A good example to this is xfire. But of course once that's done I have to do a lot more complicated stuff, stuff that's never been done before, such as reflecting your entire desktop over the game and give user control to take actions such as go to start then firefox and check your e-mail, it'd be as if you are in windows without alt+tab. But for that to work, my plan was as follows: 1. Hook into game interface. DONE. 2. Draw on the game. DONE. 3. Handle exceptions/device losing/focus change/game issues. DONE. 4. Draw a simple winform. 5. Get the handle to the desktop, capture its view, reflect it on the screen, and do this in every Present() call. 6. Get the mouse actions, reflect it on the desktop. 7. Repeat step 5. I'd really appreciate any help. At this point, I am trying to find a source a document or something that can get me started. There is nothing in google about this and i am pulling my hair out. Thanks. PS If you are interested in this project, please PM me. At this point it became a huge project extending to unmanaged C++, kernel level device drivers (for CPU instructions), C#, server logic, benchmarking, hardware monitor, and a billion other things. Codebase is over 50k lines now and I am desparately looking for someone who'd like to join and help me out. [Edited by - TheQuestion on December 5, 2007 6:45:44 PM]
Advertisement
I forgot to mention one thing. The way I want to do this is via win32 controls. I do NOT want to re-invent my own controls (I know there are dozens of articles on that), I don't want to write something from scratch. That's unacceptable. Look at xfire, if anyone used it, you'd know it uses straight win32 forms (set the skin to default and see in game it's a regular win32 form width default controls) and I highly doubt they sat down and spent months designing listboxes or checkboxes.

Another reason why I want win32 so bad is because it can be used in all dx8/dx9/ogl/dx10, windows xp/vista, 32bit/64bit. If I were to make my own or use another library, i'd increase the chances of having problems with all these different variations of systems.
Its done already, see

This way you can later add in an OpenGL renderer, support Linux, MacOS, etc. The UI should not be OS dependent at all. Nor should your engine if its designed decently.

Edit: There are a ton of other UI libraries out there too, that was just the first one to come to mind.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Quote:Original post by Mike2343
Its done already, see

This way you can later add in an OpenGL renderer, support Linux, MacOS, etc. The UI should not be OS dependent at all. Nor should your engine if its designed decently.

Edit: There are a ton of other UI libraries out there too, that was just the first one to come to mind.


I think you misunderstood me. I am not looking for a UI library. What win32 has is enough for me. What I am looking for is a way to draw those UI components within the game. Please read my first post carefully.

I have pretty much control over the game, I can get the device, the main HWND (from CreateDevice() method argument), or any other major variables the game uses. I just need to figure out a way to draw my own screen on top of it without remaking what's already out there.

Thank you.
Take a look at the DXUT GUI framework from the DirectX SDK. It uses standard windows controls and draws them through Direct3D by hooking the OwnerDraw message. You can use the same approach for OpenGL or rewire the DXUT GUI to work on your abstracted renderer interface.

Anyway, you would lose all portability, and that's something I wouldn't accept (I'm not even one of those everything-must-run-on-linux guys, it's just that the console market is very attractive lately ;)).

I don't see what's wrong with using CeGui or something similar. All common controls already written for me, works on both OpenGL and DirectX and if I need to, I can make it usable by gamepad.

-Markus-




Professional C++ and .NET developer trying to break into indie game development.
Follow my progress: http://blog.nuclex-games.com/ or Twitter - Topics: Ogre3D, Blender, game architecture tips & code snippets.
Quote:Original post by Cygon
Take a look at the DXUT GUI framework from the DirectX SDK. It uses standard windows controls and draws them through Direct3D by hooking the OwnerDraw message. You can use the same approach for OpenGL or rewire the DXUT GUI to work on your abstracted renderer interface.

Anyway, you would lose all portability, and that's something I wouldn't accept (I'm not even one of those everything-must-run-on-linux guys, it's just that the console market is very attractive lately ;)).

I don't see what's wrong with using CeGui or something similar. All common controls already written for me, works on both OpenGL and DirectX and if I need to, I can make it usable by gamepad.

-Markus-


Oh, I should have said, this is for Windows O/S only. I am not writing this to be compatible with any other O/S.

I'll check out the DXUT GUI, thanks a lot :)
I forgot to ask, would it be possible to do this with DDRAW overlays? I know it's old, but I kind a remember seeing an example that overlays a winform on top of a game and periodically checks whats typed in on the original textbox and updates the overlay.

So I could make my form in normal winform (like C#), hide it, overlay it in a game, track the mouse coordinates, and reflect it on the form.

The question is, is this method efficient? Is it widely used? and more importantly is it a good way to go? I also remember NVIDIA cards having some sort of hardware problem with alpha channels, and overlays not working.

So this should be something similar to the way xfire overlays work. With a mouse with a form, complete user interaction.

I just wanted to re-write what I wrote in the first post, because we kind of went off topic, I am not designing a game, I am trying to overlay a form on top of all existing games.
I read and understood what you wrote, I was just trying to give you an easier idea. Getting Win32 to work on top of D3D/OpenGL window (which existing games use) will be difficult to do nicely in most cases. You'll spend time customizing the look of it too when you could just grab an existing UI and just go to it (unless you want default look). You will also have to tap into the game or driver somehow to stay on top of the game window.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Quote:Original post by Mike2343
I read and understood what you wrote, I was just trying to give you an easier idea. Getting Win32 to work on top of D3D/OpenGL window (which existing games use) will be difficult to do nicely in most cases. You'll spend time customizing the look of it too when you could just grab an existing UI and just go to it (unless you want default look). You will also have to tap into the game or driver somehow to stay on top of the game window.


The problem with that approach is as follows here:

1. My application will be using a skin which is defined by an xml file. Every single corner of it, every button color, the background image, on mouse hover colors, will be specified in an xml, parsed, and drawn. So there is no point of doing all those super complicated and advanced GUI libraries. a. I have no idea how to use them, b. I don't really care if they look good, after all my skin will cover it all:)

2. I need to do most of this stuff in .NET. My main hook library and everything is in C++. My question is, is it possible to do this by using both of them? I guess the point I am trying understand is "HOW" to do it, rather than "WHAT" to use. Because trust me, before I posted here, I already tried making a simple window, register it, and show it, but in game, it does not work. It either minimizes the game, or crashes the game. I need one simple example showing how I can overlay a simple form during game execution. From there, I can take over, but I need a sample or a source that shows you how to do it. I don't know whether to use ddraw or just pure win32 or directx. I don't know HOW to use them in this case.

I have access to device, present/clear/swapchainpresent/createdevice/createadditionalswapchain/reset methods, main HWND of the application. I can hook into more methods if I have to.

Once you create the window, how do you show it every time say Present() is called? Is that the right way to do? Is there anyway to a) Make a form (during game is running) in windows in the background, b) hide it, c) show it when a key is pressed?

I already have my nice fps counter like graphics working with this principle.

Edit: I also want to ask that why out of 173 views in this topic only 1 person responded? Should I have posted this in DirectX forums or gaming forums? Thanks.
Is The Question going where no man has been before?

To me it seems so.

but I don't know, it just seems really difficult (working inside out... from graphics API to [hooking to] windows forms API etc).

(1)I would have started this as/with a windows form application.
Did you? Can you? It seems as if that was your original aim, what happened?
(2)Then custom skinned it(how do you do that? : research)
(3)Then Applied the graphics API (directx/opengl) to a Control ( e.g. Forms::Panel is a good one).
(4) Find out if 2 and 3 above compatible?

Bit like a sandbox or game/model/terrain editing tool?

Do you see that as possible?
Would you consider:
Can you/have you modularized you existing code enough to be able to create your app as a windows form application? Its just that I think if you could, then you would have a well known/used/understood base on which to continue to build your app with tons of typical ref material.

I don't think I have really answered your question but...its just that if you are not beyond the point of no return you could do (1) to (4) above and perhaps avoid what seems to be a difficult path.
Maybe you have already looked at (1) to (4) already deemed it not viable?

or maybe I do not quite understand your aim:
Is it to make you own version of an xfire type application?

This topic is closed to new replies.

Advertisement