Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / make sounds play when program is in background?

Author
Message
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 13th Jun 2011 16:22 Edited at: 13th Jun 2011 16:44
Hey,


Whenever I minimize my program or put my program in the background, the music and sounds that are playing go quite. How can I keep them playing? Same with button input from mouse/keyboard, how can I make the program still accept input even though it's not in the foreground?

And, if anyone by chance knows what "source code" is in French, I'd be glad to know


Thanks,

TheComet

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jun 2011 18:02
Quote: " how can I make the program still accept input even though it's not in the foreground?"


You can't. How would Windows know that you don't want to interact with the application in the foreground, and how does that application know that even though it has focus, you don't want to interact with it? As well as going against the logic of the operating system, it would also be a security risk.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 13th Jun 2011 18:39
Quote: "You can't. How would Windows know that you don't want to interact with the application in the foreground, and how does that application know that even though it has focus, you don't want to interact with it? As well as going against the logic of the operating system, it would also be a security risk."


Things like teamspeak are able to do it... So there's no easy way to do it? DBC I believe had the command always active on, not sure if that's the one though...

TheComet

BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 13th Jun 2011 21:29
It won't be doing it by retaining the focus. I don't know the details but it looks like it just listens to the mic port, and relays it to an IP address/port. It doesn't need focus to do that (just like MSN doesn't need to have focus to tell you somebody is pinging you, or your email client receiving mail)

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 13th Jun 2011 23:11
Quote: "It won't be doing it by retaining the focus."

Okay, well now that that's out of the way how would one do what TheComet described in DBPro?


Why does blue text appear every time you are near?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jun 2011 00:45
You wouldn't.

It's technically possible to capture input using Windows CBT functionality, but that is usually blocked by anti-spyware and anti-virus software - you'd have to write a plug-in to do it too.

Likewise, it's possible to play sounds without having the focus, but only if it's specifically enabled in DirectX. Again, you'd have to write your own plug-in to do this, or modify your own copy of the Sound plug-in. It's probably possible in pretty much the same way for Music too.

Mistrel
Retired Moderator
20
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 14th Jun 2011 02:51 Edited at: 14th Jun 2011 02:59
Of course you can.

Quote: "LOAD SOUND Filename,Sound Number,Flag,Silent Fail,Global Sound Flag

..

Global Sound Flag
Set this flag to 1 to play sound even if application does not have focus"


This functionality is native to the DirectSound API by specifying a global sound buffer.

I think music is already global.

Keyboard input you can get with GetKeyState() and mouse input with GetCursorPos() from Win32 API calls.

http://msdn.microsoft.com/en-us/library/ms646301(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms648390(v=vs.85).aspx

Both of these functions are available in the User32.dll library.

All of these features are enabled by default in PureGDK.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 14th Jun 2011 14:05
@ Mistrel

Thanks! I'll try it out as soon as I get the chance

TheComet

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 16th Jun 2011 16:31 Edited at: 16th Jun 2011 17:10
This is my first time using the command call dll, so don't laugh What's wrong here?

user32=1
make memblock 1,1
mem_ptr=get memblock ptr(1)

...

call dll user32,"GetKeyState",keynumber,mem_ptr
if memblock byte(1,0) && 0x01=1 then do stuff


where keynumber is the ASCII value of "w", 119.

TheComet

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Jun 2011 00:35
GetKeyState doesn't work like that.

1. It accepts a single argument of the key to check, and returns a WORD value as its result.
2. It only works if your window has focus and is processing keypress messages.

Besides, it's already implemented in DBPro as the GET KEY STATE() function.

I think that GetAsyncKeyState is probably the one that you want to look at, but again, I don't think that'll work if you don't have focus. You'll need to try it.

@Mistrel,
Oops, my mistake.

Login to post a reply

Server time is: 2026-07-10 22:55:05
Your offset time is: 2026-07-10 22:55:05