Dxut Programming Guide (III): using the program window through dxut

Source: Internet
Author: User

Use the program window through dxut

Your application can process most window management tasks if you use less dxut functions.
Create a window

Use your own window


Create a window

Creating a window for a direct3d application involves the following steps:
1. Define a window message (defining a to respond to the proper window messages .)
2. Setting up .)
3. Use (using .)
4. Use (using.) // This is a bit strange. ^ _ ^. This is the original version.

These steps are incorrect, which may cause the bugs. Although this is not exciting for direct3d programmers, they are required by every application. The framework uses the dxutcreatewindow function to simplify this step:
Hresult dxutcreatewindow (
Const wchar * strwindowtitle = l "direct3d window ",
Hinstance = NULL,
Hicon = NULL,
Hmenu = NULL,
Int x = cw_usedefault,
Int y = cw_usedefault
);
All parameters are optional:
Strwindowtitle is the title of the window and displayed on the taskbar. It is usually the project title.
Hinstance is the handle of the application instance. Typically, it is set to null by most programs.
Hicon is the handle of the application icon. If it is null, the first icon that embeds the executable file of the application will be used. So null can work well.
Hmenu is the menu handle. You can set it if you want. Most games do not use standard menus, but create their own game interfaces.
The last two parameters describe the location of the window. In full screen mode, they are ignored.
The simplest example is that an application can call the dxutcreatewindow function like this:
Dxutcreatewindow (L "My New Game ");
Only the first strwindowtitle parameter is input to call this function. The framework automatically creates a window and processes window messages. The window handle can be obtained by calling dxutgethwnd, if necessary.
If the application needs to respond to window messages, it can use dxutsetcallbackmsgproc to set the callback function:
Void dxutsetcallbackmsgproc (lpdxutcallbackmsgproc pcallbackmsgproc,
Void * pusercontext = NULL );
The pcallbackmsgproc parameter is an lpdxutcallbackmsgproc callback function. It has the following syntax:
Lresult callback function msgproc (
Hwnd,
Uint umsg,
Wparam,
Lparam,
Bool * pbnofurtherprocessing,
Void * pusercontext
)
{
Return 0;
}
In this callback function, the application does not need to respond to any messages, because all important messages are still processed by the framework. To prevent the framework from processing messages, the application can set * pbnofurtherprocessing to true. (Refer to lpdxutcallbackmsgproc) However, be careful when using this setting because it may cause the framework to fail to work correctly.


Use your own window

If you want the application to create and use its own window instead of letting dxut process window operations. You can create a window and use the dxutsetwindow function:
Hresult dxutsetwindow (
Hwnd hwndfocus,
Hwnd hwnddevicefullscreen,
Hwnd hwnddevice1_wed,
Bool bhandlemessages = true
);
This function requires three window handles, which are usually the same unless the window-based program uses a different window from the full-screen program. The focus window handle is used to tell direct3d when the application is switched to the background (by Alt + TAB, Mouse clicking, or other user input ). Applications usually need to pass in the focus window handle, no matter how many direct3d devices are created.
In addition to a window initialization framework, the application needs to notify the framework of received window messages to make the framework work normally. If a window is created by the Framework, the window message is automatically processed. In addition, the application can transmit messages to the framework in the windowproc callback function of the window, which can be implemented through the dxutstaticwndproc function. Its definition is as follows:
Lresult callback dxutstaticwndproc (
Hwnd,
Uint umsg,
Wparam,
Lparam
);
If you do not want applications to use dxutstaticwndproc, you can replace the functions in the function. But you are not recommended to do this. (You can alternately duplicate the functionality found in the function if you do not want the application to use dxutstaticwndproc .)

Back to main directory

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.