Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define WIN32_LEAN_AND_MEAN
- #define WIN32_EXTRA_LEAN
- #include <windows.h>
- #include <CommCtrl.h>
- #include <tchar.h>
- #include <d3d9.h>
- #include <Uxtheme.h>
- typedef LRESULT (CALLBACK *WINDOWPROC)(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- LRESULT CALLBACK ListViewWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- WINDOWPROC originalListViewWindowProc;
- HWND wnd;
- HWND listView;
- HBITMAP dib;
- HDC memoryDC;
- void * bits;
- IDirect3D9 * d3d;
- IDirect3DDevice9 * d3ddev;
- IDirect3DTexture9 * tex;
- struct Vertex
- {
- float p[3];
- float uv[2];
- };
- INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- InitCommonControls();
- const WNDCLASSEX wndClass = {
- sizeof(WNDCLASSEX),
- 0,
- WindowProc,
- 0,
- 0,
- GetModuleHandle(0),
- 0,
- 0,
- 0,
- 0,
- _T("A"),
- 0
- };
- RegisterClassEx(&wndClass);
- RECT rect;
- rect.left = 0;
- rect.top = 0;
- rect.right = 500;
- rect.bottom = 500;
- AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, FALSE, 0);
- wnd = CreateWindowEx(0, _T("A"), _T("A"), WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 500, 500, 0, 0, GetModuleHandle(0), 0);
- memoryDC = CreateCompatibleDC(NULL);
- BITMAPINFO bi;
- ZeroMemory(&bi, sizeof(bi));
- bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
- bi.bmiHeader.biWidth = 500;
- bi.bmiHeader.biHeight = -500;
- bi.bmiHeader.biPlanes = 1;
- bi.bmiHeader.biBitCount = 32;
- bi.bmiHeader.biCompression = BI_RGB;
- HBITMAP bitmap = CreateDIBSection(memoryDC, &bi, DIB_RGB_COLORS, &bits, NULL, 0);
- SelectObject(memoryDC, bitmap);
- GetClientRect(wnd, &rect);
- listView = CreateWindow(WC_LISTVIEW, _T(""), WS_CHILD | LVS_LIST | WS_VISIBLE, 0, 0, (rect.right - rect.left), (rect.bottom - rect.top), wnd, 0, GetModuleHandle(0), 0);
- originalListViewWindowProc = (WINDOWPROC)GetWindowLongPtr(listView, GWL_WNDPROC);
- SetWindowLongPtr(listView, GWL_WNDPROC, (LONG)ListViewWindowProc);
- d3d = Direct3DCreate9(D3D_SDK_VERSION);
- D3DPRESENT_PARAMETERS presentParams = {
- 500,
- 500,
- D3DFMT_UNKNOWN,
- 1,
- D3DMULTISAMPLE_NONE,
- 0,
- D3DSWAPEFFECT_DISCARD,
- listView,
- TRUE,
- FALSE,
- D3DFMT_D24S8,
- 0,
- 0,
- D3DPRESENT_INTERVAL_DEFAULT
- };
- d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, listView, D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING, &presentParams, &d3ddev);
- d3ddev->CreateTexture(500, 500, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
- LVITEM lvi;
- ZeroMemory(&lvi, sizeof(LVITEM));
- lvi.mask = LVIF_TEXT;
- lvi.iSubItem = 0;
- lvi.pszText = _T("Hello");
- ListView_InsertItem(listView, &lvi);
- MSG msg;
- while(GetMessage(&msg, NULL, 0, 0) && msg.message != WM_QUIT) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch(uMsg) {
- case WM_CLOSE:
- PostQuitMessage(0);
- return 0;
- default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- }
- LRESULT CALLBACK ListViewWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HBRUSH brush;
- if(uMsg == WM_ERASEBKGND) {
- return 1;
- } else if(uMsg == WM_PAINT) {
- RECT rect;
- rect.left = 0;
- rect.top = 0;
- rect.right = 500;
- rect.bottom = 500;
- HDC bufferedDC;
- // HPAINTBUFFER bufferedPaint = BeginBufferedPaint(memoryDC, &rect, BPBF_TOPDOWNDIB, NULL, &bufferedDC);
- // LRESULT rv = originalListViewWindowProc(hwnd, uMsg, (WPARAM)bufferedDC, lParam);
- LRESULT rv = originalListViewWindowProc(hwnd, uMsg, (WPARAM)memoryDC, lParam);
- // BufferedPaintSetAlpha(bufferedPaint, NULL, 255);
- // EndBufferedPaint(bufferedPaint, TRUE);
- GdiFlush();
- D3DLOCKED_RECT lockedRect;
- tex->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD);
- for(unsigned int y = 0; y < 500; ++y) {
- memcpy(((unsigned char *)lockedRect.pBits) + lockedRect.Pitch * y, ((unsigned char *)bits) + 500 * y * 4, lockedRect.Pitch);
- }
- tex->UnlockRect(0);
- const Vertex v[4] = {
- {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
- {{1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
- {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
- {{1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
- };
- d3ddev->BeginScene();
- d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
- d3ddev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
- d3ddev->SetTexture(0, tex);
- d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
- d3ddev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(Vertex));
- d3ddev->EndScene();
- d3ddev->Present(NULL, NULL, NULL, NULL);
- ValidateRgn(hwnd, NULL);
- return rv;
- } else {
- return originalListViewWindowProc(hwnd, uMsg, wParam, lParam);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement