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

Started by
4 comments, last by benryves 12 years, 8 months ago
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?
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.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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;
}
}

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!

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

[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?
If you set the Form's KeyPreview property to "true" it will receive KeyUp/KeyDown events before the control that has focus.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

This topic is closed to new replies.

Advertisement