[.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.

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.

(.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 )
Here is code
http://www.everfall....hp?9woyzwrubfcy

Any ideas? Anybody faced with similar problem?

Share on other sites
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 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: : 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: : Scene.Editor.dp = false; break; } }

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 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 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.

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631765
• Total Posts
3002213
×