Advertisement
Guest User

Untitled

a guest
Aug 25th, 2010
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.71 KB | None | 0 0
  1. #define WIN32_LEAN_AND_MEAN
  2. #define WIN32_EXTRA_LEAN
  3. #include <windows.h>
  4. #include <CommCtrl.h>
  5. #include <tchar.h>
  6. #include <d3d9.h>
  7. #include <Uxtheme.h>
  8.  
  9. typedef LRESULT (CALLBACK *WINDOWPROC)(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  10. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  11. LRESULT CALLBACK ListViewWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  12. WINDOWPROC originalListViewWindowProc;
  13.  
  14. HWND wnd;
  15. HWND listView;
  16. HBITMAP dib;
  17. HDC memoryDC;
  18. void * bits;
  19. IDirect3D9 * d3d;
  20. IDirect3DDevice9 * d3ddev;
  21. IDirect3DTexture9 * tex;
  22.  
  23. struct Vertex
  24. {
  25.     float p[3];
  26.     float uv[2];
  27. };
  28.  
  29. INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  30. {
  31.     InitCommonControls();
  32.  
  33.     const WNDCLASSEX wndClass = {
  34.         sizeof(WNDCLASSEX),
  35.         0,
  36.         WindowProc,
  37.         0,
  38.         0,
  39.         GetModuleHandle(0),
  40.         0,
  41.         0,
  42.         0,
  43.         0,
  44.         _T("A"),
  45.         0
  46.     };
  47.  
  48.     RegisterClassEx(&wndClass);
  49.     RECT rect;
  50.     rect.left = 0;
  51.     rect.top = 0;
  52.     rect.right = 500;
  53.     rect.bottom = 500;
  54.     AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, FALSE, 0);
  55.     wnd = CreateWindowEx(0, _T("A"), _T("A"), WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 500, 500, 0, 0, GetModuleHandle(0), 0);
  56.  
  57.     memoryDC = CreateCompatibleDC(NULL);
  58.     BITMAPINFO bi;
  59.     ZeroMemory(&bi, sizeof(bi));
  60.     bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
  61.     bi.bmiHeader.biWidth = 500;
  62.     bi.bmiHeader.biHeight = -500;
  63.     bi.bmiHeader.biPlanes = 1;
  64.     bi.bmiHeader.biBitCount = 32;
  65.     bi.bmiHeader.biCompression = BI_RGB;
  66.     HBITMAP bitmap = CreateDIBSection(memoryDC, &bi, DIB_RGB_COLORS, &bits, NULL, 0);
  67.     SelectObject(memoryDC, bitmap);
  68.  
  69.     GetClientRect(wnd, &rect);
  70.     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);
  71.     originalListViewWindowProc = (WINDOWPROC)GetWindowLongPtr(listView, GWL_WNDPROC);
  72.     SetWindowLongPtr(listView, GWL_WNDPROC, (LONG)ListViewWindowProc);
  73.  
  74.     d3d = Direct3DCreate9(D3D_SDK_VERSION);
  75.     D3DPRESENT_PARAMETERS presentParams = {
  76.         500,
  77.         500,
  78.         D3DFMT_UNKNOWN,
  79.         1,
  80.         D3DMULTISAMPLE_NONE,
  81.         0,
  82.         D3DSWAPEFFECT_DISCARD,
  83.         listView,
  84.         TRUE,
  85.         FALSE,
  86.         D3DFMT_D24S8,
  87.         0,
  88.         0,
  89.         D3DPRESENT_INTERVAL_DEFAULT
  90.     };
  91.     d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, listView, D3DCREATE_PUREDEVICE | D3DCREATE_HARDWARE_VERTEXPROCESSING, &presentParams, &d3ddev);
  92.     d3ddev->CreateTexture(500, 500, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
  93.  
  94.     LVITEM lvi;
  95.     ZeroMemory(&lvi, sizeof(LVITEM));
  96.     lvi.mask = LVIF_TEXT;
  97.     lvi.iSubItem = 0;
  98.     lvi.pszText = _T("Hello");
  99.     ListView_InsertItem(listView, &lvi);
  100.  
  101.     MSG msg;
  102.     while(GetMessage(&msg, NULL, 0, 0) && msg.message != WM_QUIT) {
  103.         TranslateMessage(&msg);
  104.         DispatchMessage(&msg);
  105.     }
  106. }
  107.  
  108. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  109. {
  110.     switch(uMsg) {
  111.     case WM_CLOSE:
  112.         PostQuitMessage(0);
  113.         return 0;
  114.     default:
  115.         return DefWindowProc(hwnd, uMsg, wParam, lParam);
  116.     }
  117. }
  118.  
  119. LRESULT CALLBACK ListViewWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  120. {
  121.     HBRUSH brush;
  122.  
  123.     if(uMsg == WM_ERASEBKGND) {
  124.         return 1;
  125.     } else if(uMsg == WM_PAINT) {
  126.         RECT rect;
  127.         rect.left = 0;
  128.         rect.top = 0;
  129.         rect.right = 500;
  130.         rect.bottom = 500;
  131.         HDC bufferedDC;
  132. //      HPAINTBUFFER bufferedPaint = BeginBufferedPaint(memoryDC, &rect, BPBF_TOPDOWNDIB, NULL, &bufferedDC);
  133. //      LRESULT rv = originalListViewWindowProc(hwnd, uMsg, (WPARAM)bufferedDC, lParam);
  134.         LRESULT rv = originalListViewWindowProc(hwnd, uMsg, (WPARAM)memoryDC, lParam);
  135. //      BufferedPaintSetAlpha(bufferedPaint, NULL, 255);
  136. //      EndBufferedPaint(bufferedPaint, TRUE);
  137.         GdiFlush();
  138.  
  139.         D3DLOCKED_RECT lockedRect;
  140.         tex->LockRect(0, &lockedRect, NULL, D3DLOCK_DISCARD);
  141.         for(unsigned int y = 0; y < 500; ++y) {
  142.             memcpy(((unsigned char *)lockedRect.pBits) + lockedRect.Pitch * y, ((unsigned char *)bits) + 500 * y * 4, lockedRect.Pitch);
  143.         }
  144.         tex->UnlockRect(0);
  145.  
  146.         const Vertex v[4] = {
  147.             {{-1.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
  148.             {{1.0f, 1.0f, 0.0f}, {1.0f, 0.0f}},
  149.             {{-1.0f, -1.0f, 0.0f}, {0.0f, 1.0f}},
  150.             {{1.0f, -1.0f, 0.0f}, {1.0f, 1.0f}},
  151.         };
  152.  
  153.         d3ddev->BeginScene();
  154.         d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
  155.         d3ddev->SetFVF(D3DFVF_XYZ | D3DFVF_TEX1);
  156.         d3ddev->SetTexture(0, tex);
  157.         d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
  158.         d3ddev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, v, sizeof(Vertex));
  159.         d3ddev->EndScene();
  160.         d3ddev->Present(NULL, NULL, NULL, NULL);
  161.  
  162.         ValidateRgn(hwnd, NULL);
  163.         return rv;
  164.     } else {
  165.         return originalListViewWindowProc(hwnd, uMsg, wParam, lParam);
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement