Solved

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

Posted on 2003-11-08
11
283 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
Comment Utility
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
Comment Utility
'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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:NBrownoh
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now