Icon drawing

Started by
3 comments, last by streamer 15 years, 9 months ago
Hi all, I have a little "tricky" question. Is there any way to draw windows system icons in directx, assuming that program have handle of the icon? Or any thoughts of how can be this done? I have googled but didn't find nothing useful, so I don't have a clue. Any information will be appreciate. thanks in advance
Advertisement
You could draw the icon to a IDirectDrawSurface9 of an IDirect3DTexture9 using the DrawIcon function, and using the HDC from the GetDC() method. So long as the texture is in one of the required GDI formats (See the docs for GetDC() for information).
Ok Steve, thank you for the tip, I got it to work

HICON hic = LoadIcon( g_hInstance, MAKEINTRESOURCE(IDI_DIRECTX_ICON));	HDC cdc;	LPDIRECT3DSURFACE9 pIconSurface = NULL;			if(SUCCEEDED(m_pd3dDevice->CreateTexture(32, 32, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &pTex,0)))		{						if(SUCCEEDED(pTex->GetSurfaceLevel(0, &pIconSurface)))//			{				if(SUCCEEDED(pIconSurface->GetDC(&cdc)))					{						DrawIcon(cdc,0,0,hic);					}					pIconSurface->ReleaseDC(cdc);							}		}	}	SAFE_RELEASE( pIconSurface );


One more question. How can I transparent pixels put to another color, because transparent pixels look black?

[Edited by - streamer on July 11, 2008 1:22:32 PM]
Uhh...this is what you're doing here:

-creating an offscreen surface
-drawing an icon to that surface
-creating an unrelated texture
-storing a pointer to the texture's surface in the pointer previously used for the offscreen surface (memory leak)
-storing a pointer to the backbuffer in the pointer previously used for the texture's surface (another memory leak)
-releasing the pointer to the backbuffer

You should be doing this:

-create a regular texture in D3DPOOL_MANAGED, with R8G8B8 format
-get the texture's top-level surface
-Get the DC
-Draw the icon
-Release the DC
-All done!

EDIT: looks like you fixed it. [smile]
Yes :)

I noticed that I made a big stupidity [smile] and I rewrited it.

Also I got alpha color key working too, so now it is all fixed, and working.

Thank you all!

This topic is closed to new replies.

Advertisement