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

Posted on 2003-11-08
Last Modified: 2012-05-04
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.
Question by:FlyveHest
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2

Expert Comment

ID: 9709011
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?


Expert Comment

ID: 9709212
'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

'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.

Author Comment

ID: 9709431

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)
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 17

Accepted Solution

zzzzzooc earned 250 total points
ID: 9709501
Basically, the display adapter is reserved for the game while in full-screen mode. When in windowed-mode, only the desktop rectangle of the client (game) window is reserved (until moved) which allows repainting of other windows out-of-the-way of the client window. I'm not too keen on DirectX programming, but the logic of it should be somewhat like that.

The only solution I can see for you to do is attempt some type of kernel-mode driver (2k/XP) or VxD (Win9x) to interact directly with the display adapater. And that most-likely will require using assembly.


Expert Comment

ID: 9712304
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 :)

Author Comment

ID: 9712708
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.

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.

Assisted Solution

MaxPol earned 250 total points
ID: 9714070
Hi, if you have a full-screen Directx application, you cannot force a window on top of it. You are in full screen single application environment and thus only one application at a time can be displayed (the one that created it).

You should minimize the directx Application if runnig or changing to windowed mode.

Or create your DirectX message window.


LVL 17

Expert Comment

ID: 9714200
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). :)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question