Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if _WIN32_WINNT < 0x0500
- #undef _WIN32_WINNT
- #define _WIN32_WINNT 0x0500
- #endif
- #define _UNICODE
- #define UNICODE
- #include <windows.h>
- #include <windowsx.h>
- #include <iostream>
- #include <d3d11.h>
- #include <d3dx11.h>
- #include <d3dx10.h>
- #pragma comment (lib, "d3d11.lib")
- #pragma comment (lib, "d3dx11.lib")
- #pragma comment (lib, "d3dx10.lib")
- using namespace std;
- IDXGISwapChain *swapchain;
- ID3D11Device *dev;
- ID3D11DeviceContext *devcon;
- // function prototypes
- void InitD3D(HWND hWnd);
- void CleanD3D(void);
- LRESULT CALLBACK WindowProc(HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow){
- HWND hWnd;
- WNDCLASSEX wc;
- ZeroMemory(&wc, sizeof(WNDCLASSEX));
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- wc.lpszClassName = L"WindowClass1";
- RegisterClassEx(&wc);
- RECT clients = {0,0,500,400};
- AdjustWindowRect(&clients, WS_OVERLAPPEDWINDOW, FALSE);
- hWnd = CreateWindowEx(NULL,
- L"WindowCLass1",
- L"Window Program",
- WS_OVERLAPPEDWINDOW,
- 300,
- 300,
- clients.right - clients.left,
- clients.bottom - clients.top,
- NULL,
- NULL,
- hInstance,
- NULL);
- ShowWindow(hWnd, nCmdShow);
- //ShowWindow( GetConsoleWindow(), SW_HIDE );
- MSG msg;
- /*while(GetMessage(&msg,NULL,0,0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }*/
- while (TRUE)
- {
- if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if(msg.message == WM_QUIT)
- break;
- }
- else
- {
- //gcode
- }
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WindowProc(HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam)
- {
- switch(message)
- {
- case WM_DESTROY:
- {
- //ShowWindow( GetConsoleWindow(), SW_RESTORE );
- PostQuitMessage(0);
- return 0;
- }break;
- }
- return DefWindowProc (hWnd, message, wParam, lParam);
- }
- void InitD3D(HWND hWnd)
- {
- DXGI_SWAP_CHAIN_DESC scd;
- ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
- scd.BufferCount = 1;
- scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- scd.OutputWindow = hWnd;
- scd.SampleDesc.Count = 1;
- scd.Windowed = TRUE;
- D3D11CreateDeviceAndSwapChain(NULL,
- D3D_DRIVER_TYPE_HARDWARE,
- NULL,
- NULL,
- NULL,
- NULL,
- D3D11_SDK_VERSION,
- &scd,
- &swapchain,
- &dev,
- NULL,
- &devcon);
- }
- void CleanD3D()
- {
- swapchain->Release();
- dev->Release();
- devcon->Release();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement