| View previous topic :: View next topic |
| Author |
Message |
b2k5
Little Pudding Boy
Joined: 25 Apr 2006
Posts: 1398
Location: Germany
|
|
|
this is a little extension of the clock i released for CS with the difference, that this one works for EVERY game :)
How does it work?
It is using the Windows Graphics Device Interface (GDI) to draw on the window which is currently in the foreground. simple hm?
The downside of using GDI is that it's flickering, so to save you from getting eye-cancer i put in a hotkey which needs to be held down to draw the clock.
Source-code:
| Code: | #include <Windows.h> // we need this.
#include <stdio.h> // input output (needed for TextOut function)
#include <time.h> // time??
void main( void )
{
HFONT newFont = CreateFont( 24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New" ); // we want a special font, the default one looks ugly!
while( true ) // main loop to keep the program alive untile closed.
{
if( GetAsyncKeyState( VK_F9 ) ) // the hotkey to show the clock.
{
struct tm *current_tm; // we
time_t current_time; // get
time( ¤t_time ); // the
current_tm = localtime( ¤t_time ); // current time
char buf[32]; // and
sprintf( buf, "[ %02i:%02i:%02i ]", current_tm->tm_hour, current_tm->tm_min, current_tm->tm_sec ); // store it nicely formatted in a string.
HWND fgw = GetForegroundWindow(); // the current window in foreground
HDC dc = GetDC( fgw ); // get the Device interface of the window
SelectObject( dc, (HGDIOBJ)newFont ); // we want to use our font, k?
SetTextColor( dc, RGB( 255, 255, 255 ) ); // give it a nice color
SetBkMode( dc, TRANSPARENT ); // and make the background transparent
TextOut( dc, 100, 100, buf, (int)strlen( buf ) ); // now we actually draw the text
UpdateWindow( fgw ); // update the window
ReleaseDC( fgw, dc ); // and release it :)
}
Sleep( 1 ); // sleep 1 ms so it doesn't take up that much of the cpu
}
DeleteObject( (HGDIOBJ)newFont ); // this is actually never called, because we close the program by just exiting it. this is a leftover, because i actually planed to add a hotkey to close the program, but forgot about it.
} |
that was simple!
if anyone wants a binary, you can donwload it here:
http://b2k5.cheat-project.com/misc/IGC.exe
|
|
| Posted on Sun Nov 23, 2008 6:50 pm |
 |
ELX[Draco]
♂♂♂♀♂ ◡ ◕
Joined: 11 Apr 2005
Posts: 8436
Location: The Netherlands
|
|
|
Sexy, too bad about the flickering though.
|
|
| Posted on Sun Nov 23, 2008 6:54 pm |
 |
NicoTn
Naughty, naughty boy!
Joined: 15 Dec 2005
Posts: 2634
Location: http://scripting.elxdraco.net/
|
|
|
thnx b2k5:P been looking for something like this :DAll heil the Almighty CATZ!
|
|
| Posted on Sun Nov 23, 2008 6:57 pm |
 |
Q_ball
unb&
Joined: 07 Jan 2007
Posts: 4558
Location: keeps coming back
|
|
|
Thanks, I'll try it out..
|
|
| Posted on Mon Nov 24, 2008 5:05 am |
 |
faxity
Little Pudding Boy
Joined: 16 Jan 2008
Posts: 1180
|
|
|
| Code: | Error 1 error C2664: 'CreateFontW' : cannot convert parameter 14 from 'const char [12]' to 'LPCWSTR' y:\vcpp\case\ingame_timer\ingame_timer\ingame_timer.cpp 7
Error 2 error C2664: 'TextOutW' : cannot convert parameter 4 from 'char [32]' to 'LPCWSTR' y:\vcpp\case\ingame_timer\ingame_timer\ingame_timer.cpp 23 |
hmm?
|
|
| Posted on Mon Nov 24, 2008 7:37 am |
 |
broodplank
Little Pudding Boy
Joined: 15 Dec 2005
Posts: 4400
Location: The Netherlands
|
|
|
|
| Posted on Mon Nov 24, 2008 9:13 am |
 |
noiz
Little Pudding Boy
Joined: 20 May 2006
Posts: 1603
|
|
|
If anyone prefers Pascal / Delphi, I made the same for another game. You need a TForm and a TLabel called outTime which is placed anywhere on that form and a global var last: String;
frmMain.onCreate:
| Code: | BorderStyle := bsNone;
FormStyle := fsStayOnTop;
Color := clLime;
AutoSize := True;
AlphaTransparency := True;
AlphaBlendColor := clLime;
outTime.Font.Size := 20;
outTime.Font.Color := clGreen;
outTime.Font.Style := outTime.Font.Style + [fsBold];
Left := 10;
Top := 10; |
frmMain.onIdle:
| Code: | if not DateTimeToStr(Now) = last then
begin
last := DateTimeToStr(Now);
outTime.Caption := last;
UnsetFocus;
end |
Code: 01001000 01100001 01101000 01100001
00101100 00100000 01110111 01100001
01110011 01110100 01100101 01100100
00100000 01110100 01101001 01101101
01100101
|
|
| Posted on Mon Nov 24, 2008 12:31 pm |
 |
jaenster
๏̯͡๏)
Joined: 12 Feb 2006
Posts: 4071
Location: The Netherlands
|
|
|
|
| Posted on Mon Nov 24, 2008 4:21 pm |
 |
faxity
Little Pudding Boy
Joined: 16 Jan 2008
Posts: 1180
|
|
|
jaenster wrote:Nice nice![/code]
haha code fail
|
|
| Posted on Mon Nov 24, 2008 4:43 pm |
 |
TheMystery357
Little Pudding Boy
Joined: 19 Sep 2009
Posts: 81
|
|
|
very nice, I will try it later
|
|
| Posted on Tue Jan 26, 2010 12:14 pm |
 |
TheMystery357
Little Pudding Boy
Joined: 19 Sep 2009
Posts: 81
|
|
|
And here is another version of this code (with very small changes)
This "new" version is for those who want to get their clock "toggled on f9 button"
| Code: | #include <Windows.h> // we need this.
#include <stdio.h> // input output (needed for TextOut function)
#include <time.h> // time??
void main( void )
{
HFONT newFont = CreateFont( 24, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New" ); // we want a special font, the default one looks ugly!
while( true ) // main loop to keep the program alive untile closed.
{
if( GetKeyState( VK_F9 ) ) // the hotkey to show the clock.
{
struct tm *current_tm; // we
time_t current_time; // get
time( ¤t_time ); // the
current_tm = localtime( ¤t_time ); // current time
char buf[32]; // and
sprintf( buf, "The time is : %02i:%02i:%02i ", current_tm->tm_hour, current_tm->tm_min, current_tm->tm_sec ); // store it nicely formatted in a string.
HWND fgw = GetForegroundWindow(); // the current window in foreground
HDC dc = GetDC( fgw ); // get the Device interface of the window
SelectObject( dc, (HGDIOBJ)newFont ); // we want to use our font, k?
SetTextColor( dc, RGB( 255, 255, 255 ) ); // give it a nice color
SetBkMode( dc, TRANSPARENT ); // and make the background transparent
TextOut( dc, 100, 100, buf, (int)strlen( buf ) ); // now we actually draw the text
UpdateWindow( fgw ); // update the window
ReleaseDC( fgw, dc ); // and release it :)
}
Sleep( 1 ); // sleep 1 ms so it doesn't take up that much of the cpu
}
DeleteObject( (HGDIOBJ)newFont ); // this is actually never called, because we close the program by just exiting it. this is a leftover, because i actually planed to add a hotkey to close the program, but forgot about it.
} |
I didnt tested this, will someone test and say the output? are there any bugs? I am asking this becouse this is a great way of me to become good C++ hacker :)
|
|
| Posted on Mon Mar 01, 2010 10:56 pm |
 |
