Glass Effect using dwmapi.dll in windows xp on C#

Glass Effect using dwmapi.dll in windows xp on C#

Page 1 of 1

2 Replies - 11120 Views - Last Post: 04 November 2009 - 09:28 PM Rate Topic: -----

#1 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-September 09

Glass Effect using dwmapi.dll in windows xp on C#

Post icon  Posted 04 November 2009 - 06:00 AM

Hii i am writing a code to make the glass effect on windows form. Well the code works fine on vista but my target is on windows xp. I have copyed all the dll's that are reqired and when i debug i am getting an error "DLL NOT FOUND EXCEPTION UNHANDILED".
Here is the code that i am using:-
-----------------------------------------------------------------------------------------------------------------------------
This is the class where i import dwmapi dll.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace welcome_page
{
	class VistaGlassEffect
	{
		internal class VistaApi
		{
			[DllImport("dwmapi.dll")]
			internal static extern void DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);

			[DllImport("dwmapi.dll")]
			internal static extern void DwmIsCompositionEnabled(ref bool isEnabled);

			internal struct Margins
			{
				public int Left, Right, Top, Bottom;
			}

			// consts for wndproc
			internal const int WM_NCHITTEST = 0x84;
			internal const int HTCLIENT = 1;
			internal const int HTCAPTION = 2;
		}
	}
}


-----------------------------------------------------------------------------------------------------------------------------
This the form where i call this class "VistaGlassEffect"

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Diagnostics;
using System.Drawing.Drawing2D;


namespace welcome_page
{
	public partial class Form2 : Form
	{
		public Form2()
		{
			InitializeComponent();
			this.FitGlass();
		}  
		Video video;
		private welcome_page.VistaGlassEffect.VistaApi.Margins marg;
		private Rectangle topRect = Rectangle.Empty;
		private Rectangle botRect = Rectangle.Empty;
		private Rectangle lefRect = Rectangle.Empty;
		private Rectangle rigRect = Rectangle.Empty;
		
		private void FitGlass()
		{
			// If DWM is not enabled then get out
			if (!this.IsGlassEnabled())
			{
				return;

			}

			// Set the Margins to their default values
			marg.Top = 600; // extend from the top
			marg.Left = 400;  // not used in this sample but could be
			marg.Right = 200; // not used in this sample but could be
			marg.Bottom = 860;// not used in this sample but could be

			this.Paint += new PaintEventHandler(this.Form1_Paint);

			// call the function that gives us glass, 
			// passing a reference to our inset Margins
			welcome_page.VistaGlassEffect.VistaApi.DwmExtendFrameIntoClientArea(this.Handle, ref marg);
		}

	   
 private void apply()
 {
	 this.Paint -= new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
	 this.RecreateHandle(); //needed if changing on the fly
	 this.FitGlass();
   
 }	
   

	private bool IsGlassEnabled()
	{
	  //if (Environment.OSVersion.Version.Major < 6)
	  //{
	  //  Debug.WriteLine("How about trying this on Vista?");
	  //  return false;
	  //}

	  //Check if DWM is enabled
	  bool isGlassSupported = false;
------welcome_page.VistaGlassEffect.VistaApi.DwmIsCompositionEnabled(ref isGlassSupported);---Here Error OCCURS.
	  return isGlassSupported;
	}

	// Alpha-blending Paint after the glass extension
	// this seems better than the winforms transparency approach because here we can click on the glass!
	private void Form1_Paint(object sender, PaintEventArgs e)
	{
	  // black brush for Alpha transparency
	  SolidBrush blackBrush = new SolidBrush(Color.Black);

	  Graphics g = e.Graphics;

	  if (this.IsGlassEnabled())
	  {	  
		// setup the rectangles
		topRect = new Rectangle(0, 0, this.ClientSize.Width, marg.Top);
		lefRect = new Rectangle(0, 0, marg.Left, this.ClientSize.Height);
		rigRect = new Rectangle(this.ClientSize.Width - marg.Right, 0, marg.Right, this.ClientSize.Height);
		botRect = new Rectangle(0, this.ClientSize.Height - marg.Bottom, this.ClientSize.Width, marg.Bottom);
		// Fill Rectangles
		g.FillRectangle(blackBrush, topRect);
		g.FillRectangle(blackBrush, lefRect);
		g.FillRectangle(blackBrush, rigRect);
		g.FillRectangle(blackBrush, botRect);
	  }	

	  blackBrush.Dispose();
	}

   
  
	 
		
	protected override void WndProc(ref Message m)
	{	  
	  base.WndProc(ref m);

	  if (m.Msg == welcome_page.VistaGlassEffect.VistaApi.WM_NCHITTEST // if this is a click
		&& m.Result.ToInt32() == welcome_page.VistaGlassEffect.VistaApi.HTCLIENT // ...and it is on the client
		&& this.IsOnGlass(m.LParam.ToInt32())) // ...and specifically in the glass area
	  {
		m.Result = new IntPtr(welcome_page.VistaGlassEffect.VistaApi.HTCAPTION); // lie and say they clicked on the title bar
	  }
	}

	private bool IsOnGlass(int lParam)
	{
	  // sanity check
	  if (!this.IsGlassEnabled())
	  {
		return false;
	  }

	  // get screen coordinates
	  int x = (lParam << 16) >> 16; // lo order word
	  int y =  lParam		>> 16; // hi order word

	  // translate screen coordinates to client area
	  Point p = this.PointToClient(new Point(x, y));

	  // work out if point clicked is on glass
	  if (topRect.Contains(p) || lefRect.Contains(p) || rigRect.Contains(p) || botRect.Contains(p))
	  {
		return true;
	  }

	  return false;
	}
	void buttn()
	{
 
	}
		private void Form2_Load(object sender, EventArgs e)
		{		 
		   
			int width = panel1.Width;
			int height = panel1.Height;
			System.Uri u = new Uri(@"F:\Documents\Viswa Teja\Documents\C2\teja.avi");
			video = Video.FromUrl(u);
			video.Owner = panel1;
			video.Play();
			panel1.Size = new Size(width, height);
			//this.apply();
			
			
			  
		}

