Dxut Study Notes (3) Response to keyboard and mouse and Message Processing

Source: Internet
Author: User

The first thing to note is,
1:
Dxut does not use a directinput device. Like a common Win32 application, dxut uses a Windows message driver to drive game operations and respond to keyboard and mouse actions. In this way, the speed of the commercial engine will be slow, but it is enough for the demo demonstration.

2:
When dinput is used, it also encapsulates the dinput actions into events and sends them to the GUI for detection to see if they hit themselves. If they are hit, a message is generated in msgproc ().

3:
In a common application, windows also converts a mouse event to a different message. Each message is directed to a different window (you can't see a hwnd handle in each message struct ?), A mouse event can be processed by different windows or even different applications.
One problem that has plagued me for many years is that can programmers control the mechanism of converting events into messages? Forgot to give advice.
Typedef struct tagmsg {
Hwnd; // indicates
Uint message;
Wparam;
Lparam;
DWORD time;
Point pt;
} Msg
4: for 3D game programs, there is only one window. The GUI is actually just a painting in the window. Therefore, we need to abstract the concept of the window to our GUI elements, each button and element on the interface have a unique ID (this ID can be used to generate a unique ID when being generated to an element). This ID, it can be considered as the window handle of this element!

Next let's take a look at the dxut event message system.
1: window message processing function of dxutstaticwndproc instant Application

Dxutcreatewindow (...)
{
...
Wndclass. lpfnwndproc = dxutstaticwndproc; // It indicates that dxutstaticwndproc is the message processing function of the entire application.
}

2: dxutstaticwndproc
1
This function is used to distribute messages and send keyboard messages to proc for processing.
Lpdxutcallbackkeyboard pcallbackkeyboard = getdxutstate (). getkeyboardfunc ();
If (pcallbackkeyboard)
Pcallbackkeyboard (uint) wparam, bkeydown, baltdown, getdxutstate (). getkeyboardfuncusercontext ());
2
The mouse message is handed over to proc for processing:
Lpdxutcallbackmouse pcallbackmouse = getdxutstate (). getmousefunc ();
If (pcallbackmouse)
Pcallbackmouse (bleftbutton, brightbutton, bmiddlebutton, bsidebutton1, bsidebutton2, nmousewheeldelta, xpos, ypos, getdxutstate (). getmousefuncusercontext ());
(The two above message processing functions are not removed after processing, and the messages are still handed over to the following main message processing functions. you can do nothing about these two functions, which is just for your convenience)
3
Process all the messages to msgproc (). Here is the main part of programming.
In this function, messages are sent to the GUI for processing and to camera for processing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.