|
本人不善文字表达,因此直接贴出代码,里面有详细注释!
欢迎大家一起交流!群:87341183
同步CSDN博客 http://blog.csdn.net/qq578023708/article/details/46379605
下面是代码:
- #include <windows.h>
- #include <d3d9.h>
- #include <d3dx9.h>
- #pragma comment(lib,"d3d9.lib")
- #pragma comment(lib,"d3dx9.lib")
- #define WIN_CLASS "dx01"//窗体类名
- #define WIN_NAME "dx01" //窗体标题
- #define WIN_WIDTH 800 //窗体宽度
- #define WIN_HEIGHT 600 //窗体高度
- #define WIN_FULLSCREEN false //是否全屏
- //Windows消息回调函数
- LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
- {
- switch(msg)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_KEYUP:
- if (wparam==VK_ESCAPE)
- {
- PostQuitMessage(0);
- }
- break;
- }
- return DefWindowProc(hwnd,msg,wparam,lparam);
- }
- //Window入口函数
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
- {
- //设置窗口结构类属性
- WNDCLASSEX wc={sizeof(WNDCLASSEX),CS_CLASSDC,WndProc,0,0,hInstance,NULL,NULL,NULL,NULL,WIN_CLASS,NULL};
- //注册窗口类型
- RegisterClassEx(&wc);
- //创建窗口
- HWND hwnd= CreateWindow(WIN_CLASS,WIN_NAME,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,WIN_WIDTH,WIN_HEIGHT,NULL,NULL,hInstance,NULL);
- if (hwnd)
- {
- ShowWindow(hwnd,nShowCmd); //显示窗口
- UpdateWindow(hwnd); //更新窗口
- MSG msg;
- ZeroMemory(&msg,sizeof(msg));
- //窗口消息循环
- while (msg.message!=WM_QUIT)
- {
- if (PeekMessage(&msg,NULL,0U,0U,PM_REMOVE))
- {
- TranslateMessage(&msg); //转换消息
- DispatchMessage(&msg); //分派消息
- }
- }
- }
- }
复制代码
|
|