Solved

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

Posted on 2003-11-08
11
284 Views
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.
0
Comment
Question by:FlyveHest
  • 2
  • 2
  • 2
  • +2
11 Comments
 
LVL 2

Expert Comment

by:gimmeadrink
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?


0
 
LVL 3

Expert Comment

by:NBrownoh
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
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.
0
 

Author Comment

by:FlyveHest
ID: 9709431
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)
0
 
LVL 17

Accepted Solution

by:
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.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:NBrownoh
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 :)
0
 

Author Comment

by:FlyveHest
ID: 9712708
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.
0
 
LVL 2

Assisted Solution

by:MaxPol
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.


Bye,

Max
0
 
LVL 17

Expert Comment

by:zzzzzooc
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). :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now