Advertisement

Desktop Overlay

Started by June 17, 2004 02:58 PM
4 comments, last by Wintermute2004 20 years, 5 months ago
O.K. Scriptkiddies! I was hoping that someone might want a challenge. I have been looking at AngelCodes Desktop Overlay code that allows for a directdraw screen animation to be displayed onto the win32 desktop. http://www.angelcode.com/dev/overlay/ "This demo will show an animated image like an old TV without signal on your desktop, under your windows and icons. It does this by using DirectDraw overlay surfaces that are masked to the desktop background color. DirectX 7 or later is needed to run the demo. " Now for the newbee question and hopefully one might be up for this challenge (NOTE: do not care about being a resource hog). I would like to know how to draw a very very basic box, 3d object, or load a image into that code instead of the static screen the code shows. Exmaple: http://www.cplusplus.com/src/direct3d.zip AngelCode does not have the time as he is very busy. Now, I have searched and searched the web with only answers like "Just use Active Desktop", but I do not want to do a gif/flash animation. I would like to get a code sample to show a simple 3d box on the desktop. Very Very basic so that my little brain can get that light bulb going to go "OH THATS HOW THEY DO IT!" I hope that one of you would like a challenge, or even help out a newbee at this to get my brain, and coding in the right direction. Sure it might be a dumb thing to do, but I would realy like to learn how anyways. Thank You
Check out nehe.gamedev.net -> Tutorials on the left panel.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Advertisement
Hi,

you should just create an ActiveX Control, that uses OpenGL to Display itself. then, create a Webpage with this control embedded and set it as Background. I played around trying to hook OpenGL into the Desktops HWND, but this doesn't works that well. So simply create an ActiveX, that'll do the job. But remember to refresh your HWND after each draw Cycle !

