Jump to content
  • Advertisement
Sign in to follow this  
LaudaDAgnus

[.net] System sound in Windows Forms (C++, Direct3D 9)

This topic is 2529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everybody!
Sorry my english, I'm russian developer.

Recently I started working with Windows Forms (Visual C++ 2010 Express) to create some utilities for my project. So I create form, place all controls I need and render my scene (Direct3D 9) into "Panel" object. Then I bound my render function with "Timer".

Now I trying to make WSAD-movement for the cam and here I encoutered with this proplem. Camera works nice, but it is the assidentally sound at the keydown event. Its sounds like MessageBox sound and I have not any ideas why and when (in code) this sound happends.

http://z-prog.info/download/editor02.rar
(.NET Framework 4.0 and d3dx9_43.dll needed)

I working with treeView1_KeyDown, because it is in focus, when programm started.
Some problems with code sample pasting (size="2" in every line mellow.gif)
Here is code
http://www.everfall....hp?9woyzwrubfcy



Any ideas? Anybody faced with similar problem?

Share this post


Link to post
Share on other sites
Advertisement
The TreeView control does not know how to handle WASD and so makes the default beep when it receives a key that it doesn't support. One way to work around this would be to set e.SuppressKeyPress = true; in your key event handler for each key you handle yourself (do not set it to true for keys you do not handle else those keys will stop working in the TreeView control).

A better way to handle key input may be to put the form in control. Ensure that the form gets a chance to receive keyboard events before the other controls claim them by setting the form's KeyPreview property to true. You can then handle the key events with the form's event handlers, rather than relying on a specific control (such as the TreeView control) being selected.

Share this post


Link to post
Share on other sites
thanks! no more sound with [color="#1C2837"]e.SuppressKeyPress = true; on each key.
[color="#1C2837"]

[color="#1C2837"]this is norm?
[color="#1C2837"]

[color="#1C2837"]private: System::Void treeView1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
switch(e->KeyCode)
{
case Keys::W :
e->SuppressKeyPress = true;
Scene.Editor.wp = true;
break;
case Keys::S :
e->SuppressKeyPress = true;
Scene.Editor.sp = true;
break;
case Keys::A :
e->SuppressKeyPress = true;
Scene.Editor.ap = true;
break;
case Keys::D :
e->SuppressKeyPress = true;
Scene.Editor.dp = true;
break;
}
}
private: System::Void treeView1_KeyUp(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
switch(e->KeyCode)
{
case Keys::W :
Scene.Editor.wp = false;
break;
case Keys::S :
Scene.Editor.sp = false;
break;
case Keys::A :
Scene.Editor.ap = false;
break;
case Keys::D :
Scene.Editor.dp = false;
break;
}
}

Share this post


Link to post
Share on other sites
If it works, I guess so. It does still seem like a bit of a hack to put the keyboard handling code for the form into a TreeView control, though!

Share this post


Link to post
Share on other sites
[color=#1C2837][size=2]A better way to handle key input may be to put the form in control.[/quote]

I don't understand this... How can I do this?

May be just call Form::Keydown method in keydown event of TreeView (and in other controls, that can be active)? It's will be norm?

Share this post


Link to post
Share on other sites
If you set the Form's KeyPreview property to "true" it will receive KeyUp/KeyDown events before the control that has focus.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!