桌面 透明 三角形 分层窗口 DX
//桌面 透明 三角形 分层窗口 DX
//IDirect3DSurface9 GetDC UpdateLayeredWindow #include <Windows.h>
#include <mmsystem.h>
#include <d3dx9.h>
#pragma warning( disable : 4996 )
#include <strsafe.h>
#pragma warning( default : 4996 ) //include path $(DXSDK_DIR)Include;
//library path $(DXSDK_DIR)Lib\x86
//library d3dx9.lib d3d9.lib Winmm.lib LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; HWND g_hWnd = NULL;
IDirect3DSurface9* g_pkRenderTarget = NULL;
IDirect3DSurface9* g_pkOffscreenPlainSurface = NULL; struct CUSTOMVERTEX
{
FLOAT x, y, z;
DWORD color;
}; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE) HRESULT InitD3D(HWND hWnd)
{
if (NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
{
return E_FAIL;
} D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
{
return E_FAIL;
} g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); return S_OK;
} HRESULT InitGeometry()
{
CUSTOMVERTEX g_Vertices[] =
{
{ -1.0f, -1.0f, 0.0f, 0xffff0000, },
{ 1.0f, -1.0f, 0.0f, 0xff0000ff, },
{ 0.0f, 1.0f, 0.0f, 0xffffffff, },
}; if (FAILED(g_pd3dDevice->CreateVertexBuffer( * sizeof(CUSTOMVERTEX), , D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL)))
{
return E_FAIL;
} VOID* pVertices;
if (FAILED(g_pVB->Lock(, sizeof(g_Vertices), (void**)&pVertices, )))
{
return E_FAIL;
}
memcpy(pVertices, g_Vertices, sizeof(g_Vertices));
g_pVB->Unlock(); return S_OK;
} VOID Cleanup()
{
if (g_pVB != NULL)
{
g_pVB->Release();
}
if (g_pd3dDevice != NULL)
{
g_pd3dDevice->Release();
}
if (g_pD3D != NULL)
{
g_pD3D->Release();
}
} VOID SetupMatrices()
{
D3DXMATRIXA16 matWorld;
UINT iTime = timeGetTime() % ;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
D3DXMatrixRotationY(&matWorld, fAngle);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld); D3DXVECTOR3 vEyePt(0.0f, 3.0f, -5.0f);
D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / , 1.0f, 1.0f, 100.0f);
g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); } VOID Render()
{ RECT kRect;
GetWindowRect(g_hWnd, &kRect); UINT uiWndWidth = kRect.right - kRect.left;
UINT uiWndHeight = kRect.bottom - kRect.top; if (!g_pkOffscreenPlainSurface)
{
g_pd3dDevice->CreateOffscreenPlainSurface(uiWndWidth, uiWndHeight, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &g_pkOffscreenPlainSurface, );
g_pd3dDevice->CreateRenderTarget(uiWndWidth, uiWndHeight, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, , true, &g_pkRenderTarget, );
}
else
{
D3DSURFACE_DESC kDesc;
g_pkOffscreenPlainSurface->GetDesc(&kDesc); if (kDesc.Width != uiWndWidth || kDesc.Width != uiWndHeight)
{
g_pkOffscreenPlainSurface->Release();
g_pkRenderTarget->Release();
g_pd3dDevice->CreateOffscreenPlainSurface(uiWndWidth, uiWndHeight, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &g_pkOffscreenPlainSurface, );
g_pd3dDevice->CreateRenderTarget(uiWndWidth, uiWndHeight, D3DFMT_X8R8G8B8, D3DMULTISAMPLE_NONE, , true, &g_pkRenderTarget, );
}
} if (!g_pkOffscreenPlainSurface || !g_pkRenderTarget)
{
return;
} HRESULT hr = g_pd3dDevice->SetRenderTarget(, g_pkRenderTarget);
g_pd3dDevice->Clear(, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(, , ), 1.0f, ); if (SUCCEEDED(g_pd3dDevice->BeginScene()))
{
SetupMatrices(); g_pd3dDevice->SetStreamSource(, g_pVB, , sizeof(CUSTOMVERTEX));
g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, , ); g_pd3dDevice->EndScene();
} g_pd3dDevice->Present(NULL, NULL, NULL, NULL); hr = g_pd3dDevice->GetRenderTargetData(g_pkRenderTarget, g_pkOffscreenPlainSurface); HDC hDC = ;
//g_pkRenderTarget->GetDC(&hDC);
g_pkOffscreenPlainSurface->GetDC(&hDC); POINT kPoint = { , };
SIZE kSize = { uiWndWidth, uiWndHeight }; BLENDFUNCTION kBlend;
kBlend.AlphaFormat = AC_SRC_ALPHA;
kBlend.SourceConstantAlpha = ;
kBlend.BlendFlags = ;
kBlend.BlendOp = AC_SRC_OVER; UpdateLayeredWindow(g_hWnd, , &kPoint, &kSize, hDC, &kPoint, , &kBlend, ULW_ALPHA); g_pkOffscreenPlainSurface->ReleaseDC(hDC);
//g_pkRenderTarget->ReleaseDC(hDC);
} LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
Cleanup();
PostQuitMessage();
return ;
} return DefWindowProc(hWnd, msg, wParam, lParam);
} INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, INT)
{
UNREFERENCED_PARAMETER(hInst); WNDCLASSEX wc =
{
sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, L"D3D Tutorial", NULL
};
RegisterClassEx(&wc); g_hWnd = CreateWindowEx(WS_EX_LAYERED, L"D3D Tutorial", L"D3D Tutorial 03: Matrices", WS_POPUP | WS_THICKFRAME, , , , , NULL, NULL, wc.hInstance, NULL); if (SUCCEEDED(InitD3D(g_hWnd)))
{
if (SUCCEEDED(InitGeometry()))
{
ShowWindow(g_hWnd, SW_SHOWDEFAULT);
UpdateWindow(g_hWnd); MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
}
} UnregisterClass(L"D3D Tutorial", wc.hInstance);
return ;
}
桌面 透明 三角形 分层窗口 DX的更多相关文章
- [置顶] VC++界面编程之--使用分层窗口实现界面皮肤
使用分层界面来实现界面皮肤的好处是:可以保证图片边缘处理不失真,且能用于异形窗口上,如一些不规则的窗口,你很难用SetWindowRgn来达到理想效果. 在很多情况下,界面的漂亮与否,取决于PS的制作 ...
- VC++界面编程之--使用分层窗口实现界面皮肤
使用分层界面来实现界面皮肤的好处是:可以保证图片边缘处理不失真,且能用于异形窗口上,如一些不规则的窗口,你很难用SetWindowRgn来达到理想效果. 在很多情况下,界面的漂亮与否,取决于PS的制作 ...
- 第二十篇:在SOUI中使用分层窗口
从Windows 2K开始,MS为UI开发引入了分层窗口这一窗口风格.使用分层窗口,应用程序的主窗口可以是半透明,也可以是逐点半透明(即每一个像素点的透明度可以不同). 可以说,正是因为有了分层窗口, ...
- android在桌面弹出一个窗口
android在桌面弹出一个窗口 遇到了这种需求,要和iPhone一样的效果. 下面是简单实现功能,优化和美化部分,有时间慢慢搞. 方法应该有不少吧,我用的是弹出一个activity,将这个activ ...
- C# 实现窗口程序winform像QQ一样靠近桌面边缘自动隐藏窗口
实现原理: 实现这个功能的原理步骤如下: 1.判断窗体程序是否靠近桌面边缘: 2.获取桌面屏幕大小与窗体程序大小: 3.把窗体程序显示在桌面以外隐藏起来,预留部分窗体方便用户拉出程序: 4.判断鼠标是 ...
- android 桌面透明
目录(?)[-] public void setWallpaperOffsetSteps float xStep float yStep Parameters public void setWal ...
- winform, 实现窗口程序像QQ一样靠近桌面边缘自动隐藏窗口
实现原理: 步骤如下: 1.判断窗体程序是否靠近桌面边缘: 2.获取桌面屏幕大小与窗体程序大小: 3.把窗体程序显示在桌面以外隐藏起来,预留部分窗体方便用户拉出程序: 4.判断鼠标是否在窗体程序上,在 ...
- Windows 10设置桌面图标间距、窗口的背景颜色、选中文字的背景颜色
Windows 10取消了“高级外观设置”(或者叫“窗口颜色和外观”设置),想调整一些参数只能进注册表了. 修改后可能需要注销或重启才能生效. 按Win+R,然后输入regedit进入注册表编辑器. ...
- css实现的透明三角形
css实现下图样式,具体像素值记不住了,很好设置,html code (2014百度秋招面试题): <div id="demo"></div> 分析:这 ...
随机推荐
- sql server 按分组拼接数据
SELECT B.id , LEFT(tempname, LEN(tempname) - 1) AS name FROM ( SELECT id , ( SELECT name + ',' FROM ...
- poj -- 1042 Gone Fishing(枚举+贪心)
题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...
- REDIS源码中一些值得学习的技术细节02
Redis中散列函数的实现: Redis针对整数key和字符串key,采用了不同的散列函数 对于整数key,redis使用了 Thomas Wang的 32 bit Mix Function,实现了d ...
- SSM框架——使用MyBatis Generator自动创建代码
版权声明:本文为博主原创文章,未经博主允许不得转载. 这两天需要用到MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是 ...
- AdminLTE-2.2.0 学习
这货基于Bootstrap 3(提供了统一的样式,覆盖了默认的),所以官方建议先搞懂Bootstrap 3再说. # 布局 Layout 布局由四个主要部分组成: Wrapper (.wrapper) ...
- 5ucms后台调用标签
<%=Rs.Data(1,i)%>栏目 <%=Rs.Data(2,i)%>标题 <%=Rs.Data(3,i)%>推荐 <%=Rs.Data(4,i)%> ...
- VMware克隆SUSE网卡配置
1.配置DNS vim /etc/resolv.conf domain sitenameserver 202.98.0.682.配置网关 vim /etc/sysconfig/network/rout ...
- [PHP]OOP两类写法的性能对比
在PHP的OOP中我们有常见两种方法调用,对象调用和静态调用. 下面是一个简单的测试来比较它们的细微差异. /** * 对象初始化 -> 调用:objectCall.php * * 测试调用50 ...
- oracle for loop循环以及游标循环
1. for in loop形式 DECLARE CURSOR c_sal IS SELECT employee_id, first_name || last_name ename, salar ...
- php mysql支持emoji表情方案
将emoji转换成utf8 然后存储到数据库,但是 效率低 public function rrr($text) { $text = 'a