TheMystery357
Little Pudding Boy
Joined: 19 Sep 2009
Posts: 81
|
|
|
And one more thing :
how to change clock place?
for example, I wanna put it in upper right part of screen? how can I do that?
|
|
| Posted on Mon Mar 01, 2010 11:26 pm |
 |
TheMystery357
Little Pudding Boy
Joined: 19 Sep 2009
Posts: 81
|
|
|
faxity wrote: | Code: | Error 1 error C2664: 'CreateFontW' : cannot convert parameter 14 from 'const char [12]' to 'LPCWSTR' y:\vcpp\case\ingame_timer\ingame_timer\ingame_timer.cpp 7
Error 2 error C2664: 'TextOutW' : cannot convert parameter 4 from 'char [32]' to 'LPCWSTR' y:\vcpp\case\ingame_timer\ingame_timer\ingame_timer.cpp 23 |
hmm?
Faxity it looks like you have the "unicode problem"
you should go into: project properties->configuration properties->general->Character set>>> "Use Multi-byte character set"
I hope I helped :)
and this works if you are using visual C++ 2008... for others I cant garantie but its about multi-byte anyway...
|
|
| Posted on Mon Mar 01, 2010 11:46 pm |
 |
b2k5
Little Pudding Boy
Joined: 25 Apr 2006
Posts: 1398
Location: Germany
|
|
|
TheMystery357 wrote:And one more thing :
how to change clock place?
for example, I wanna put it in upper right part of screen? how can I do that?
see second(x) and third(y) parameter of TextOut function.
|
|
| Posted on Mon Mar 01, 2010 11:57 pm |
 |
Q_ball
unb&
Joined: 07 Jan 2007
Posts: 4558
Location: keeps coming back
|
|
|
Is it possible to make this work for vista? I use the HL clock right now and it's fine, but it'd be cool if I could use it for every game.
|
|
| Posted on Tue Mar 02, 2010 8:33 am |
 |
TheMystery357
Little Pudding Boy
Joined: 19 Sep 2009
Posts: 81
|
|
|
b2k5 wrote:TheMystery357 wrote:And one more thing :
how to change clock place?
for example, I wanna put it in upper right part of screen? how can I do that?
see second(x) and third(y) parameter of TextOut function.
thankz, I missed that one :)
|
|
| Posted on Tue Mar 02, 2010 12:52 pm |
 |
b2k5
Little Pudding Boy
Joined: 25 Apr 2006
Posts: 1398
Location: Germany
|
|
|
Q_ball wrote:Is it possible to make this work for vista? I use the HL clock right now and it's fine, but it'd be cool if I could use it for every game.
this should work across all Windows versions with every game.
Could you please Be a little more precise than just saying it doesnt work on Vista?
Maybe post sp and .Net Framework Version Gfx drivers etc... :)
|
|
| Posted on Tue Mar 02, 2010 2:44 pm |
 |
faxity
Little Pudding Boy
Joined: 16 Jan 2008
Posts: 1180
|
|
|
lol @ quoting my post from 2 years ago
|
|
| Posted on Tue Mar 02, 2010 3:05 pm |
 |
TheMystery357
Little Pudding Boy
Joined: 19 Sep 2009
Posts: 81
|
|
|
hahahaha posted in november 2008 xD
I dont pay attention to that kind of stuff
|
|
| Posted on Tue Mar 02, 2010 6:01 pm |
 |
Q_ball
unb&
Joined: 07 Jan 2007
Posts: 4558
Location: keeps coming back
|
|
|
b2k5 wrote:Q_ball wrote:Is it possible to make this work for vista? I use the HL clock right now and it's fine, but it'd be cool if I could use it for every game.
this should work across all Windows versions with every game.
Could you please Be a little more precise than just saying it doesnt work on Vista?
Maybe post sp and .Net Framework Version Gfx drivers etc... :)
Vista 32bit SP2
.NET Framework 3.5 sp1
Nvidia 9600m gs - driver version 8.16.11.8681
Dunno if that helps. I'm using directx 10 as well.
|
|
| Posted on Tue Mar 02, 2010 9:57 pm |
 |
|