Link to home
Start Free TrialLog in
Avatar of FlyveHest
FlyveHest

asked on

Display form / text / anything on top of a DirectX application

I am looking to make a program which can display the current time, on top of all windows, but primaryli games, which use DirectX.  (Most games haven't got an ingame clock, and its not possible to check the clock in the systray when playing)

I have a program working, using SetWindowPos, and its working fine when in Windows .. but when running games, i've only yet found one where it works, the rest the display just shows for a splitsecond (i guess a single frame), and then disappears.

Is it at all possible to do this from Visual Basic?

I've seen some other apps that can do this, so I know its possible.
Avatar of gimmeadrink
gimmeadrink

Have you tried using BringWindowToTop api instead?

' in declarations:
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long

' in form_load or simular

BringWindowToTop Form1.hwnd

Im not 100% sure if this will work with DirectX apps.... also, what is the resolution of the games you want the form to be on top of?


'In a module or declared private in a forms declarations
Public Const HWND_TOPMOST = -1
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE

'In a form_activate/load routing
Call SetWindowPos(FormName.hWnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, FLAGS)

Replace FormName with the name of the form.

This will set that form ontop of any other window and keep it there.  The only way anything will cover it up is if another form calls the same type of code to set its position on top which might be your case so you might want a timer or routine to track what form is currently the highest in z-order then set it back to your app.
Avatar of FlyveHest

ASKER

NBrownoh:

This is exactly what I already do, and it doesn't work (as I started in the question).  The form only displays for what I guess is a single frame, and then disappears.

It doesn't do this in all games, but out of the four i've tested so far, I can only get it to work in one.  I read that you can open a DirectX applicaion in shared and exclusive mode, and its probably this that causes the program not to work like it was intended.

BUT, a program like PowerStrip can display text on top of a DirectX application, and it stays there no matter what, and its this function that I would like to replicate (I dont know if it hooks into the drivers, uses some special DirectX screen, or something third)
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i would think that watching the z-order would fix this problem, im sure that every frame the game sets its z-order back to the top, so if you just watch that it and keep calling the routine to set your form on top it should work, at least in my head it does :)
NBrownoh:
I tried this (actually before you wrote the comment), and it kind'a works.  The form i display flashes every other frame, and it looks terrible.

zzzzzooc:
Do you know of any OCX, DLL or other that could accomplish this?  (This was more or less what I expected, btw, having to use some third party control to get this to work, as it probably is way to low-level for VB to interact with properly)

What I have done atm is, instead of displaying the time, i've created a bunch of samples, and then I get my program to say it, instead of display it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Think I may have a possible solution for you. If you set the parent window of your application to the game's window then it may be able to display above it. Example below:


Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT = (-8)
Private Sub Form_Activate()
    Dim lParentHwnd As Long, lChildHwnd As Long, lFlags As Long
    lParentHwnd = FindWindow(vbNullString, "Sid Meier's Civilization III")
    lChildHwnd = Form1.hwnd
    Call SetWindowLong(lChildHwnd, GWL_HWNDPARENT, lParentHwnd)
End Sub



After that, you can try setting the Z-ORDER of your application to keep it there. I haven't tried it with much (just Civ3). :)