Wintermute
//	---------------------------------------------------------------------------------------------------------//	DRAWING ON THE DESKTOP BACKGROUND DEMO//	This code has been written for demonstration purposes only.//	It uses a hacky solution to access the desktop background handle, so you may use it at your own risks.//	One requirement is that the active desktop web-content is activated.//	Also, it has been made to work with a 32bit desktop, (if you don't support A8R8G8B8, it won't work)//	It has been successfully tested on Win98, WinMe, Win2000 and WinXP.//	Finally, if it doesn't work, that can be for one of the previous reasons, or maybe because//	you ran out of video memory. try lowering the resolution...//	If it crashes or if you find a bug, don't hesitate to contact me.//	---------------------------------------------------------------------------------------------------------//	AUTHOR : Charles-Edouard Breteche (Lion)//	E-MAIL : eddycharly@hotmail.com//	THIS CODE WAS WRITTEN FOR THE DR-CODE WEBSITE : www.dr-code.com//	---------------------------------------------------------------------------------------------------------#include <windows.h>#include <d3d8.h>#include <d3dx8.h>#include <stdio.h>#pragma comment (lib, "d3d8")#pragma comment (lib, "d3dx8")struct MESH_VERTEX{	D3DXVECTOR3	position;	D3DXVECTOR3	normal;};struct MIRROR_VERTEX{	D3DXVECTOR3	position;	DWORD		color;	//	mainly for alpha component	float		tu, tv;	MIRROR_VERTEX (float x, float y, float z, DWORD c, float u, float v)	{		position = D3DXVECTOR3 (x, y, z);		color = c;		tu = u; tv = v;	}};void InitD3D8Material (D3DMATERIAL8& mtrl, float r = 0.0f, float g = 0.0f, float b = 0.0f, float a = 1.0f){	ZeroMemory	(&mtrl, sizeof (D3DMATERIAL8));	mtrl.Ambient.r = r;	mtrl.Ambient.g = g;	mtrl.Ambient.b = b;	mtrl.Ambient.a = a;	mtrl.Diffuse.r = r;	mtrl.Diffuse.g = g;	mtrl.Diffuse.b = b;	mtrl.Diffuse.a = a;}int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow){		HWND hwnd1, hwnd2, hwnd3, hwnd, old_parent;	HWND hwnd0;		hwnd0 = ::GetDesktopWindow ();		hwnd1 = ::FindWindow ("ProgMan", NULL);	hwnd2 = ::GetWindow (::FindWindow ("ProgMan", NULL), GW_CHILD);	hwnd3 = ::GetWindow (::GetWindow (::FindWindow ("ProgMan", NULL), GW_CHILD), GW_CHILD);		//	we hook hwnd3 (the icons)	hwnd = hwnd3;		RECT rect;	::GetWindowRect (hwnd0, ▭);		//	everything happens here.....	//	we make desktop window the parent of our hooked window, and the magic happens	old_parent = ::SetParent (hwnd, hwnd0);		//	let's hide hwnd1 & hwnd2	::ShowWindow (hwnd1, SW_HIDE);	::ShowWindow (hwnd2, SW_HIDE);		long	width	= rect.right - rect.left;	long	height	= rect.bottom - rect.top;		LPDIRECT3D8 lpD3D = Direct3DCreate8 (D3D_SDK_VERSION);		D3DDISPLAYMODE d3ddm;	lpD3D->GetAdapterDisplayMode (D3DADAPTER_DEFAULT, &d3ddm);		D3DPRESENT_PARAMETERS d3dpp;	ZeroMemory(&d3dpp,sizeof(d3dpp));		d3dpp.Windowed			= TRUE;	d3dpp.BackBufferFormat	= D3DFMT_A8R8G8B8;//d3ddm.Format; 	d3dpp.BackBufferWidth	= width;	d3dpp.BackBufferHeight	= height;	d3dpp.BackBufferCount	= 1;	d3dpp.SwapEffect		= D3DSWAPEFFECT_FLIP;		d3dpp.EnableAutoDepthStencil	= TRUE;	d3dpp.AutoDepthStencilFormat	= D3DFMT_D16;		LPDIRECT3DDEVICE8 lpDevice = NULL;		HRESULT result;		if (FAILED (			result = lpD3D->CreateDevice (				D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd0,				D3DCREATE_SOFTWARE_VERTEXPROCESSING,				&d3dpp, &lpDevice			)		)	)	{		char strtmp[256];		lpD3D->Release ();		//	unhook our window		::SetParent (hwnd, old_parent);		//	restore everything		::ShowWindow (hwnd3, SW_SHOWMAXIMIZED);		::ShowWindow (hwnd2, SW_SHOWMAXIMIZED);		::ShowWindow (hwnd1, SW_SHOWMAXIMIZED);		sprintf (strtmp, "Failed to create a d3d device. (error = %x)", result);		MessageBox (hwnd0, strtmp, "Fatal error", 0);		return FALSE;	}	//	VIEW MATRIX	D3DXMATRIX matView;	D3DXVECTOR3 vUpVec		(0.0f, 1.0f, 0.0f);	D3DXVECTOR3 vEyePt		(-12.0f, 2.0f, 0.0f);	D3DXVECTOR3 vLookatPt		(0.0f, 0.0f, 0.0f);	D3DXMatrixLookAtLH		(&matView, &vEyePt, &vLookatPt, &vUpVec);		lpDevice->SetTransform	(D3DTS_VIEW, &matView);		//	PROJ MATRIX	D3DXMATRIX matProj;	FLOAT fAspect = (FLOAT) width / height;	D3DXMatrixPerspectiveFovLH	(&matProj, D3DX_PI / 4, fAspect, 1.0f, 1000.0f);		lpDevice->SetTransform	(D3DTS_PROJECTION, &matProj);		//	SOMETHING TO RENDER	LPD3DXMESH mesh, mesh2;	LPD3DXBUFFER adj;	HDC hdc = ::CreateCompatibleDC (NULL);	HFONT	hFont;	HFONT	hFontOld;	LOGFONT	lf;		ZeroMemory (&lf, sizeof(lf));	lf.lfHeight		= 24;	lf.lfStrikeOut	= 1;	lf.lfQuality	= PROOF_QUALITY;		lstrcpy (lf.lfFaceName, "Impact");		hFont		= ::CreateFontIndirect (&lf);	hFontOld	= (HFONT) ::SelectObject (hdc, hFont); 		result = D3DXCreateText		(lpDevice, hdc, "Dr - Code", 0.001f, 1, &mesh, &adj, 0);		::SelectObject(hdc, hFontOld);		result = mesh->CloneMeshFVF (0, D3DFVF_XYZ | D3DFVF_NORMAL, lpDevice, &mesh2);	result = D3DXComputeNormals (mesh2, 0);		MESH_VERTEX* vb;		mesh2->LockVertexBuffer (0, (BYTE**) &vb);		for (unsigned int i = 0; i < mesh2->GetNumVertices(); ++i)	{		vb.position.x -= 1.5f;		vb.position.z += 0.5f;		vb.position.y -= 0.3f;	}		mesh2->UnlockVertexBuffer ();		float yaw = 0, pitch = 0, roll = 0;		int counter = 0;		//	let's give focus to hwnd, so everything keeps going on	::BringWindowToTop (hwnd0);		lpDevice->SetRenderState (D3DRS_LIGHTING, TRUE);	lpDevice->SetRenderState (D3DRS_AMBIENT, 0x20202020);		// Set up a material	D3DMATERIAL8 mtrl;	InitD3D8Material	(mtrl, 0.8f, 0.8f, 0.9f, 1.0f);	lpDevice->SetMaterial	(&mtrl);		// Add some lighting	D3DLIGHT8 light;	ZeroMemory (&light, sizeof (D3DLIGHT8));	light.Type		= D3DLIGHT_DIRECTIONAL;	light.Direction		= D3DXVECTOR3 (0, 1, 0);	light.Diffuse.r		= 1;	light.Diffuse.g		= 0.4f;	light.Diffuse.b		= 0.4f;		lpDevice->SetLight	(0, &light);	lpDevice->LightEnable	(0, TRUE);		light.Direction		= D3DXVECTOR3 (0, -1, 0);	light.Diffuse.r		= 0.3f;	light.Diffuse.g		= 1;	light.Diffuse.b		= 0.3f;		lpDevice->SetLight	(1, &light);	lpDevice->LightEnable	(1, TRUE);		D3DXMATRIX mirror (		1, 0, 0, 0,		0, -1, 0, 0,		0, 0, 1, 0,		0, 0, 0, 1	);		float start = 14.0f;	float end = 5.5f;		lpDevice->SetRenderState (D3DRS_FOGENABLE, TRUE);	lpDevice->SetRenderState (D3DRS_FOGTABLEMODE,	D3DFOG_NONE);	lpDevice->SetRenderState (D3DRS_FOGVERTEXMODE,	D3DFOG_LINEAR);	lpDevice->SetRenderState (D3DRS_FOGCOLOR, 0x00999920);	lpDevice->SetRenderState (D3DRS_FOGEND,		*(DWORD *)(&end));	lpDevice->SetRenderState (D3DRS_FOGSTART,	*(DWORD *)(&start));	lpDevice->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);		lpDevice->SetTextureStageState (0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);	lpDevice->SetTextureStageState (0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);	lpDevice->SetTextureStageState (0, D3DTSS_MIPFILTER, D3DTEXF_POINT);		MIRROR_VERTEX floor[4] =	{		MIRROR_VERTEX (-10, 0, -10, 0x60808080, 0, 0),		MIRROR_VERTEX (-10, 0, 10, 0x60808080, 0, 1),		MIRROR_VERTEX (10, 0, -10, 0x60808080, 1, 0),		MIRROR_VERTEX (10, 0, 10, 0x60808080, 1, 1)	};		LPDIRECT3DTEXTURE8 floor_tex = NULL;	D3DXCreateTextureFromFile (lpDevice, "floor.bmp", &floor_tex);		while (counter < 2000)	{		lpDevice->Clear (0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x60202020, 1.0f, 0);		yaw	+= 0.01f;		pitch	+= 0.02f;		roll	+= 0.03f;		if (D3D_OK == lpDevice->BeginScene ())		{			D3DXMATRIX world, tmp;			D3DXMatrixTranslation (&world, 0, 0, 0);			lpDevice->SetTransform (D3DTS_WORLD, &world);			lpDevice->SetTexture (0, floor_tex);			lpDevice->SetRenderState (D3DRS_LIGHTING, FALSE);			lpDevice->SetRenderState (D3DRS_ZWRITEENABLE, FALSE);			float start2 = 9;			float end2 = 20;			lpDevice->SetRenderState (D3DRS_FOGCOLOR, 0x00202020);			lpDevice->SetRenderState (D3DRS_FOGEND,		*(DWORD *)(&end2));			lpDevice->SetRenderState (D3DRS_FOGSTART,	*(DWORD *)(&start2));			lpDevice->SetVertexShader (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXCOORDSIZE2(1));			lpDevice->DrawPrimitiveUP (D3DPT_TRIANGLESTRIP, 2, floor, sizeof (MIRROR_VERTEX));			lpDevice->SetRenderState (D3DRS_LIGHTING, TRUE);			lpDevice->SetRenderState (D3DRS_ZWRITEENABLE, TRUE);			lpDevice->SetRenderState (D3DRS_FOGCOLOR, 0x00999920);			lpDevice->SetRenderState (D3DRS_FOGEND,		*(DWORD *)(&end));			lpDevice->SetRenderState (D3DRS_FOGSTART,	*(DWORD *)(&start));			D3DXMatrixTranslation (&world, 0, 1.65f, 0);			D3DXMatrixRotationYawPitchRoll (&tmp, yaw, pitch, roll);			world = tmp * world;			lpDevice->SetTransform (D3DTS_WORLD, &world);			lpDevice->SetTexture (0, NULL);			if (mesh2) mesh2->DrawSubset (0);			D3DXMATRIX view, mirror_view;			lpDevice->GetTransform	(D3DTS_VIEW, &view);			mirror_view = view * mirror;			lpDevice->SetTransform	(D3DTS_VIEW, &mirror_view);			lpDevice->SetRenderState (D3DRS_CULLMODE, D3DCULL_CW);			lpDevice->SetRenderState (D3DRS_ALPHABLENDENABLE, TRUE);			//	write in zbuffer only			lpDevice->SetRenderState (D3DRS_SRCBLEND, D3DBLEND_ZERO);			lpDevice->SetRenderState (D3DRS_DESTBLEND, D3DBLEND_ONE);			if (mesh2) mesh2->DrawSubset (0);			lpDevice->SetRenderState (D3DRS_SRCBLEND, D3DBLEND_DESTALPHA);			lpDevice->SetRenderState (D3DRS_DESTBLEND, D3DBLEND_INVDESTALPHA);			lpDevice->SetRenderState (D3DRS_ZWRITEENABLE, FALSE);			if (mesh2) mesh2->DrawSubset (0);			lpDevice->SetTransform	(D3DTS_VIEW, &view);			lpDevice->SetRenderState (D3DRS_CULLMODE, D3DCULL_CCW);			lpDevice->SetRenderState (D3DRS_ALPHABLENDENABLE, FALSE);			lpDevice->SetRenderState (D3DRS_ZWRITEENABLE, TRUE);			lpDevice->EndScene ();			lpDevice->Present (NULL,NULL,NULL,NULL);			//	limit to 10 renderings per second			::Sleep (30);			counter++;		}	}	//	release D3D	mesh->Release ();	mesh2->Release ();	lpDevice->Release ();	lpD3D->Release ();	floor_tex->Release ();	//	unhook our window	::SetParent (hwnd, old_parent);	//	restore everything	::ShowWindow (hwnd3, SW_SHOWMAXIMIZED);	::ShowWindow (hwnd2, SW_SHOWMAXIMIZED);	::ShowWindow (hwnd1, SW_SHOWMAXIMIZED);	return 0;}


Hope this helps.
i just did a quick google search and found some interesting results...
GetDC(GetDesktopWindow()) works but i need to figure out how to actually render the ogl stuff w/ the desktop. all i get now is a clear window.
this forum @ flipcode may help too [link]http://www.flipcode.com/cgi-bin/msg.cgi?showThread=00005207&forum=3dtheory&id=-1[/link]
if someone knows how to carry the first suggestion a little further let me know!
The Problem with GetDesktopWindow is that its not really the desktop you see, its a window behind the desktop, so the you won't ever see anything there. The real background ( for example the background picture ) is a window of class "SysListView32" if you didn't activate the ACtive Desktop in which case you have an "Internet Explorer_Server" class Window. But as it seems, the only working solution is to use the DirectDraw colorkey.

Correct me if I'm wrong :)

CU
Wintermute

This topic is closed to new replies.

Advertisement