Advertisement
Guest User

Untitled

a guest
Feb 20th, 2015
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #if _WIN32_WINNT < 0x0500
  2. #undef _WIN32_WINNT
  3. #define _WIN32_WINNT 0x0500
  4. #endif
  5.  
  6. #define _UNICODE
  7. #define UNICODE
  8.  
  9. #include <windows.h>
  10. #include <windowsx.h>
  11. #include <iostream>
  12. #include <d3d11.h>
  13. #include <d3dx11.h>
  14. #include <d3dx10.h>
  15.  
  16. #pragma comment (lib, "d3d11.lib")
  17. #pragma comment (lib, "d3dx11.lib")
  18. #pragma comment (lib, "d3dx10.lib")
  19.  
  20. using namespace std;
  21.  
  22. IDXGISwapChain *swapchain;
  23. ID3D11Device *dev;
  24. ID3D11DeviceContext *devcon;
  25.  
  26. // function prototypes
  27. void InitD3D(HWND hWnd);
  28. void CleanD3D(void);
  29.  
  30. LRESULT CALLBACK WindowProc(HWND hWnd,
  31. UINT message,
  32. WPARAM wParam,
  33. LPARAM lParam);
  34.  
  35. int WINAPI WinMain(HINSTANCE hInstance,
  36. HINSTANCE hPrevInstance,
  37. LPSTR lpCmdLine,
  38. int nCmdShow){
  39.  
  40. HWND hWnd;
  41.  
  42. WNDCLASSEX wc;
  43.  
  44. ZeroMemory(&wc, sizeof(WNDCLASSEX));
  45.  
  46. wc.cbSize = sizeof(WNDCLASSEX);
  47. wc.style = CS_HREDRAW | CS_VREDRAW;
  48. wc.lpfnWndProc = WindowProc;
  49. wc.hInstance = hInstance;
  50. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  51. wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  52. wc.lpszClassName = L"WindowClass1";
  53.  
  54. RegisterClassEx(&wc);
  55.  
  56. RECT clients = {0,0,500,400};
  57. AdjustWindowRect(&clients, WS_OVERLAPPEDWINDOW, FALSE);
  58.  
  59. hWnd = CreateWindowEx(NULL,
  60. L"WindowCLass1",
  61. L"Window Program",
  62. WS_OVERLAPPEDWINDOW,
  63. 300,
  64. 300,
  65. clients.right - clients.left,
  66. clients.bottom - clients.top,
  67. NULL,
  68. NULL,
  69. hInstance,
  70. NULL);
  71.  
  72. ShowWindow(hWnd, nCmdShow);
  73.  
  74. //ShowWindow( GetConsoleWindow(), SW_HIDE );
  75.  
  76. MSG msg;
  77.  
  78. /*while(GetMessage(&msg,NULL,0,0))
  79. {
  80. TranslateMessage(&msg);
  81.  
  82. DispatchMessage(&msg);
  83. }*/
  84.  
  85. while (TRUE)
  86. {
  87. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  88. {
  89. TranslateMessage(&msg);
  90.  
  91. DispatchMessage(&msg);
  92.  
  93. if(msg.message == WM_QUIT)
  94. break;
  95. }
  96. else
  97. {
  98. //gcode
  99. }
  100. }
  101.  
  102. return msg.wParam;
  103.  
  104. }
  105.  
  106. LRESULT CALLBACK WindowProc(HWND hWnd,
  107. UINT message,
  108. WPARAM wParam,
  109. LPARAM lParam)
  110. {
  111. switch(message)
  112. {
  113. case WM_DESTROY:
  114. {
  115. //ShowWindow( GetConsoleWindow(), SW_RESTORE );
  116. PostQuitMessage(0);
  117. return 0;
  118. }break;
  119.  
  120. }
  121. return DefWindowProc (hWnd, message, wParam, lParam);
  122. }
  123. void InitD3D(HWND hWnd)
  124. {
  125. DXGI_SWAP_CHAIN_DESC scd;
  126.  
  127. ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
  128.  
  129. scd.BufferCount = 1;
  130. scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  131. scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  132. scd.OutputWindow = hWnd;
  133. scd.SampleDesc.Count = 1;
  134. scd.Windowed = TRUE;
  135.  
  136. D3D11CreateDeviceAndSwapChain(NULL,
  137. D3D_DRIVER_TYPE_HARDWARE,
  138. NULL,
  139. NULL,
  140. NULL,
  141. NULL,
  142. D3D11_SDK_VERSION,
  143. &scd,
  144. &swapchain,
  145. &dev,
  146. NULL,
  147. &devcon);
  148. }
  149.  
  150. void CleanD3D()
  151. {
  152. swapchain->Release();
  153. dev->Release();
  154. devcon->Release();
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement