[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Drawing a form in the DC of a third-party application

I have a game that when running, runs in full screen mode.  I am wondering if it is possible to write an application that would allow a visual pop-up in the DC of the game window.  Basically, I want to show a notification when something occurs on my PC, like a Skype call or email received, etc...  I have wriiten a program that can tell when the game is active and seems to correctly get the DC of the game window.  I just can't seem to find a way to draw into the DC...  If someone could point me in the right direction, it would be greatly appreciated.  Some code would help too :-)  I just want to pop up the window, be able to move it to another part of the screen or close it.  
0
TomGrills
Asked:
TomGrills
  • 5
  • 3
1 Solution
 
ZhaawZSoftware DeveloperCommented:
(1) Is it a specific game or it can be any game?
(2) Does it/they use DirectX, OpenGL or something else?
0
 
TomGrillsAuthor Commented:
I'd like it to be any game...  But this one that I play most often is DirectX ....

0
 
ZhaawZSoftware DeveloperCommented:
 Hmm.. I don't know about "universal" way of doing this. However with DX it should be possible :) Not sure about "how this can be done", but I have an idea and I know that it works (at least for me).

  Here's an idea...

  I have a .dll file (however I don't have / have never seen a source-code for it, so I can't help with this part) that works like a bridge between the game and DX. Author of this .dll file implemented a possibility to show an image with no textures (i.e., to show only wireframes) - this means that it IS POSSIBLE to add a popup to screen.
  The game looks for DX .dll files in a directory of the game if no other path is specified. File "d3d9.dll" is responsible for drawing an image on the screen. You have to make your own d3d9.dll that has all the functions that are in original "d3d9.dll". Game loads your d3d9.dll. When game calls a function from your .dll, you have to call the same functions from original d3d9.dll (i.e., you don't have to write all the functions, you just have to make a "connection" in your .dll between game and original .dll file).
  When this is done (i.e., default function is called and processed), you may draw something else on the screen.


  I hope you got the idea (english is not my native language).
  As I said, this is only the idea. I have only "user experience" with this stuff.
0
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!

 
TomGrillsAuthor Commented:
I don't think that the image would be clickable and movable....  I think it should be a bit simpler than hijacking the DX DLL...  I thought that I could write directly into the Device Context...  Perhaps using a transparent form that overlays the current image and non transparent where the clickable control would be...  Maybe I'm not thinking of this the right way...  all I really want to do is draw the form so that it appears and stays on top of the game screen...  This way, I can acknowledge the alert and continue playing the game if I choose to...   Maybe I should be trying to add a child window to the application handle of the game?  Any ideas?
0
 
ZhaawZSoftware DeveloperCommented:
You may capture mouse clicks and movement - there's no problem. It would be quite easy to implement clicking and moving such "self-drawn popup".


Sure, you may draw directly into the DC, however the image will blink all the time because DX is redrawing screen all the time. Here's what I tried:

[source]
procedure TForm1.Timer1Timer(Sender: TObject);
var
  wnd : cardinal;
  hdc : cardinal;
begin
wnd := FindWindow('ArkClientMainWindow', 'Project Entropia');
if wnd = 0 then begin
  Timer1.Interval := 1000;
end else begin
  Timer1.Interval := 1;
  hdc := GetWindowDC(wnd);
  if hdc <> 0 then begin
    Rectangle(hdc, 0, 0, 20, 20);
    ReleaseDC(wnd, hdc);
  end;
end;
end;
[/source]

wnd := FindWindow('ArkClientMainWindow', 'Project Entropia');  <-- this gets a handle of the "game window"
hdc := GetWindowDC(wnd);  <-- this gets device context of the window
Rectangle(hdc, 0, 0, 20, 20);  <-- this draws a small rectangle in top-left corner of screen

As you can see, it's done many times each second (Timer1.Interval := 1), and it blinks, blinks, blinks all the time.

Now trying with "child window"...
0
 
ZhaawZSoftware DeveloperCommented:
Here it is:

[source]
var
  chld : cardinal = 0;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  wnd : cardinal;
begin
if chld = 0 then begin
  wnd := FindWindow('ArkClientMainWindow', 'Project Entropia');
  if wnd <> 0 then begin
    beep;
    chld := CreateWindowEx(
      ws_ex_toolwindow or ws_ex_topmost,
      '#32770', nil,
      ws_visible or ws_child or ws_caption,
      0, 0, 100, 100,
      wnd, 0, hInstance, nil
    );
    Timer1.Enabled := false;
  end;
end;
end;
[/source]

This creates a small (100×100px) dialog window as a child control of game window. It works fine if created in another form, however it can't be seen if created in a "window of game". The game draws picture over this window. It can be moved, it can be clicked, but you can't see it. Moreover - the game also captures all user input (i.e., clicking mouse buttons and moving mouse cursor).


About "transparent form" - I'm not sure if it is possible. But even if it is, it also will blink (I've seen blinking skype notice-window while playing some games and also another blinking info-windows from another software - it's possible to see that there is *something*, but it's impossible to read something in such blinking window).


I still advise you to make a custom d3d9.dll file (to avoid blinking).
Mouse input can be captured and blocked (if needed) by using low-level mouse hooks (this can be done with SetWindowsHookEx() function).
0
 
TomGrillsAuthor Commented:
Could you provide an example of the code you use that works for you?  I assume that you hook the mouse as well?  if you could sow an example of how you do it, I can try to write a wrapper around the d3d9.dll...  also, I'll up the points too ...  ;-)  
0
 
ZhaawZSoftware DeveloperCommented:
As I said, I do not have a souce of .dll that I'm using (I'm not an author of it). And I use it for other purposes (1 - to be able to see pic without textures; 2 - to be able to run a game in windowed mode)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now