.Net WinForm System Beep on a 64 Bit OS

我与影子孤独终老i 提交于 2019-11-28 07:35:39

问题


My application needs to beep when validation fails so the user (who may be several feet away) may hear it. I'd like to use the Console.Beep() but this is unavailable in a x64 environment (see the remarks). There may or may not be speakers in/at the computer, so I can't use System.Media.SystemSounds.Beep.Play().

The current target platform is a x86 environment, but I'd like to have the ability for the application to run in x64 also.

Is there a way to do this or should I just give up?

Edit: Added link to the method.


回答1:


Beep has been removed as a native function from all x64 platforms (so no managed version of course), there was a Microsoft Connect issue that petitioned to return it.

We use a different trick to discover servers, we remote eject the dvd drive, and the drive with the tray open is the one were looking for :)

[EDIT]
Larry Osterman has a great article about this: What's up with the beep driver in Windows 7




回答2:


Playing one of the standard windows sounds might be a better approach. The following article shows how (it only takes a couple lines):

http://msdn.microsoft.com/en-us/library/4y171b18(VS.100).aspx

If you wanted to stay within theme, you could check the windows registry for the current sound scheme, and play the appropriate sound to fit your need.




回答3:


You can use the Console.Beep() method described here: https://msdn.microsoft.com/en-us/library/8hftfeyw(v=vs.110).aspx

Make sure that you run the executable as an administrator (escalated privileges)



来源:https://stackoverflow.com/questions/1488531/net-winform-system-beep-on-a-64-bit-os

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!