		private void button1_Click(object sender, EventArgs e)
		{
			this.Close();
					}	   
		


	}
}




-----------------------------------------------------------------------------------------------------------------------------


Please kindly help me. :D

Is This A Good Question/Topic? 0
  • +

Replies To: Glass Effect using dwmapi.dll in windows xp on C#

#2 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: Glass Effect using dwmapi.dll in windows xp on C#

Posted 04 November 2009 - 08:02 AM

Vista uses a completly different method of drawing windows than XP does, copying one DLL isn't going to convert XP to Vista.

Using dependency walker, dwmapi.dll depends on all these DLLs to work:

ACLUI.DLL
ACTIVEDS.DLL
ADSLDPC.DLL
ADVAPI32.DLL
ADVPACK.DLL
API-MS-WIN-CORE-CONSOLE-L1-1-0.DLL
API-MS-WIN-CORE-DATETIME-L1-1-0.DLL
API-MS-WIN-CORE-DEBUG-L1-1-0.DLL
API-MS-WIN-CORE-DELAYLOAD-L1-1-0.DLL
API-MS-WIN-CORE-ERRORHANDLING-L1-1-0.DLL
API-MS-WIN-CORE-FIBERS-L1-1-0.DLL
API-MS-WIN-CORE-FILE-L1-1-0.DLL
API-MS-WIN-CORE-HANDLE-L1-1-0.DLL
API-MS-WIN-CORE-HEAP-L1-1-0.DLL
API-MS-WIN-CORE-INTERLOCKED-L1-1-0.DLL
API-MS-WIN-CORE-IO-L1-1-0.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L1-1-0.DLL
API-MS-WIN-CORE-LOCALIZATION-L1-1-0.DLL
API-MS-WIN-CORE-LOCALREGISTRY-L1-1-0.DLL
API-MS-WIN-CORE-MEMORY-L1-1-0.DLL
API-MS-WIN-CORE-MISC-L1-1-0.DLL
API-MS-WIN-CORE-NAMEDPIPE-L1-1-0.DLL
API-MS-WIN-CORE-PROCESSENVIRONMENT-L1-1-0.DLL
API-MS-WIN-CORE-PROCESSTHREADS-L1-1-0.DLL
API-MS-WIN-CORE-PROFILE-L1-1-0.DLL
API-MS-WIN-CORE-RTLSUPPORT-L1-1-0.DLL
API-MS-WIN-CORE-STRING-L1-1-0.DLL
API-MS-WIN-CORE-SYNCH-L1-1-0.DLL
API-MS-WIN-CORE-SYSINFO-L1-1-0.DLL
API-MS-WIN-CORE-THREADPOOL-L1-1-0.DLL
API-MS-WIN-CORE-UTIL-L1-1-0.DLL
API-MS-WIN-SECURITY-BASE-L1-1-0.DLL
API-MS-WIN-SECURITY-LSALOOKUP-L1-1-0.DLL
API-MS-WIN-SECURITY-SDDL-L1-1-0.DLL
API-MS-WIN-SERVICE-CORE-L1-1-0.DLL
API-MS-WIN-SERVICE-MANAGEMENT-L1-1-0.DLL
API-MS-WIN-SERVICE-MANAGEMENT-L2-1-0.DLL
API-MS-WIN-SERVICE-WINSVC-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M.DLL
POWRPROF.DLL
PRINTUI.DLL
PROFAPI.DLL
PROPSYS.DLL
PSAPI.DLL
PUIAPI.DLL
RASAPI32.DLL
RASDLG.DLL
RASMAN.DLL
REGAPI.DLL
RPCRT4.DLL
RSTRTMGR.DLL
RTUTILS.DLL
SAMCLI.DLL
SAMLIB.DLL
SCECLI.DLL
SECUR32.DLL
SENSAPI.DLL
SETUPAPI.DLL
SHDOCVW.DLL
SHELL32.DLL
SHLWAPI.DLL
SLC.DLL
SPFILEQ.DLL
SPINF.DLL
SPPC.DLL
SRVCLI.DLL
SSPICLI.DLL
SYSNTFY.DLL
TAPI32.DLL
URLMON.DLL
USER32.DLL
USERENV.DLL
USP10.DLL
UXTHEME.DLL
VAULTCLI.DLL
VERSION.DLL
VPNIKEAPI.DLL
W32TOPL.DLL
WDI.DLL
WEBIO.DLL
WEBSERVICES.DLL
WER.DLL
WERUI.DLL
WINBRAND.DLL
WINDOWSCODECS.DLL
WINHTTP.DLL
WININET.DLL
WINMM.DLL
WINNSI.DLL
WINSCARD.DLL
WINSPOOL.DRV
WINSTA.DLL
WINTRUST.DLL
WKSCLI.DLL
WLDAP32.DLL
WS2_32.DLL
WTSAPI32.DLL
XMLLITE.DLL
Was This Post Helpful? 0
  • +
  • -

#3 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 24-September 09

Re: Glass Effect using dwmapi.dll in windows xp on C#

Posted 04 November 2009 - 09:28 PM

I have no objection for copying these dll's. All i Need is that it should work.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1