Install the DirectX SDK development environment:
Search for DirectX sdkon Baidu, access the Microsoft official website, and download dxsdk_jun10.exe
Baidu Network Disk: http://pan.baidu.com/s/1o6r3MDO
Download and install
Vs2010 is used for VC ++ development.
Create a vs2010 project: Win32 project, empty project
After creating an empty Win32 project, you must first set the DirectX development environment.
Right-click Project-properties and select the VC ++ directory from the project properties pop-up.
Here you need to set the include directory and library directory
Directory: D: \ Program Files (x86) \ Microsoft DirectX SDK (June 2010) \ include
Library Directory: D: \ Program Files (x86) \ Microsoft DirectX SDK (June 2010) \ Lib \ x86
After setting, create a new main. cpp file, which is the entry file of the program.
First, you must include several header files and several library files.
#include <d3d9.h>#include <d3dx9.h>#include <tchar.h>#pragma comment(lib,"winmm.lib")#pragma comment(lib,"d3d9.lib")#pragma comment(lib,"d3dx9.lib")
Then the Windows message loop window is set up:
# Include <d3d9. h> # include <d3dx9. h> # include <tchar. h> # pragma comment (Lib, "winmm. lib ") # pragma comment (Lib," d3d9. lib ") # pragma comment (Lib," d3dx9. lib ") # define window_width 800 // width # define window_height 600 // height # define window_title l" Hello, windows! "// Title lresult callback wndproc (hwnd, uint message, wparam, lparam ); // form process function // program entry [10/17/2014 administrator] int winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd) {// form creation step-1/4: form class design wndclassex wndclass = {0}; wndclass. cbsize = sizeof (wndclassex); wndclass. style = cs_hredraw | cs_vredraw; wndclass. lpfnwndproc = wndproc; wndclass. cbclsextra = 0; wndclass. cbwndextra = 0; wndclass. hinstance = hinstance; wndclass. hicon = (hicon): LoadImage (null, l "icon. ICO ", image_icon, 0, 0, lr_defaultsize | lr_loadfromfile); wndclass. hcursor = loadcursor (null, idc_arrow); wndclass. hbrbackground = (hbrush) getstockobject (gray_brush); wndclass. lpszmenuname = NULL; wndclass. lpszclassname = l "myclassname"; // create a form step-2/4: register the Form class if (! Registerclassex (& wndclass) Return-1; // form creation step-3/4: create a form to obtain the handle hwnd = createwindow (L "myclassname", window_title, ws_overlappedwindow, cw_usedefault, cw_usedefault, window_width, window_height, null, null, hinstance, null); // create a form step-4/4: display the form movewindow (hwnd, 80, window_width, window_height, true ); showwindow (hwnd, nshowcmd); updatewindow (hwnd); // message loop MSG = {0}; while (MSG. message! = Wm_quit) {If (peekmessage (& MSG, 0, 0, 0, pm_remove) {translatemessage (& MSG); dispatchmessage (& MSG );} else {// game logic update and screen rendering} unregisterclass (L "myclassname", wndclass. hinstance); Return 0;} // message processing function lresult callback wndproc (hwnd, uint message, wparam, lparam) {Switch (Message) {Case wm_paint: validaterect (hwnd, null); break; Case wm_keydown: If (wparam = vk_escape) destroywindow (hwnd); break; Case wm_destroy: postquitmessage (0); break; default: return defwindowproc (hwnd, message, wparam, lparam) ;}return 0 ;}
After the form is created, a 800*600 form is displayed. Now, the development environment is ready.
Note 1: Install DirectX SDK in some concepts