Home > Software engineering >  Win32 empty project d3d9 loading bitmaps photo. PNG why Windows compiled a flash out right
Win32 empty project d3d9 loading bitmaps photo. PNG why Windows compiled a flash out right

Time:10-02

#include
#include
#include
#include
#include
using namespace std;
# pragma comment (lib, "d3d9. Lib")
# pragma comment (lib, "d3dx9. Lib")

Const string APPTITLE="the Draw Bitmap Program";

# define SCREENW 800
# define SCREENH 600

# define KEY_DOWN (vk_code) ((GetAsyncKeyState (vk_code) & amp; 0 x8000)? 1-0)

LPDIRECT3D9 d=NULL;
LPDIRECT3DDEVICE9 d3ddev=NULL;
LPDIRECT3DSURFACE9 backbuffer=NULL;
LPDIRECT3DSURFACE9 surface=NULL;

Bool gameover=false;
Bool Game_Init (HWND Windows)
{
D=Direct3DCreate9 (D3D_SDK_VERSION);
if (! D)
{
MessageBox (window, "the Error initializing Direct3D", "Error", MB_OK);
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory (& amp; D3dpp, sizeof (d3dpp));
D3dpp. Windowed=TRUE;
D3dpp. SwapEffect=D3DSWAPEFFECT_DISCARD;
D3dpp. BackBufferFormat=D3DFMT_X8R8G8B8;
D3dpp. BackBufferCount=1;
D3dpp. BackBufferWidth=SCREENW;
D3dpp. BackBufferHeight=SCREENH;
D3dpp. HDeviceWindow=window;
D3d - & gt; CreateDevice (D3DADAPTER_DEFAULT D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, & amp; D3dpp, & amp; D3ddev);
if (! D3ddev)
{
MessageBox (window, "the Error creating Dicect3D device", "Error", MB_OK);
return false;
}

D3ddev - & gt; Clear (0, NULL, D3DCLEAR_TARGET D3DCOLOR_XRGB (0, 0, 0), 1.0 f, 0).
Retrieves the result=d3ddev - & gt; CreateOffscreenPlainSurface (SCREENW SCREENH, D3DFMT_X8R8G8B8 D3DPOOL_DEFAULT, & amp; Surface, NULL);
If (result!=D3D_OK) return false.
Result=D3DXLoadSurfaceFromFile (surface, NULL, NULL, "phtot. PNG", NULL, D3DX_DEFAULT, 0, NULL);
If (result!=D3D_OK) return false.
return true;
}

Void Game_Run (HWND HWND)
{
if (! D3ddev) return;
D3ddev - & gt; GetBackBuffer (0, 0, D3DBACKBUFFER_TYPE_MONO, & amp; Backbuffer);
If (d3ddev - & gt; BeginScene ())
{
D3ddev - & gt; StretchRect (surface, NULL, backbuffer, NULL, D3DTEXF_NONE);
D3ddev - & gt; EndScene ();
D3ddev - & gt; The Present (NULL, NULL, NULL, NULL);
}
If (KEY_DOWN (VK_ESCAPE))
PostMessage (HWND, WM_DESTROY, 0, 0);
}

Void Game_End (HWND HWND)
{
If (surface) surface - & gt; Release ();
If (d3ddev) d3ddev - & gt; Release ();
If (d) d - & gt; Release ();
}

LRESULT WINAPI WinProc (HWND HWND, UINT MSG, WPARAM WPARAM, LPARAM LPARAM)
{
The switch (MSG)
{
Case WM_DESTROY:
Gameover=true;
break;
}
Return DefWindowProc (hWnd, MSG, wParam, lParam);
}

Int WINAPI WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
Modifed WNDCLASSEX wc.
The HWND HWND;
MSG message;
Wc. CbSize=sizeof (modifed WNDCLASSEX);
Wc. Style=CS_HREDRAW | CS_VREDRAW;
Wc. LpfnWndProc=(WNDPROC WinProc);
Wc. CbClsExtra=0;
Wc. CbWndExtra=0;
Wc. LpszMenuName=NULL;
Wc. HIcon=NULL;
Wc. HIconSm=NULL;
The wc. The hInstance=hInstance;
Wc. HCursor=LoadCursor (NULL, IDC_ARROW);
Wc. HbrBackground=(HBRUSH) GetStockObject (WHITE_BRUSH);
Wc. LpszClassName="MainWindowClass";

if (! RegisterClassEx (& amp; Wc))
Return FALSE;
HWND=CreateWindow (" MainWindowClass, "APPTITLE c_str (), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREENW, SCREENH, NULL, NULL, hInstance, NULL);

If (HWND==0) return 0;
ShowWindow (HWND, nCmdShow);
UpdateWindow (HWND);
if (! Game_Init (HWND)) return FALSE.
while (! Gameover)
{
If (PeekMessage (& amp; The message, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (& amp; Message);
DispatchMessage (& amp; Message);
}
Game_Run (HWND);
}
The return message. WParam;
}

CodePudding user response:

Code function at the end of the day is not others to help you see or interpretation or comment; But by myself calm down and take a long enough time and energy to do it yourself step or set a breakpoint or step to perform to a certain intermediate result shows or written to the log file analysis step by step,
Remind: cow x teacher cannot replace the student understand and use the toilet!
Single step debugging and set breakpoint debugging (VS IDE compilation connection through later, press F10 or F11 key step, press Shift + F11 exit the current function; In a press F9 set breakpoints after press F5 execution stops at the breakpoint,) is one of the programmers must master the skills,

CodePudding user response:

Thank you, I see
  • Related